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

bill_service.go   A

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A smobilpay.*billService.Get 0 17 4
1
package smobilpay
2
3
import (
4
	"context"
5
	"encoding/json"
6
	"fmt"
7
	"net/http"
8
)
9
10
// billService is the API client for the `/bill` endpoint
11
type billService service
12
13
const (
14
	// BillMerchantENEO is the merchant name for ENEO
15
	BillMerchantENEO = "ENEO"
16
17
	// BillMerchantCamwater is the merchant name for camwater
18
	BillMerchantCamwater = "CAMWATER"
19
)
20
21
// Get returns a bill
22
//
23
// https://apidocs.smobilpay.com/s3papi/API-Reference.2066448558.html
24
func (service *billService) Get(ctx context.Context, params *BillGetParams, options ...RequestOption) ([]*Bill, *Response, error) {
25
	request, err := service.client.newRequest(ctx, options, http.MethodGet, fmt.Sprintf("/bill?serviceid=%s&merchant=%s&serviceNumber=%s", params.ServiceID, params.Merchant, params.ServiceNumber), nil)
26
	if err != nil {
27
		return nil, nil, err
28
	}
29
30
	response, err := service.client.do(request)
31
	if err != nil {
32
		return nil, response, err
33
	}
34
35
	var bills []*Bill
36
	if err = json.Unmarshal(*response.Body, &bills); err != nil {
37
		return nil, response, err
38
	}
39
40
	return bills, response, nil
41
}
42