Passed
Push — main ( 2d22a4...4648c5 )
by Acho
01:50
created

smobilpay.*topupService.Collect   A

Complexity

Conditions 4

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 11
nop 3
dl 0
loc 17
rs 9.85
c 0
b 0
f 0
1
package smobilpay
2
3
import (
4
	"context"
5
	"encoding/json"
6
	"fmt"
7
	"net/http"
8
)
9
10
// topupService is the API client for the `/` endpoint
11
type topupService service
12
13
// GetPackages returns a list of all available topup packages.
14
//
15
// https://apidocs.smobilpay.com/s3papi/API-Reference.2066448558.html
16
func (service *topupService) GetPackages(ctx context.Context, serviceID string, options ...RequestOption) ([]*Topup, *Response, error) {
17
	request, err := service.client.newRequest(ctx, options, http.MethodGet, fmt.Sprintf("/topup?serviceid=%s", serviceID), nil)
18
	if err != nil {
19
		return nil, nil, err
20
	}
21
22
	response, err := service.client.do(request)
23
	if err != nil {
24
		return nil, response, err
25
	}
26
27
	var packages []*Topup
28
	if err = json.Unmarshal(*response.Body, &packages); err != nil {
29
		return nil, response, err
30
	}
31
32
	return packages, response, nil
33
}
34