Total Lines | 33 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package mtnmomo |
||
2 | |||
3 | import ( |
||
4 | "context" |
||
5 | "encoding/json" |
||
6 | "net/http" |
||
7 | ) |
||
8 | |||
9 | // collectionService is the API client for the `/collection` endpoint |
||
10 | type collectionService service |
||
11 | |||
12 | // Token is used to create an access token which can then be used to authorize and authenticate towards the other end-points of the API. |
||
13 | // |
||
14 | // API Docs: https://momodeveloper.mtn.com/docs/services/collection/operations/token-POST |
||
15 | func (service *collectionService) Token(ctx context.Context) (*AuthToken, *Response, error) { |
||
16 | request, err := service.client.newRequest(ctx, http.MethodPost, "/collection/token/", nil) |
||
17 | if err != nil { |
||
18 | return nil, nil, err |
||
19 | } |
||
20 | |||
21 | service.client.addBasicAuth(request) |
||
22 | |||
23 | response, err := service.client.do(request) |
||
24 | if err != nil { |
||
25 | return nil, nil, err |
||
26 | } |
||
27 | |||
28 | authToken := new(AuthToken) |
||
29 | if err = json.Unmarshal(*response.Body, authToken); err != nil { |
||
30 | return nil, response, err |
||
31 | } |
||
32 | |||
33 | return authToken, response, err |
||
34 | } |
||
35 |