/
collections.go
155 lines (137 loc) · 3.65 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package feedly
import (
"context"
"encoding/json"
"io/ioutil"
"net/http"
"net/url"
"strings"
)
type apiCollections struct {
api *apiV3
}
type Collection struct {
Customizable bool `json:"customizable"`
Description string `json:"description"`
Enterprise bool `json:"enterprise"`
Feeds []Feed `json:"feeds"`
ID string `json:"id"`
Label string `json:"label"`
NumFeeds float64 `json:"numFeeds"`
}
func (a Collection) String() string {
e, err := json.Marshal(a)
if err != nil {
panic(err)
}
return string(e)
}
type Collections []Collection
func (a Collections) String() string {
s := make([]string, len(a))
for i, v := range a {
s[i] = v.String()
}
return "[" + strings.Join(s, ",") + "]"
}
type CollectionCreate struct {
Description string `json:"description,omitempty"`
Feeds []CollectionFeedCreate `json:"feeds"`
ID string `json:"id"`
Label string `json:"label"`
}
type CollectionFeedCreate struct {
ID string `json:"id"`
Title string `json:"title,omitempty"`
}
type CollectionFeedCreates []CollectionFeedCreate
type CollectionFeedDelete struct {
ID string `json:"id"`
}
type CollectionFeedDeletes []CollectionFeedDelete
func (a *apiCollections) CollectionsCreate(ctx context.Context, param *CollectionCreate) (
collections Collections,
err error,
) {
var req *http.Request
if req, err = a.api.NewRequest(ctx, "POST", "collections", param); err != nil {
return
}
if _, err = a.api.Do(req, &collections); err != nil {
return
}
return
}
func (a *apiCollections) CollectionsFeedsPut(ctx context.Context, id string, param CollectionFeedCreate) (
feeds Feeds,
err error,
) {
var req *http.Request
rel := "collections/" + url.QueryEscape(id) + "/feeds"
if req, err = a.api.NewRequest(ctx, "PUT", rel, param); err != nil {
return
}
if _, err = a.api.Do(req, &feeds); err != nil {
return
}
return
}
func (a *apiCollections) CollectionsFeedsMPut(ctx context.Context, id string, params CollectionFeedCreates) (
feeds Feeds,
err error,
) {
var req *http.Request
rel := "collections/" + url.QueryEscape(id) + "/feeds/.mput"
if req, err = a.api.NewRequest(ctx, "POST", rel, params); err != nil {
return
}
if _, err = a.api.Do(req, &feeds); err != nil {
return
}
return
}
func (a *apiCollections) CollectionsFeedsDelete(ctx context.Context, id, feedID string) (err error) {
var req *http.Request
rel := "collections/" + url.QueryEscape(id) + "/feeds/" + url.QueryEscape(feedID)
if req, err = a.api.NewRequest(ctx, "DELETE", rel, nil); err != nil {
return
}
if _, err = a.api.Do(req, ioutil.Discard); err != nil {
return
}
return
}
func (a *apiCollections) CollectionsFeedsMDelete(ctx context.Context, id string, param CollectionFeedDeletes) (
err error,
) {
var req *http.Request
rel := "collections/" + url.QueryEscape(id) + "/feeds/.mdelete"
if req, err = a.api.NewRequest(ctx, "DELETE", rel, param); err != nil {
return
}
if _, err = a.api.Do(req, ioutil.Discard); err != nil {
return
}
return
}
func (a *apiCollections) CollectionsGet(ctx context.Context, id string) (collections Collections, err error) {
var req *http.Request
rel := "collections/" + url.QueryEscape(id)
if req, err = a.api.NewRequest(ctx, "GET", rel, nil); err != nil {
return
}
if _, err = a.api.Do(req, &collections); err != nil {
return
}
return
}
func (a *apiCollections) CollectionsList(ctx context.Context) (collections Collections, err error) {
var req *http.Request
if req, err = a.api.NewRequest(ctx, "GET", "collections", nil); err != nil {
return
}
if _, err = a.api.Do(req, &collections); err != nil {
return
}
return
}