1 package gondole |
1 package gondole |
2 |
2 |
3 import ( |
3 import ( |
4 "encoding/json" |
4 "encoding/json" |
|
5 "log" |
|
6 "net/url" |
|
7 "strings" |
|
8 |
5 "github.com/sendgrid/rest" |
9 "github.com/sendgrid/rest" |
6 "log" |
|
7 "strings" |
|
8 ) |
10 ) |
9 |
11 |
10 var () |
|
11 |
|
12 type registerApp struct { |
12 type registerApp struct { |
13 ID string `json:"id"` |
13 ID int `json:"id"` |
14 ClientID string `json:"client_id"` |
14 ClientID string `json:"client_id"` |
15 ClientSecret string `json:"client_secret"` |
15 ClientSecret string `json:"client_secret"` |
16 } |
16 } |
17 |
17 |
18 // NewApp registers a new instance |
18 // NewApp registers a new instance |
19 func NewApp(name string, scopes []string, redirectURI, baseURL string) (g *Client, err error) { |
19 func NewApp(name string, scopes []string, redirectURI, instanceURL string) (g *Client, err error) { |
20 var endpoint string |
20 if instanceURL == "" { |
|
21 instanceURL = defaultInstanceURL |
|
22 } |
21 |
23 |
22 if baseURL != "" { |
24 if !strings.Contains(instanceURL, "://") { |
23 endpoint = baseURL |
25 instanceURL = "https://" + instanceURL |
|
26 } |
|
27 |
|
28 apiPath := instanceURL + defaultAPIPath |
|
29 |
|
30 if _, err := url.ParseRequestURI(apiPath); err != nil { |
|
31 return nil, err |
24 } |
32 } |
25 |
33 |
26 g = &Client{ |
34 g = &Client{ |
27 Name: name, |
35 Name: name, |
28 APIBase: endpoint, |
36 APIBase: apiPath, |
29 } |
37 } |
30 |
38 |
31 req := g.prepareRequest("apps") |
39 req := g.prepareRequest("apps") |
32 if redirectURI != "" { |
40 if redirectURI != "" { |
33 req.QueryParams["redirect_uris"] = redirectURI |
41 req.QueryParams["redirect_uris"] = redirectURI |