gondole.go
author Ollivier Robert <roberto@keltia.net>
Fri, 07 Apr 2017 15:32:29 +0200
changeset 33 bce8b17415ae
parent 26 dbc7755fbcca
child 34 69711df3beac
permissions -rw-r--r--
Add new error ErrAlreadyRegistered.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7
0fbbac6d8e8c We have an skeleton now.
Ollivier Robert <roberto@keltia.net>
parents:
diff changeset
     1
package gondole
0fbbac6d8e8c We have an skeleton now.
Ollivier Robert <roberto@keltia.net>
parents:
diff changeset
     2
13
Ollivier Robert <roberto@keltia.net>
parents: 12
diff changeset
     3
import ()
21
555716349f64 Move App stuff into app.go.
Ollivier Robert <roberto@keltia.net>
parents: 13
diff changeset
     4
import (
555716349f64 Move App stuff into app.go.
Ollivier Robert <roberto@keltia.net>
parents: 13
diff changeset
     5
	"github.com/sendgrid/rest"
555716349f64 Move App stuff into app.go.
Ollivier Robert <roberto@keltia.net>
parents: 13
diff changeset
     6
	"fmt"
33
bce8b17415ae Add new error ErrAlreadyRegistered.
Ollivier Robert <roberto@keltia.net>
parents: 26
diff changeset
     7
	"errors"
21
555716349f64 Move App stuff into app.go.
Ollivier Robert <roberto@keltia.net>
parents: 13
diff changeset
     8
)
7
0fbbac6d8e8c We have an skeleton now.
Ollivier Robert <roberto@keltia.net>
parents:
diff changeset
     9
0fbbac6d8e8c We have an skeleton now.
Ollivier Robert <roberto@keltia.net>
parents:
diff changeset
    10
const (
21
555716349f64 Move App stuff into app.go.
Ollivier Robert <roberto@keltia.net>
parents: 13
diff changeset
    11
	APIVersion = "0.0"
12
4f58e9f1e2bc Add APIEndpoint. Fill in Gondole variable.
Ollivier Robert <roberto@keltia.net>
parents: 7
diff changeset
    12
13
Ollivier Robert <roberto@keltia.net>
parents: 12
diff changeset
    13
	APIEndpoint = "/api/v1"
21
555716349f64 Move App stuff into app.go.
Ollivier Robert <roberto@keltia.net>
parents: 13
diff changeset
    14
555716349f64 Move App stuff into app.go.
Ollivier Robert <roberto@keltia.net>
parents: 13
diff changeset
    15
	NoRedirect = "urn:ietf:wg:oauth:2.0:oob"
7
0fbbac6d8e8c We have an skeleton now.
Ollivier Robert <roberto@keltia.net>
parents:
diff changeset
    16
)
0fbbac6d8e8c We have an skeleton now.
Ollivier Robert <roberto@keltia.net>
parents:
diff changeset
    17
33
bce8b17415ae Add new error ErrAlreadyRegistered.
Ollivier Robert <roberto@keltia.net>
parents: 26
diff changeset
    18
var (
bce8b17415ae Add new error ErrAlreadyRegistered.
Ollivier Robert <roberto@keltia.net>
parents: 26
diff changeset
    19
	ErrAlreadyRegistered = errors.New("App already registered")
bce8b17415ae Add new error ErrAlreadyRegistered.
Ollivier Robert <roberto@keltia.net>
parents: 26
diff changeset
    20
)
bce8b17415ae Add new error ErrAlreadyRegistered.
Ollivier Robert <roberto@keltia.net>
parents: 26
diff changeset
    21
21
555716349f64 Move App stuff into app.go.
Ollivier Robert <roberto@keltia.net>
parents: 13
diff changeset
    22
// prepareRequest insert all pre-defined stuff
555716349f64 Move App stuff into app.go.
Ollivier Robert <roberto@keltia.net>
parents: 13
diff changeset
    23
func (g *Gondole) prepareRequest(what string) (req rest.Request) {
555716349f64 Move App stuff into app.go.
Ollivier Robert <roberto@keltia.net>
parents: 13
diff changeset
    24
	endPoint := APIEndpoint + fmt.Sprintf("/%s/", what)
555716349f64 Move App stuff into app.go.
Ollivier Robert <roberto@keltia.net>
parents: 13
diff changeset
    25
555716349f64 Move App stuff into app.go.
Ollivier Robert <roberto@keltia.net>
parents: 13
diff changeset
    26
	// Add at least one option, the APIkey if present
555716349f64 Move App stuff into app.go.
Ollivier Robert <roberto@keltia.net>
parents: 13
diff changeset
    27
	hdrs := make(map[string]string)
555716349f64 Move App stuff into app.go.
Ollivier Robert <roberto@keltia.net>
parents: 13
diff changeset
    28
	opts := make(map[string]string)
555716349f64 Move App stuff into app.go.
Ollivier Robert <roberto@keltia.net>
parents: 13
diff changeset
    29
555716349f64 Move App stuff into app.go.
Ollivier Robert <roberto@keltia.net>
parents: 13
diff changeset
    30
	// Insert our sig
555716349f64 Move App stuff into app.go.
Ollivier Robert <roberto@keltia.net>
parents: 13
diff changeset
    31
	hdrs["User-Agent"] = fmt.Sprintf("Gondole/%s", APIVersion)
555716349f64 Move App stuff into app.go.
Ollivier Robert <roberto@keltia.net>
parents: 13
diff changeset
    32
555716349f64 Move App stuff into app.go.
Ollivier Robert <roberto@keltia.net>
parents: 13
diff changeset
    33
	req = rest.Request{
555716349f64 Move App stuff into app.go.
Ollivier Robert <roberto@keltia.net>
parents: 13
diff changeset
    34
		BaseURL:     endPoint,
555716349f64 Move App stuff into app.go.
Ollivier Robert <roberto@keltia.net>
parents: 13
diff changeset
    35
		Headers:     hdrs,
555716349f64 Move App stuff into app.go.
Ollivier Robert <roberto@keltia.net>
parents: 13
diff changeset
    36
		QueryParams: opts,
13
Ollivier Robert <roberto@keltia.net>
parents: 12
diff changeset
    37
	}
Ollivier Robert <roberto@keltia.net>
parents: 12
diff changeset
    38
	return
7
0fbbac6d8e8c We have an skeleton now.
Ollivier Robert <roberto@keltia.net>
parents:
diff changeset
    39
}