generated from NdoleStudio/go-http-client
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathvariants_service.go
45 lines (37 loc) · 1.2 KB
/
variants_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package lemonsqueezy
import (
"context"
"encoding/json"
"net/http"
"strconv"
)
// VariantsService is the API client for the `/v1/variants` endpoint
type VariantsService service
// Get returns the variant with the given ID.
//
// https://docs.lemonsqueezy.com/api/variants#retrieve-a-variant
func (service *VariantsService) Get(ctx context.Context, variantID int) (*VariantAPIResponse, *Response, error) {
response, err := service.client.do(ctx, http.MethodGet, "/v1/variants/"+strconv.Itoa(variantID))
if err != nil {
return nil, response, err
}
variant := new(VariantAPIResponse)
if err = json.Unmarshal(*response.Body, variant); err != nil {
return nil, response, err
}
return variant, response, nil
}
// List returns a paginated list of variants.
//
// https://docs.lemonsqueezy.com/api/variants#list-all-variants
func (service *VariantsService) List(ctx context.Context) (*VariantsAPIResponse, *Response, error) {
response, err := service.client.do(ctx, http.MethodGet, "/v1/variants")
if err != nil {
return nil, response, err
}
variants := new(VariantsAPIResponse)
if err = json.Unmarshal(*response.Body, variants); err != nil {
return nil, response, err
}
return variants, response, nil
}