forked from NdoleStudio/lemonsqueezy-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
products_service.go
44 lines (36 loc) · 1.18 KB
/
products_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
package lemonsqueezy
import (
"context"
"encoding/json"
"net/http"
)
// ProductsService is the API client for the `/v1/products` endpoint
type ProductsService service
// Get returns the product with the given ID.
//
// https://docs.lemonsqueezy.com/api/products#retrieve-a-product
func (service *ProductsService) Get(ctx context.Context, productID string) (*ProductApiResponse, *Response, error) {
response, err := service.client.do(ctx, http.MethodGet, "/v1/products/"+productID)
if err != nil {
return nil, response, err
}
product := new(ProductApiResponse)
if err = json.Unmarshal(*response.Body, product); err != nil {
return nil, response, err
}
return product, response, nil
}
// List returns a paginated list of products.
//
// https://docs.lemonsqueezy.com/api/products#list-all-products
func (service *ProductsService) List(ctx context.Context) (*ProductsApiResponse, *Response, error) {
response, err := service.client.do(ctx, http.MethodGet, "/v1/products")
if err != nil {
return nil, response, err
}
products := new(ProductsApiResponse)
if err = json.Unmarshal(*response.Body, products); err != nil {
return nil, response, err
}
return products, response, nil
}