generated from NdoleStudio/go-http-client
-
Notifications
You must be signed in to change notification settings - Fork 17
/
files_service.go
44 lines (36 loc) · 1.11 KB
/
files_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"
)
// FilesService is the API client for the `/v1/files` endpoint
type FilesService service
// Get returns the file with the given ID.
//
// https://docs.lemonsqueezy.com/api/files#retrieve-a-file
func (service *FilesService) Get(ctx context.Context, fileID string) (*FileApiResponse, *Response, error) {
response, err := service.client.do(ctx, http.MethodGet, "/v1/files/"+fileID)
if err != nil {
return nil, response, err
}
file := new(FileApiResponse)
if err = json.Unmarshal(*response.Body, file); err != nil {
return nil, response, err
}
return file, response, nil
}
// List returns a paginated list of files.
//
// https://docs.lemonsqueezy.com/api/files#list-all-files
func (service *FilesService) List(ctx context.Context) (*FilesApiResponse, *Response, error) {
response, err := service.client.do(ctx, http.MethodGet, "/v1/files")
if err != nil {
return nil, response, err
}
files := new(FilesApiResponse)
if err = json.Unmarshal(*response.Body, files); err != nil {
return nil, response, err
}
return files, response, nil
}