Move App stuff into app.go.
authorOllivier Robert <roberto@keltia.net>
Thu, 06 Apr 2017 23:31:31 +0200
changeset 21 555716349f64
parent 20 3379b2ff8f4c
child 22 1f5788b33eee
Move App stuff into app.go.
app.go
app_test.go
config.go
gondole
gondole.go
gondole_test.go
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app.go	Thu Apr 06 23:31:31 2017 +0200
@@ -0,0 +1,18 @@
+package gondole
+
+import (
+
+)
+
+// NewApp registers a new instance
+func NewApp(name, redirectURI string) (g *Gondole, err error) {
+	// Load configuration, will register if none is found
+
+	g = &Gondole{
+		Name:   name,
+		ID:     config.ID,
+		Secret: config.BearerToken,
+	}
+	return
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app_test.go	Thu Apr 06 23:31:31 2017 +0200
@@ -0,0 +1,16 @@
+package gondole
+
+import (
+	"testing"
+	"github.com/stretchr/testify/assert"
+	"reflect"
+)
+
+func TestNewApp(t *testing.T) {
+	g, err := NewApp("foo", "bar")
+	assert.NoError(t, err, "no error")
+	assert.Equal(t, reflect.TypeOf(&Gondole{}), reflect.TypeOf(g), "should be Gondole")
+
+	assert.Equal(t, "foo", g.Name, "should be equal")
+	assert.Equal(t, "bar", g.RedirectURI, "should be equal")
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config.go	Thu Apr 06 23:31:31 2017 +0200
@@ -0,0 +1,1 @@
+package gondole
Binary file gondole has changed
--- a/gondole.go	Wed Apr 05 22:03:09 2017 +0200
+++ b/gondole.go	Thu Apr 06 23:31:31 2017 +0200
@@ -1,17 +1,40 @@
 package gondole
 
 import ()
+import (
+	"github.com/sendgrid/rest"
+	"fmt"
+)
 
 const (
-	Version = "0.0"
+	APIVersion = "0.0"
 
 	APIEndpoint = "/api/v1"
+
+	NoRedirect = "urn:ietf:wg:oauth:2.0:oob"
 )
 
-func NewApp(name, redirectURI string) (g *Gondole, err error) {
-	g = &Gondole{
-		Name:        name,
-		RedirectURI: redirectURI,
+// prepareRequest insert all pre-defined stuff
+func (g *Gondole) prepareRequest(what string) (req rest.Request) {
+	endPoint := APIEndpoint + fmt.Sprintf("/%s/", what)
+	key, ok := HasAPIKey()
+
+	// Add at least one option, the APIkey if present
+	hdrs := make(map[string]string)
+	opts := make(map[string]string)
+
+	// Insert our sig
+	hdrs["User-Agent"] = fmt.Sprintf("Gondole/%s", APIVersion)
+
+	// Insert key
+	if ok {
+		opts["key"] = key
+	}
+
+	req = rest.Request{
+		BaseURL:     endPoint,
+		Headers:     hdrs,
+		QueryParams: opts,
 	}
 	return
 }
--- a/gondole_test.go	Wed Apr 05 22:03:09 2017 +0200
+++ b/gondole_test.go	Thu Apr 06 23:31:31 2017 +0200
@@ -1,16 +1,5 @@
 package gondole
 
 import (
-	"github.com/stretchr/testify/assert"
-	"reflect"
-	"testing"
 )
 
-func TestNewApp(t *testing.T) {
-	g, err := NewApp("foo", "bar")
-	assert.NoError(t, err, "no error")
-	assert.Equal(t, reflect.TypeOf(&Gondole{}), reflect.TypeOf(g), "should be Gondole")
-
-	assert.Equal(t, "foo", g.Name, "should be equal")
-	assert.Equal(t, "bar", g.RedirectURI, "should be equal")
-}