equal
deleted
inserted
replaced
1 package gondole |
1 package gondole |
2 |
2 |
3 import () |
3 import () |
|
4 import ( |
|
5 "github.com/sendgrid/rest" |
|
6 "fmt" |
|
7 ) |
4 |
8 |
5 const ( |
9 const ( |
6 Version = "0.0" |
10 APIVersion = "0.0" |
7 |
11 |
8 APIEndpoint = "/api/v1" |
12 APIEndpoint = "/api/v1" |
|
13 |
|
14 NoRedirect = "urn:ietf:wg:oauth:2.0:oob" |
9 ) |
15 ) |
10 |
16 |
11 func NewApp(name, redirectURI string) (g *Gondole, err error) { |
17 // prepareRequest insert all pre-defined stuff |
12 g = &Gondole{ |
18 func (g *Gondole) prepareRequest(what string) (req rest.Request) { |
13 Name: name, |
19 endPoint := APIEndpoint + fmt.Sprintf("/%s/", what) |
14 RedirectURI: redirectURI, |
20 key, ok := HasAPIKey() |
|
21 |
|
22 // Add at least one option, the APIkey if present |
|
23 hdrs := make(map[string]string) |
|
24 opts := make(map[string]string) |
|
25 |
|
26 // Insert our sig |
|
27 hdrs["User-Agent"] = fmt.Sprintf("Gondole/%s", APIVersion) |
|
28 |
|
29 // Insert key |
|
30 if ok { |
|
31 opts["key"] = key |
|
32 } |
|
33 |
|
34 req = rest.Request{ |
|
35 BaseURL: endPoint, |
|
36 Headers: hdrs, |
|
37 QueryParams: opts, |
15 } |
38 } |
16 return |
39 return |
17 } |
40 } |