-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabels.go
58 lines (46 loc) · 1.23 KB
/
labels.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
46
47
48
49
50
51
52
53
54
55
56
57
58
package goqonto
import (
"context"
"net/http"
)
// labelsBasePath Qonto API Labels Endpoint
const labelsBasePath = "v2/labels"
// LabelsService provides access to the labels in Qonto API
type LabelsService service
// LabelsOptions Qonto API Labels query strings
// https://api-doc.qonto.eu/2.0/labels/list-labels
type LabelsOptions struct {
CurrentPage int64 `json:"current_page,omitempty"`
PerPage int64 `json:"per_page,omitempty"`
}
// Label struct
// https://api-doc.qonto.eu/2.0/labels/list-labels
type Label struct {
ID string `json:"id"`
Name string `json:"name"`
ParentID string `json:"parent_id"`
}
// labelsRoot root key in the JSON response for labels
type labelsRoot struct {
Labels []Label `json:"labels"`
}
// List all the labels
func (s *LabelsService) List(ctx context.Context, opt *LabelsOptions) ([]Label, *Response, error) {
req, err := s.client.NewRequest(ctx, http.MethodGet, labelsBasePath, opt)
if err != nil {
return nil, nil, err
}
type respWithMeta struct {
labelsRoot
metaRoot
}
root := new(respWithMeta)
resp, err := s.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
}
if m := &root.metaRoot; m != nil {
resp.Meta = &m.Meta
}
return root.Labels, resp, nil
}