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