Passed
Push — main ( 9ca7b6...75c795 )
by Acho
05:09
created

account_service.go   A

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 20
dl 0
loc 35
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A client.*accountService.Balance 0 21 4
1
package client
2
3
import (
4
	"context"
5
	"encoding/json"
6
	"net/http"
7
)
8
9
// accountService is the API client for the `/api/account/` endpoint
10
type accountService service
11
12
// Balance is used for the partner to get the Balance of his account
13
//
14
// API Docs: https://developer.afrikpay.com/documentation/account/agent/balance/v2/
15
func (service *accountService) Balance(ctx context.Context) (map[string]interface{}, *Response, error) {
16
	request, err := service.client.newRequest(ctx, http.MethodPost, "/api/account/agent/balance/v2/", map[string]string{
17
		"agentid":       service.client.agentID,
18
		"agentplatform": service.client.agentPlatform,
19
		"hash":          service.client.hash(service.client.agentID, service.client.apiKey),
20
	})
21
	if err != nil {
22
		return nil, nil, err
23
	}
24
25
	response, err := service.client.do(request)
26
	if err != nil {
27
		return nil, response, err
28
	}
29
30
	status := map[string]interface{}{}
31
	if err = json.Unmarshal(*response.Body, &status); err != nil {
32
		return nil, response, err
33
	}
34
35
	return status, response, nil
36
}
37