-
Notifications
You must be signed in to change notification settings - Fork 0
/
drisqus_users.go
309 lines (266 loc) · 8.68 KB
/
drisqus_users.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
// Copyright Piero de Salvia.
// All Rights Reserved
package drisqus
import (
"context"
"net/url"
"time"
"github.com/pierods/gisqus"
)
// UserActivities models the response of the user activity list endpoint
type UserActivities struct {
Posts []*gisqus.Post
}
/*
UserActivitiesQuick wraps UserActivities. It includes frequently used parameters, and sets the rest to their zero values
When pages is -1, all pages are retrieved.
*/
func (d *Drisqus) UserActivitiesQuick(ctx context.Context, userID string, pages int) (*UserActivities, error) {
return d.UserActivities(ctx, userID, pages, time.Time{}, []gisqus.Include{})
}
/*
UserActivities wraps https://disqus.com/api/docs/users/listActivity/ (https://disqus.com/api/3.0/users/listActivity.json)
When pages is -1, all pages are retrieved.
*/
func (d *Drisqus) UserActivities(ctx context.Context, userID string, pages int, since time.Time, includes []gisqus.Include) (*UserActivities, error) {
values := url.Values{}
if since != (time.Time{}) {
values.Set("since", gisqus.ToDisqusTime(since))
}
for _, include := range includes {
values.Add("include", string(include))
}
values.Set("limit", "100")
var activities UserActivities
gisqusResponse, err := d.gisqus.UserActivities(ctx, userID, values)
if err != nil {
return nil, err
}
for page := 0; page < pages || pages == -1; page++ {
activities.Posts = append(activities.Posts, gisqusResponse.Posts...)
if !gisqusResponse.Cursor.HasNext {
break
}
values.Set("cursor", gisqusResponse.Cursor.Next)
gisqusResponse, err = d.gisqus.UserActivities(ctx, userID, values)
if err != nil {
return nil, err
}
}
return &activities, nil
}
/*
UserMostActiveForums wraps https://disqus.com/api/docs/users/listMostActiveForums/ (https://disqus.com/api/3.0/users/listMostActiveForums.json)
*/
func (d *Drisqus) UserMostActiveForums(ctx context.Context, userID string) ([]*gisqus.Forum, error) {
values := url.Values{}
values.Set("limit", "100")
forums, err := d.gisqus.UserMostActiveForums(ctx, userID, values)
if err != nil {
return nil, err
}
return forums.Response, nil
}
/*
UserPostsQuick wraps UserPosts. It includes frequently used parameters, and sets the rest to their zero values
When pages is -1, all pages are retrieved.
*/
func (d *Drisqus) UserPostsQuick(ctx context.Context, userID string, pages int) ([]*gisqus.Post, error) {
return d.UserPosts(ctx, userID, []gisqus.Include{}, pages, time.Time{}, "")
}
/*
UserPosts wraps https://disqus.com/api/docs/users/listPosts/ (https://disqus.com/api/3.0/users/listPosts.json)
It does not support the "related" argument (related fields can be gotten with calls to their respective APIS)
When pages is -1, all pages are retrieved.
*/
func (d *Drisqus) UserPosts(ctx context.Context, userID string, includes []gisqus.Include, pages int, since time.Time, order gisqus.Order) ([]*gisqus.Post, error) {
values := url.Values{}
if since != (time.Time{}) {
values.Set("since", gisqus.ToDisqusTime(since))
}
if order != "" {
values.Set("order", string(order))
}
for _, include := range includes {
values.Add("include", string(include))
}
values.Set("limit", "100")
var posts []*gisqus.Post
gisqusResponse, err := d.gisqus.UserPosts(ctx, userID, values)
if err != nil {
return nil, err
}
for page := 0; page < pages || pages == -1; page++ {
posts = append(posts, gisqusResponse.Response...)
if !gisqusResponse.Cursor.HasNext {
break
}
values.Set("cursor", gisqusResponse.Cursor.Next)
gisqusResponse, err = d.gisqus.UserPosts(ctx, userID, values)
if err != nil {
return nil, err
}
}
return posts, nil
}
/*
UserDetails wraps https://disqus.com/api/docs/users/details/ (https://disqus.com/api/3.0/users/details.json)
*/
func (d *Drisqus) UserDetails(ctx context.Context, userID string) (*gisqus.User, error) {
values := url.Values{}
details, err := d.gisqus.UserDetails(ctx, userID, values)
if err != nil {
return nil, err
}
return details.Response, nil
}
// InterestingUser models the response of the interesting users endpoint.
type InterestingUser struct {
Reason string
User *gisqus.User
}
/*
UserInteresting wraps https://disqus.com/api/docs/users/interestingUsers/ (https://disqus.com/api/3.0/users/interestingUsers.json)
When pages is -1, all pages are retrieved.
*/
func (d *Drisqus) UserInteresting(ctx context.Context, pages int) ([]*InterestingUser, error) {
values := url.Values{}
values.Set("limit", "100")
var interestingUsers []*InterestingUser
gisqusResponse, err := d.gisqus.UserInteresting(ctx, values)
if err != nil {
return nil, err
}
for page := 0; page < pages || pages == -1; page++ {
for _, item := range gisqusResponse.Response.Items {
interestingUser := InterestingUser{
Reason: item.Reason,
User: gisqusResponse.Response.Objects[item.ID],
}
interestingUsers = append(interestingUsers, &interestingUser)
}
if !gisqusResponse.Cursor.HasNext {
break
}
values.Set("cursor", gisqusResponse.Cursor.Next)
gisqusResponse, err = d.gisqus.UserInteresting(ctx, values)
if err != nil {
return nil, err
}
}
return interestingUsers, nil
}
/*
UserActiveForums wraps https://disqus.com/api/docs/users/listActiveForums/ (https://disqus.com/api/3.0/users/listActiveForums.json)
When pages is -1, all pages are retrieved.
*/
func (d *Drisqus) UserActiveForums(ctx context.Context, userID string, pages int, order gisqus.Order) ([]*gisqus.Forum, error) {
values := url.Values{}
if order != "" {
values.Set("order", string(order))
}
values.Set("limit", "100")
var forums []*gisqus.Forum
gisqusResponse, err := d.gisqus.UserActiveForums(ctx, userID, values)
if err != nil {
return nil, err
}
for page := 0; page < pages || pages == -1; page++ {
forums = append(forums, gisqusResponse.Response...)
if !gisqusResponse.Cursor.HasNext {
break
}
values.Set("cursor", gisqusResponse.Cursor.Next)
gisqusResponse, err = d.gisqus.UserActiveForums(ctx, userID, values)
if err != nil {
return nil, err
}
}
return forums, nil
}
/*
UserFollowers wraps https://disqus.com/api/docs/users/listFollowers/ (https://disqus.com/api/3.0/users/listFollowers.json)
Numlikes, NumPosts, NumFollowers are not returned by Disqus' API
When pages is -1, all pages are retrieved.
*/
func (d *Drisqus) UserFollowers(ctx context.Context, userID string, pages int, order gisqus.Order) ([]*gisqus.User, error) {
values := url.Values{}
if order != "" {
values.Set("order", string(order))
}
values.Set("limit", "100")
var users []*gisqus.User
gisqusResponse, err := d.gisqus.UserFollowers(ctx, userID, values)
if err != nil {
return nil, err
}
for page := 0; page < pages || pages == -1; page++ {
users = append(users, gisqusResponse.Response...)
if !gisqusResponse.Cursor.HasNext {
break
}
values.Set("cursor", gisqusResponse.Cursor.Next)
gisqusResponse, err = d.gisqus.UserFollowers(ctx, userID, values)
if err != nil {
return nil, err
}
}
return users, nil
}
/*
UserFollowing wraps https://disqus.com/api/docs/users/listFollowing/ (https://disqus.com/api/3.0/users/listFollowing.json)
Numlikes, NumPosts, NumFollowers are not returned by Disqus' API
When pages is -1, all pages are retrieved.
*/
func (d *Drisqus) UserFollowing(ctx context.Context, userID string, pages int, order gisqus.Order) ([]*gisqus.User, error) {
values := url.Values{}
if order != "" {
values.Set("order", string(order))
}
values.Set("limit", "100")
var users []*gisqus.User
gisqusResponse, err := d.gisqus.UserFollowing(ctx, userID, values)
if err != nil {
return nil, err
}
for page := 0; page < pages || pages == -1; page++ {
users = append(users, gisqusResponse.Response...)
if !gisqusResponse.Cursor.HasNext {
break
}
values.Set("cursor", gisqusResponse.Cursor.Next)
gisqusResponse, err = d.gisqus.UserFollowing(ctx, userID, values)
if err != nil {
return nil, err
}
}
return users, nil
}
/*
UserForumFollowing wraps https://disqus.com/api/docs/users/listFollowingForums/ (https://disqus.com/api/3.0/users/listFollowingForums.json)
When pages is -1, all pages are retrieved.
*/
func (d *Drisqus) UserForumFollowing(ctx context.Context, userID string, pages int, order gisqus.Order) ([]*gisqus.Forum, error) {
values := url.Values{}
if order != "" {
values.Set("order", string(order))
}
values.Set("limit", "100")
var forums []*gisqus.Forum
gisqusResponse, err := d.gisqus.UserForumFollowing(ctx, userID, values)
if err != nil {
return nil, err
}
for page := 0; page < pages || pages == -1; page++ {
forums = append(forums, gisqusResponse.Response...)
if !gisqusResponse.Cursor.HasNext {
break
}
values.Set("cursor", gisqusResponse.Cursor.Next)
gisqusResponse, err = d.gisqus.UserForumFollowing(ctx, userID, values)
if err != nil {
return nil, err
}
}
return forums, nil
}