Passed
Push — main ( fec294...1af38c )
by Acho
01:36
created

client.*LicenseKeysService.List   A

Complexity

Conditions 3

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nop 1
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
package client
2
3
import (
4
	"context"
5
	"encoding/json"
6
	"net/http"
7
)
8
9
// LicenseKeysService is the API client for the `/v1/license-keys` endpoint
10
type LicenseKeysService service
11
12
// Get retrieves the license key with the given ID.
13
//
14
// https://docs.lemonsqueezy.com/api/license-keys#retrieve-a-license-key
15
func (service *LicenseKeysService) Get(ctx context.Context, licenseKeyID string) (*LicenseKeyApiResponse, *Response, error) {
16
	response, err := service.client.do(ctx, http.MethodGet, "/v1/license-keys/"+licenseKeyID)
17
	if err != nil {
18
		return nil, response, err
19
	}
20
21
	licenseKey := new(LicenseKeyApiResponse)
22
	if err = json.Unmarshal(*response.Body, licenseKey); err != nil {
23
		return nil, response, err
24
	}
25
26
	return licenseKey, response, nil
27
}
28
29
// List a paginated list of discount redemptions.
30
//
31
// https://docs.lemonsqueezy.com/api/license-keys#list-all-license-keys
32
func (service *LicenseKeysService) List(ctx context.Context) (*LicenseKeysApiResponse, *Response, error) {
33
	response, err := service.client.do(ctx, http.MethodGet, "/v1/license-keys")
34
	if err != nil {
35
		return nil, response, err
36
	}
37
38
	licenseKeys := new(LicenseKeysApiResponse)
39
	if err = json.Unmarshal(*response.Body, licenseKeys); err != nil {
40
		return nil, response, err
41
	}
42
43
	return licenseKeys, response, nil
44
}
45