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