forked from dghubble/go-twitter
/
lists.go
434 lines (385 loc) · 18.8 KB
/
lists.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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
package twitter
import (
"net/http"
"github.com/dghubble/sling"
)
// List represents a Twitter List.
type List struct {
Slug string `json:"slug"`
Name string `json:"name"`
CreatedAt string `json:"created_at"`
URI string `json:"uri"`
SubscriberCount int `json:"subscriber_count"`
IDStr string `json:"id_str"`
MemberCount int `json:"member_count"`
Mode string `json:"mode"`
ID int64 `json:"id"`
FullName string `json:"full_name"`
Description string `json:"description"`
User *User `json:"user"`
Following bool `json:"following"`
}
// Members is a cursored collection of list members.
type Members struct {
Users []User `json:"users"`
NextCursor int64 `json:"next_cursor"`
NextCursorStr string `json:"next_cursor_str"`
PreviousCursor int64 `json:"previous_cursor"`
PreviousCursorStr string `json:"previous_cursor_str"`
}
// Membership is a cursored collection of lists a user is on.
type Membership struct {
Lists []List `json:"lists"`
NextCursor int64 `json:"next_cursor"`
NextCursorStr string `json:"next_cursor_str"`
PreviousCursor int64 `json:"previous_cursor"`
PreviousCursorStr string `json:"previous_cursor_str"`
}
// Ownership is a cursored collection of lists a user owns.
type Ownership struct {
Lists []List `json:"lists"`
NextCursor int64 `json:"next_cursor"`
NextCursorStr string `json:"next_cursor_str"`
PreviousCursor int64 `json:"previous_cursor"`
PreviousCursorStr string `json:"previous_cursor_str"`
}
// Subscribers is a cursored collection of users that subscribe to a list.
type Subscribers struct {
Users []User `json:"users"`
NextCursor int64 `json:"next_cursor"`
NextCursorStr string `json:"next_cursor_str"`
PreviousCursor int64 `json:"previous_cursor"`
PreviousCursorStr string `json:"previous_cursor_str"`
}
// Subscribed is a cursored collection of lists the user is subscribed to.
type Subscribed struct {
Lists []List `json:"lists"`
NextCursor int64 `json:"next_cursor"`
NextCursorStr string `json:"next_cursor_str"`
PreviousCursor int64 `json:"previous_cursor"`
PreviousCursorStr string `json:"previous_cursor_str"`
}
// ListsService provides methods for accessing Twitter lists endpoints.
type ListsService struct {
sling *sling.Sling
}
// newListService returns a new ListService.
func newListService(sling *sling.Sling) *ListsService {
return &ListsService{
sling: sling.Path("lists/"),
}
}
// ListsListParams are the parameters for ListsService.List
type ListsListParams struct {
UserID int64 `url:"user_id,omitempty"`
ScreenName string `url:"screen_name,omitempty"`
Reverse bool `url:"reverse,omitempty"`
}
// List eturns all lists the authenticating or specified user subscribes to, including their own.
// https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-list
func (s *ListsService) List(params *ListsListParams) ([]List, *http.Response, error) {
list := new([]List)
apiError := new(APIError)
resp, err := s.sling.New().Get("list.json").QueryStruct(params).Receive(list, apiError)
return *list, resp, relevantError(err, *apiError)
}
// ListsMembersParams are the parameters for ListsService.Members
type ListsMembersParams struct {
ListID int64 `url:"list_id,omitempty"`
Slug string `url:"slug,omitempty"`
OwnerScreenName string `url:"owner_screen_name,omitempty"`
OwnerID int64 `url:"owner_id,omitempty"`
Count int `url:"count,omitempty"`
Cursor int64 `url:"cursor,omitempty"`
IncludeEntities *bool `url:"include_entities,omitempty"`
SkipStatus *bool `url:"skip_status,omitempty"`
}
// Members returns the members of the specified list
// https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-members
func (s *ListsService) Members(params *ListsMembersParams) (*Members, *http.Response, error) {
members := new(Members)
apiError := new(APIError)
resp, err := s.sling.New().Get("members.json").QueryStruct(params).Receive(members, apiError)
return members, resp, relevantError(err, *apiError)
}
// ListsMembersShowParams are the parameters for ListsService.MembersShow
type ListsMembersShowParams struct {
ListID int64 `url:"list_id,omitempty"`
Slug string `url:"slug,omitempty"`
UserID int64 `url:"user_id,omitempty"`
ScreenName string `url:"screen_name,omitempty"`
OwnerScreenName string `url:"owner_screen_name,omitempty"`
OwnerID int64 `url:"owner_id,omitempty"`
IncludeEntities *bool `url:"include_entities,omitempty"`
SkipStatus *bool `url:"skip_status,omitempty"`
}
// MembersShow checks if the specified user is a member of the specified list.
// https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-members-show
func (s *ListsService) MembersShow(params *ListsMembersShowParams) (*User, *http.Response, error) {
user := new(User)
apiError := new(APIError)
resp, err := s.sling.New().Get("members/show.json").QueryStruct(params).Receive(user, apiError)
return user, resp, relevantError(err, *apiError)
}
// ListsMembershipsParams are the parameters for ListsService.Memberships
type ListsMembershipsParams struct {
UserID int64 `url:"user_id,omitempty"`
ScreenName string `url:"screen_name,omitempty"`
Count int `url:"count,omitempty"`
Cursor int64 `url:"cursor,omitempty"`
FilterToOwnedLists *bool `url:"filter_to_owned_lists,omitempty"`
}
// Memberships returns the lists the specified user has been added to.
// https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-memberships
func (s *ListsService) Memberships(params *ListsMembershipsParams) (*Membership, *http.Response, error) {
membership := new(Membership)
apiError := new(APIError)
resp, err := s.sling.New().Get("memberships.json").QueryStruct(params).Receive(membership, apiError)
return membership, resp, relevantError(err, *apiError)
}
// ListsOwnershipsParams are the parameters for ListsService.Ownerships
type ListsOwnershipsParams struct {
UserID int64 `url:"user_id,omitempty"`
ScreenName string `url:"screen_name,omitempty"`
Count int `url:"count,omitempty"`
Cursor int64 `url:"cursor,omitempty"`
}
// Ownerships returns the lists owned by the specified Twitter user.
// https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-ownerships
func (s *ListsService) Ownerships(params *ListsOwnershipsParams) (*Ownership, *http.Response, error) {
ownership := new(Ownership)
apiError := new(APIError)
resp, err := s.sling.New().Get("ownerships.json").QueryStruct(params).Receive(ownership, apiError)
return ownership, resp, relevantError(err, *apiError)
}
// ListsShowParams are the parameters for ListsService.Show
type ListsShowParams struct {
ListID int64 `url:"list_id,omitempty"`
Slug string `url:"slug,omitempty"`
OwnerScreenName string `url:"owner_screen_name,omitempty"`
OwnerID int64 `url:"owner_id,omitempty"`
}
// Show returns the specified list.
// https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-show
func (s *ListsService) Show(params *ListsShowParams) (*List, *http.Response, error) {
list := new(List)
apiError := new(APIError)
resp, err := s.sling.New().Get("show.json").QueryStruct(params).Receive(list, apiError)
return list, resp, relevantError(err, *apiError)
}
// ListsStatusesParams are the parameters for ListsService.Statuses
type ListsStatusesParams struct {
ListID int64 `url:"list_id,omitempty"`
Slug string `url:"slug,omitempty"`
OwnerScreenName string `url:"owner_screen_name,omitempty"`
OwnerID int64 `url:"owner_id,omitempty"`
SinceID int64 `url:"since_id,omitempty"`
MaxID int64 `url:"max_id,omitempty"`
Count int `url:"count,omitempty"`
IncludeEntities *bool `url:"include_entities,omitempty"`
IncludeRetweets *bool `url:"include_rts,omitempty"`
}
// Statuses returns a timeline of tweets authored by members of the specified list.
// https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-statuses
func (s *ListsService) Statuses(params *ListsStatusesParams) ([]Tweet, *http.Response, error) {
tweets := new([]Tweet)
apiError := new(APIError)
resp, err := s.sling.New().Get("statuses.json").QueryStruct(params).Receive(tweets, apiError)
return *tweets, resp, relevantError(err, *apiError)
}
// ListsSubscribersParams are the parameters for ListsService.Subscribers
type ListsSubscribersParams struct {
ListID int64 `url:"list_id,omitempty"`
Slug string `url:"slug,omitempty"`
OwnerScreenName string `url:"owner_screen_name,omitempty"`
OwnerID int64 `url:"owner_id,omitempty"`
Count int `url:"count,omitempty"`
Cursor int64 `url:"cursor,omitempty"`
IncludeEntities *bool `url:"include_entities,omitempty"`
SkipStatus *bool `url:"skip_status,omitempty"`
}
// Subscribers returns the subscribers of the specified list.
// https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-subscribers
func (s *ListsService) Subscribers(params *ListsSubscribersParams) (*Subscribers, *http.Response, error) {
subscribers := new(Subscribers)
apiError := new(APIError)
resp, err := s.sling.New().Get("subscribers.json").QueryStruct(params).Receive(subscribers, apiError)
return subscribers, resp, relevantError(err, *apiError)
}
// ListsSubscribersShowParams are the parameters for ListsService.SubscribersShow
type ListsSubscribersShowParams struct {
OwnerScreenName string `url:"owner_screen_name,omitempty"`
OwnerID int64 `url:"owner_id,omitempty"`
ListID int64 `url:"list_id,omitempty"`
Slug string `url:"slug,omitempty"`
UserID int64 `url:"user_id,omitempty"`
ScreenName string `url:"screen_name,omitempty"`
IncludeEntities *bool `url:"include_entities,omitempty"`
SkipStatus *bool `url:"skip_status,omitempty"`
}
// SubscribersShow returns the user if they are a subscriber to the list.
// https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-subscribers-show
func (s *ListsService) SubscribersShow(params *ListsSubscribersShowParams) (*User, *http.Response, error) {
user := new(User)
apiError := new(APIError)
resp, err := s.sling.New().Get("subscribers/show.json").QueryStruct(params).Receive(user, apiError)
return user, resp, relevantError(err, *apiError)
}
// ListsSubscriptionsParams are the parameters for ListsService.Subscriptions
type ListsSubscriptionsParams struct {
UserID int64 `url:"user_id,omitempty"`
ScreenName string `url:"screen_name,omitempty"`
Count int `url:"count,omitempty"`
Cursor int64 `url:"cursor,omitempty"`
}
// Subscriptions returns a collection of the lists the specified user is subscribed to.
// https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-subscriptions
func (s *ListsService) Subscriptions(params *ListsSubscriptionsParams) (*Subscribed, *http.Response, error) {
subscribed := new(Subscribed)
apiError := new(APIError)
resp, err := s.sling.New().Get("subscriptions.json").QueryStruct(params).Receive(subscribed, apiError)
return subscribed, resp, relevantError(err, *apiError)
}
// ListsCreateParams are the parameters for ListsService.Create
type ListsCreateParams struct {
Name string `url:"name,omitempty"`
Mode string `url:"mode,omitempty"`
Description string `url:"description,omitempty"`
}
// Create creates a new list for the authenticated user.
// https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-create
func (s *ListsService) Create(name string, params *ListsCreateParams) (*List, *http.Response, error) {
if params == nil {
params = &ListsCreateParams{}
}
params.Name = name
list := new(List)
apiError := new(APIError)
resp, err := s.sling.New().Post("create.json").BodyForm(params).Receive(list, apiError)
return list, resp, relevantError(err, *apiError)
}
// ListsDestroyParams are the parameters for ListsService.Destroy
type ListsDestroyParams struct {
OwnerScreenName string `url:"owner_screen_name,omitempty"`
OwnerID int64 `url:"owner_id,omitempty"`
ListID int64 `url:"list_id,omitempty"`
Slug string `url:"slug,omitempty"`
}
// Destroy deletes the specified list.
// https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-destroy
func (s *ListsService) Destroy(params *ListsDestroyParams) (*List, *http.Response, error) {
list := new(List)
apiError := new(APIError)
resp, err := s.sling.New().Post("destroy.json").BodyForm(params).Receive(list, apiError)
return list, resp, relevantError(err, *apiError)
}
// ListsMembersCreateParams are the parameters for ListsService.MembersCreate
type ListsMembersCreateParams struct {
ListID int64 `url:"list_id,omitempty"`
Slug string `url:"slug,omitempty"`
UserID int64 `url:"user_id,omitempty"`
ScreenName string `url:"screen_name,omitempty"`
OwnerScreenName string `url:"owner_screen_name,omitempty"`
OwnerID int64 `url:"owner_id,omitempty"`
}
// MembersCreate adds a member to a list.
// https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-members-create
func (s *ListsService) MembersCreate(params *ListsMembersCreateParams) (*http.Response, error) {
apiError := new(APIError)
resp, err := s.sling.New().Post("members/create.json").BodyForm(params).Receive(nil, apiError)
return resp, err
}
// ListsMembersCreateAllParams are the parameters for ListsService.MembersCreateAll
type ListsMembersCreateAllParams struct {
ListID int64 `url:"list_id,omitempty"`
Slug string `url:"slug,omitempty"`
UserID string `url:"user_id,omitempty"`
ScreenName string `url:"screen_name,omitempty"`
OwnerScreenName string `url:"owner_screen_name,omitempty"`
OwnerID int64 `url:"owner_id,omitempty"`
}
// MembersCreateAll adds multiple members to a list.
// https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-members-create_all
func (s *ListsService) MembersCreateAll(params *ListsMembersCreateAllParams) (*http.Response, error) {
apiError := new(APIError)
resp, err := s.sling.New().Post("members/create_all.json").BodyForm(params).Receive(nil, apiError)
return resp, err
}
// ListsMembersDestroyParams are the parameters for ListsService.MembersDestroy
type ListsMembersDestroyParams struct {
ListID int64 `url:"list_id,omitempty"`
Slug string `url:"slug,omitempty"`
UserID int64 `url:"user_id,omitempty"`
ScreenName string `url:"screen_name,omitempty"`
OwnerScreenName string `url:"owner_screen_name,omitempty"`
OwnerID int64 `url:"owner_id,omitempty"`
}
// MembersDestroy removes the specified member from the list.
// https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-members-destroy
func (s *ListsService) MembersDestroy(params *ListsMembersDestroyParams) (*http.Response, error) {
apiError := new(APIError)
resp, err := s.sling.New().Post("members/destroy.json").BodyForm(params).Receive(nil, apiError)
return resp, err
}
// ListsMembersDestroyAllParams are the parameters for ListsService.MembersDestroyAll
type ListsMembersDestroyAllParams struct {
ListID int64 `url:"list_id,omitempty"`
Slug string `url:"slug,omitempty"`
UserID string `url:"user_id,omitempty"`
ScreenName string `url:"screen_name,omitempty"`
OwnerScreenName string `url:"owner_screen_name,omitempty"`
OwnerID int64 `url:"owner_id,omitempty"`
}
// MembersDestroyAll removes multiple members from a list.
// https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-members-destroy_all
func (s *ListsService) MembersDestroyAll(params *ListsMembersDestroyAllParams) (*http.Response, error) {
apiError := new(APIError)
resp, err := s.sling.New().Post("members/destroy_all.json").BodyForm(params).Receive(nil, apiError)
return resp, err
}
// ListsSubscribersCreateParams are the parameters for ListsService.SubscribersCreate
type ListsSubscribersCreateParams struct {
OwnerScreenName string `url:"owner_screen_name,omitempty"`
OwnerID int64 `url:"owner_id,omitempty"`
ListID int64 `url:"list_id,omitempty"`
Slug string `url:"slug,omitempty"`
}
// SubscribersCreate subscribes the authenticated user to the specified list.
// https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-subscribers-create
func (s *ListsService) SubscribersCreate(params *ListsSubscribersCreateParams) (*List, *http.Response, error) {
list := new(List)
apiError := new(APIError)
resp, err := s.sling.New().Post("subscribers/create.json").BodyForm(params).Receive(list, apiError)
return list, resp, err
}
// ListsSubscribersDestroyParams are the parameters for ListsService.SubscribersDestroy
type ListsSubscribersDestroyParams struct {
ListID int64 `url:"list_id,omitempty"`
Slug string `url:"slug,omitempty"`
OwnerScreenName string `url:"owner_screen_name,omitempty"`
OwnerID int64 `url:"owner_id,omitempty"`
}
// SubscribersDestroy unsubscribes the authenticated user from the specified list.
// https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-subscribers-destroy
func (s *ListsService) SubscribersDestroy(params *ListsSubscribersDestroyParams) (*http.Response, error) {
apiError := new(APIError)
resp, err := s.sling.New().Post("subscribers/destroy.json").BodyForm(params).Receive(nil, apiError)
return resp, err
}
// ListsUpdateParams are the parameters for ListsService.Update
type ListsUpdateParams struct {
ListID int64 `url:"list_id,omitempty"`
Slug string `url:"slug,omitempty"`
Name string `url:"name,omitempty"`
Mode string `url:"mode,omitempty"`
Description string `url:"description,omitempty"`
OwnerScreenName string `url:"owner_screen_name,omitempty"`
OwnerID int64 `url:"owner_id,omitempty"`
}
// Update updates the specified list.
// https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-update
func (s *ListsService) Update(params *ListsUpdateParams) (*http.Response, error) {
apiError := new(APIError)
resp, err := s.sling.New().Post("update.json").BodyForm(params).Receive(nil, apiError)
return resp, err
}