7 ) |
7 ) |
8 |
8 |
9 const ( |
9 const ( |
10 APIVersion = "0.0" |
10 APIVersion = "0.0" |
11 |
11 |
12 defAPIEndpoint = "https://mastodon.social/api/v1" |
12 // That is not overridable |
|
13 apiURL = "/api/v1" |
|
14 |
|
15 // Fallback instance |
|
16 FallBackURL = "https://mastodon.social" |
13 |
17 |
14 NoRedirect = "urn:ietf:wg:oauth:2.0:oob" |
18 NoRedirect = "urn:ietf:wg:oauth:2.0:oob" |
15 ) |
19 ) |
16 |
20 |
17 var ( |
21 var ( |
18 APIEndpoint string |
22 APIEndpoint string |
19 ErrAlreadyRegistered = errors.New("App already registered") |
23 ErrAlreadyRegistered = errors.New("App already registered") |
20 ) |
24 ) |
21 |
25 |
22 // prepareRequest insert all pre-defined stuff |
26 // prepareRequest insert all pre-defined stuff |
23 func (g *Gondole) prepareRequest(what string) (req rest.Request) { |
27 func (g *Client) prepareRequest(what string) (req rest.Request) { |
24 var endPoint string |
28 var APIBase string |
25 |
29 |
26 // Allow for overriding for registration |
30 // Allow for overriding for registration |
27 if APIEndpoint == "" { |
31 if g.APIBase == "" { |
28 endPoint = defAPIEndpoint |
32 APIBase = FallBackURL |
29 } else { |
33 } else { |
30 endPoint = APIEndpoint |
34 APIBase = g.APIBase |
31 } |
35 } |
32 |
36 |
33 endPoint = endPoint + fmt.Sprintf("/%s", what) |
37 APIEndpoint = fmt.Sprintf("%s%s/%", APIBase, apiURL, what) |
|
38 |
34 // Add at least one option, the APIkey if present |
39 // Add at least one option, the APIkey if present |
35 hdrs := make(map[string]string) |
40 hdrs := make(map[string]string) |
36 opts := make(map[string]string) |
41 opts := make(map[string]string) |
37 |
42 |
38 // Insert our sig |
43 // Insert our sig |
39 hdrs["User-Agent"] = fmt.Sprintf("Gondole/%s", APIVersion) |
44 hdrs["User-Agent"] = fmt.Sprintf("Client/%s", APIVersion) |
40 hdrs["Authorization"] = fmt.Sprintf("Bearer %s", g.Secret) |
45 hdrs["Authorization"] = fmt.Sprintf("Bearer %s", g.Secret) |
41 |
46 |
42 req = rest.Request{ |
47 req = rest.Request{ |
43 BaseURL: endPoint, |
48 BaseURL: APIEndpoint, |
44 Headers: hdrs, |
49 Headers: hdrs, |
45 QueryParams: opts, |
50 QueryParams: opts, |
46 } |
51 } |
47 return |
52 return |
48 } |
53 } |