generated from NdoleStudio/go-http-client
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathprices_service.go
45 lines (37 loc) · 1.15 KB
/
prices_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"
)
// PricesService is the API client for the `/v1/prices` endpoint
type PricesService service
// Get returns the price with the given ID.
//
// https://docs.lemonsqueezy.com/api/prices#retrieve-a-price
func (service *PricesService) Get(ctx context.Context, priceID int) (*PriceAPIResponse, *Response, error) {
response, err := service.client.do(ctx, http.MethodGet, "/v1/prices/"+strconv.Itoa(priceID))
if err != nil {
return nil, response, err
}
price := new(PriceAPIResponse)
if err = json.Unmarshal(*response.Body, price); err != nil {
return nil, response, err
}
return price, response, nil
}
// List returns a paginated list of prices.
//
// https://docs.lemonsqueezy.com/api/prices#list-all-prices
func (service *PricesService) List(ctx context.Context) (*PricesAPIResponse, *Response, error) {
response, err := service.client.do(ctx, http.MethodGet, "/v1/prices")
if err != nil {
return nil, response, err
}
prices := new(PricesAPIResponse)
if err = json.Unmarshal(*response.Body, prices); err != nil {
return nil, response, err
}
return prices, response, nil
}