1
|
|
|
package client |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"context" |
5
|
|
|
"encoding/json" |
6
|
|
|
"net/http" |
7
|
|
|
) |
8
|
|
|
|
9
|
|
|
// LicenseKeyInstancesService is the API client for the `/v1/license-key-instances` endpoint |
10
|
|
|
type LicenseKeyInstancesService service |
11
|
|
|
|
12
|
|
|
// Get retrieves the license key instance with the given ID. |
13
|
|
|
// |
14
|
|
|
// https://docs.lemonsqueezy.com/api/license-key-instances#retrieve-a-license-key-instance |
15
|
|
|
func (service *LicenseKeyInstancesService) Get(ctx context.Context, licenseKeyID string) (*LicenseKeyInstanceApiResponse, *Response, error) { |
16
|
|
|
response, err := service.client.do(ctx, http.MethodGet, "/v1/license-key-instances/"+licenseKeyID) |
17
|
|
|
if err != nil { |
18
|
|
|
return nil, response, err |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
licenseKeyInstance := new(LicenseKeyInstanceApiResponse) |
22
|
|
|
if err = json.Unmarshal(*response.Body, licenseKeyInstance); err != nil { |
23
|
|
|
return nil, response, err |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
return licenseKeyInstance, response, nil |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
// List a paginated list of license key instances. |
30
|
|
|
// |
31
|
|
|
// https://docs.lemonsqueezy.com/api/license-key-instances#list-all-license-key-instances |
32
|
|
|
func (service *LicenseKeyInstancesService) List(ctx context.Context) (*LicenseKeyInstancesApiResponse, *Response, error) { |
33
|
|
|
response, err := service.client.do(ctx, http.MethodGet, "/v1/license-key-instances") |
34
|
|
|
if err != nil { |
35
|
|
|
return nil, response, err |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
licenseKeyInstances := new(LicenseKeyInstancesApiResponse) |
39
|
|
|
if err = json.Unmarshal(*response.Body, licenseKeyInstances); err != nil { |
40
|
|
|
return nil, response, err |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return licenseKeyInstances, response, nil |
44
|
|
|
} |
45
|
|
|
|