Test Failed
Push — main ( 35e706...ca941c )
by Acho
01:54
created

mtnmomo.*collectionService.Token   A

Complexity

Conditions 4

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 12
nop 1
dl 0
loc 19
rs 9.8
c 0
b 0
f 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