-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollections.go
61 lines (51 loc) · 1.32 KB
/
collections.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
59
60
61
package crunchclient
import (
"context"
"fmt"
"net/http"
)
type CollectionsResult struct {
Count int32 `json:"num"`
Items []Collection `json:"list"`
}
type Collection struct {
Description struct {
Id string `json:"id"`
Name string `json:"name"`
IsShared bool `json:"isShared"`
TechnicalName string `json:"technicalName"`
} `json:"desc"`
Summary struct {
Org struct {
Name string `json:"name"`
} `json:"org"`
Read bool `json:"read"`
Write bool `json:"write"`
ApiCount int32 `json:"apis"`
} `json:"summary"`
Owner struct {
Id string `json:"id"`
Username string `json:"username"`
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
} `json:"owner"`
}
type CollectionsService struct {
client *Client
}
func (cs CollectionsService) GetAll(ctx context.Context) (c CollectionsResult, err error) {
req, err := cs.client.newRequest(ctx, http.MethodGet, "/api/v1/collections")
if err != nil {
return
}
_, err = cs.client.doRequest(req, &c)
return
}
func (cs CollectionsService) ReadCollection(ctx context.Context, id string) (c Collection, err error) {
req, err := cs.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("/api/v1/collections/%s", id))
if err != nil {
return
}
_, err = cs.client.doRequest(req, &c)
return
}