-
Notifications
You must be signed in to change notification settings - Fork 3
/
responses.go
456 lines (400 loc) · 11.5 KB
/
responses.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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
package twigo
import (
"encoding/json"
"fmt"
"net/http"
"time"
"github.com/arshamalh/twigo/entities"
)
type CallerData struct {
ID string
Params Map
}
// *** Response Entities *** //
type TweetResponse struct {
Data entities.Tweet
Includes IncludesEntity
Errors []ErrorEntity
Meta MetaEntity
RateLimits RateLimits
}
func (r *TweetResponse) Parse(raw_response *http.Response) (*TweetResponse, error) {
err := json.NewDecoder(raw_response.Body).Decode(&r)
defer raw_response.Body.Close()
r.RateLimits.Set(raw_response.Header)
return r, err
}
type TweetsResponse struct {
Data []entities.Tweet
Includes IncludesEntity
Errors []ErrorEntity
Meta MetaEntity
RateLimits RateLimits
CallerData CallerData
Caller func(string, Map) (*TweetsResponse, error)
}
func (r *TweetsResponse) Parse(raw_response *http.Response) (*TweetsResponse, error) {
err := json.NewDecoder(raw_response.Body).Decode(&r)
defer raw_response.Body.Close()
r.RateLimits.Set(raw_response.Header)
return r, err
}
func (r *TweetsResponse) NextPage() (*TweetsResponse, error) {
if r.Meta.NextToken == "" {
return nil, fmt.Errorf("no next page")
}
r.CallerData.Params["pagination_token"] = r.Meta.NextToken
return r.Caller(r.CallerData.ID, r.CallerData.Params)
}
type BookmarkedTweetsResponse struct {
Data []entities.Tweet
Includes IncludesEntity
Errors []ErrorEntity
Meta MetaEntity
RateLimits RateLimits
CallerData CallerData
Caller func(Map) (*BookmarkedTweetsResponse, error)
}
func (r *BookmarkedTweetsResponse) Parse(raw_response *http.Response) (*BookmarkedTweetsResponse, error) {
err := json.NewDecoder(raw_response.Body).Decode(&r)
defer raw_response.Body.Close()
r.RateLimits.Set(raw_response.Header)
return r, err
}
func (r *BookmarkedTweetsResponse) NextPage() (*BookmarkedTweetsResponse, error) {
if r.Meta.NextToken == "" {
return nil, fmt.Errorf("no next page")
}
r.CallerData.Params["pagination_token"] = r.Meta.NextToken
return r.Caller(r.CallerData.Params)
}
type UserResponse struct {
Data entities.User
Includes IncludesEntity
Errors []ErrorEntity
Meta MetaEntity
RateLimits RateLimits
}
func (r *UserResponse) Parse(raw_response *http.Response) (*UserResponse, error) {
err := json.NewDecoder(raw_response.Body).Decode(&r)
defer raw_response.Body.Close()
r.RateLimits.Set(raw_response.Header)
return r, err
}
type UsersResponse struct {
Data []entities.User
Includes IncludesEntity
Errors []ErrorEntity
Meta MetaEntity
RateLimits RateLimits
CallerData CallerData
Caller func(string, Map) (*UsersResponse, error)
}
func (r *UsersResponse) Parse(raw_response *http.Response) (*UsersResponse, error) {
err := json.NewDecoder(raw_response.Body).Decode(&r)
defer raw_response.Body.Close()
r.RateLimits.Set(raw_response.Header)
return r, err
}
func (r *UsersResponse) NextPage() (*UsersResponse, error) {
if r.Meta.NextToken == "" {
return nil, fmt.Errorf("no next page")
}
r.CallerData.Params["pagination_token"] = r.Meta.NextToken
return r.Caller(r.CallerData.ID, r.CallerData.Params)
}
type MutedUsersResponse struct {
Data []entities.User
Includes IncludesEntity
Errors []ErrorEntity
Meta MetaEntity
RateLimits RateLimits
CallerData CallerData
Caller func(Map) (*MutedUsersResponse, error)
}
func (r *MutedUsersResponse) Parse(raw_response *http.Response) (*MutedUsersResponse, error) {
err := json.NewDecoder(raw_response.Body).Decode(&r)
defer raw_response.Body.Close()
r.RateLimits.Set(raw_response.Header)
return r, err
}
func (r *MutedUsersResponse) NextPage() (*MutedUsersResponse, error) {
if r.Meta.NextToken == "" {
return nil, fmt.Errorf("no next page")
}
r.CallerData.Params["pagination_token"] = r.Meta.NextToken
return r.Caller(r.CallerData.Params)
}
type SpaceResponse struct {
Data entities.Space
Includes IncludesEntity
Errors []ErrorEntity
Meta MetaEntity
RateLimits RateLimits
}
func (r *SpaceResponse) Parse(raw_response *http.Response) (*SpaceResponse, error) {
err := json.NewDecoder(raw_response.Body).Decode(&r)
defer raw_response.Body.Close()
r.RateLimits.Set(raw_response.Header)
return r, err
}
type SpacesResponse struct {
Data entities.Space
Includes IncludesEntity
Errors []ErrorEntity
Meta MetaEntity
RateLimits RateLimits
}
func (r *SpacesResponse) Parse(raw_response *http.Response) (*SpacesResponse, error) {
err := json.NewDecoder(raw_response.Body).Decode(&r)
defer raw_response.Body.Close()
r.RateLimits.Set(raw_response.Header)
return r, err
}
type ListResponse struct {
Data List
Includes IncludesEntity
Errors []ErrorEntity
Meta MetaEntity
RateLimits RateLimits
}
func (r *ListResponse) Parse(raw_response *http.Response) (*ListResponse, error) {
err := json.NewDecoder(raw_response.Body).Decode(&r)
defer raw_response.Body.Close()
r.RateLimits.Set(raw_response.Header)
return r, err
}
type ListsResponse struct {
Data []List
Includes IncludesEntity
Errors []ErrorEntity
Meta MetaEntity
RateLimits RateLimits
CallerData CallerData
Caller func(string, Map) (*ListsResponse, error)
}
func (r *ListsResponse) Parse(raw_response *http.Response) (*ListsResponse, error) {
err := json.NewDecoder(raw_response.Body).Decode(&r)
defer raw_response.Body.Close()
r.RateLimits.Set(raw_response.Header)
return r, err
}
func (r *ListsResponse) NextPage() (*ListsResponse, error) {
if r.Meta.NextToken == "" {
return nil, fmt.Errorf("no next page")
}
r.CallerData.Params["pagination_token"] = r.Meta.NextToken
return r.Caller(r.CallerData.ID, r.CallerData.Params)
}
type LikeResponse struct {
Data struct {
Liked bool `json:"liked"`
}
Includes IncludesEntity
Errors []ErrorEntity
Meta MetaEntity
RateLimits RateLimits
}
func (r *LikeResponse) Parse(raw_response *http.Response) (*LikeResponse, error) {
err := json.NewDecoder(raw_response.Body).Decode(&r)
defer raw_response.Body.Close()
r.RateLimits.Set(raw_response.Header)
return r, err
}
type HideReplyResponse struct {
Data struct {
Hidden bool `json:"hidden"`
}
Includes IncludesEntity
Errors []ErrorEntity
Meta MetaEntity
RateLimits RateLimits
}
func (r *HideReplyResponse) Parse(raw_response *http.Response) (*HideReplyResponse, error) {
err := json.NewDecoder(raw_response.Body).Decode(&r)
defer raw_response.Body.Close()
r.RateLimits.Set(raw_response.Header)
return r, err
}
type RetweetResponse struct {
Data struct {
Retweeted bool `json:"retweeted"`
}
Includes IncludesEntity
Errors []ErrorEntity
Meta MetaEntity
RateLimits RateLimits
}
func (r *RetweetResponse) Parse(raw_response *http.Response) (*RetweetResponse, error) {
err := json.NewDecoder(raw_response.Body).Decode(&r)
defer raw_response.Body.Close()
r.RateLimits.Set(raw_response.Header)
return r, err
}
type BlockResponse struct {
Data struct {
Blocking bool `json:"blocking"`
}
Includes IncludesEntity
Errors []ErrorEntity
Meta MetaEntity
RateLimits RateLimits
}
func (r *BlockResponse) Parse(raw_response *http.Response) (*BlockResponse, error) {
err := json.NewDecoder(raw_response.Body).Decode(&r)
defer raw_response.Body.Close()
r.RateLimits.Set(raw_response.Header)
return r, err
}
type FollowResponse struct {
Data struct {
Following bool `json:"following"`
}
Includes IncludesEntity
Errors []ErrorEntity
Meta MetaEntity
RateLimits RateLimits
}
func (r *FollowResponse) Parse(raw_response *http.Response) (*FollowResponse, error) {
err := json.NewDecoder(raw_response.Body).Decode(&r)
defer raw_response.Body.Close()
r.RateLimits.Set(raw_response.Header)
return r, err
}
type MuteResponse struct {
Data struct {
Muting bool `json:"muting"`
}
Includes IncludesEntity
Errors []ErrorEntity
Meta MetaEntity
RateLimits RateLimits
}
func (r *MuteResponse) Parse(raw_response *http.Response) (*MuteResponse, error) {
err := json.NewDecoder(raw_response.Body).Decode(&r)
defer raw_response.Body.Close()
r.RateLimits.Set(raw_response.Header)
return r, err
}
type ListMemberResponse struct {
Data struct {
IsMember bool `json:"is_member"`
}
Includes IncludesEntity
Errors []ErrorEntity
Meta MetaEntity
RateLimits RateLimits
}
func (r *ListMemberResponse) Parse(raw_response *http.Response) (*ListMemberResponse, error) {
err := json.NewDecoder(raw_response.Body).Decode(&r)
defer raw_response.Body.Close()
r.RateLimits.Set(raw_response.Header)
return r, err
}
type DeleteResponse struct {
Data struct {
Deleted bool `json:"deleted"`
}
Includes IncludesEntity
Errors []ErrorEntity
Meta MetaEntity
RateLimits RateLimits
}
func (r *DeleteResponse) Parse(raw_response *http.Response) (*DeleteResponse, error) {
err := json.NewDecoder(raw_response.Body).Decode(&r)
defer raw_response.Body.Close()
r.RateLimits.Set(raw_response.Header)
return r, err
}
type PinResponse struct {
Data struct {
Pinned bool `json:"pinned"`
}
Includes IncludesEntity
Errors []ErrorEntity
Meta MetaEntity
RateLimits RateLimits
}
func (r *PinResponse) Parse(raw_response *http.Response) (*PinResponse, error) {
err := json.NewDecoder(raw_response.Body).Decode(&r)
defer raw_response.Body.Close()
r.RateLimits.Set(raw_response.Header)
return r, err
}
type BookmarkResponse struct {
Data struct {
Bookmarked bool `json:"bookmarked"`
}
Includes IncludesEntity
Errors []ErrorEntity
Meta MetaEntity
RateLimits RateLimits
}
func (r *BookmarkResponse) Parse(raw_response *http.Response) (*BookmarkResponse, error) {
err := json.NewDecoder(raw_response.Body).Decode(&r)
defer raw_response.Body.Close()
r.RateLimits.Set(raw_response.Header)
return r, err
}
type UpdateListResponse struct {
Data struct {
Updated bool `json:"updated"`
}
Includes IncludesEntity
Errors []ErrorEntity
Meta MetaEntity
RateLimits RateLimits
}
func (r *UpdateListResponse) Parse(raw_response *http.Response) (*UpdateListResponse, error) {
err := json.NewDecoder(raw_response.Body).Decode(&r)
defer raw_response.Body.Close()
r.RateLimits.Set(raw_response.Header)
return r, err
}
type TweetsCountResponse struct {
Data struct {
End time.Time `json:"end"`
Start time.Time `json:"start"`
TweetCount int `json:"tweet_count"`
}
Meta struct {
// TODO: Also there is a "meta" field in the response that is a object
TotalTweetCount int `json:"total_tweet_count"`
NextToken string `json:"next_token"`
}
Includes IncludesEntity
Errors []ErrorEntity
RateLimits RateLimits
}
func (r *TweetsCountResponse) Parse(raw_response *http.Response) (*TweetsCountResponse, error) {
err := json.NewDecoder(raw_response.Body).Decode(&r)
defer raw_response.Body.Close()
r.RateLimits.Set(raw_response.Header)
return r, err
}
type ComplianceJobResponse struct {
Data entities.ComplianceJob
Includes IncludesEntity
Errors []ErrorEntity
Meta MetaEntity
RateLimits RateLimits
}
func (r *ComplianceJobResponse) Parse(raw_response *http.Response) (*ComplianceJobResponse, error) {
err := json.NewDecoder(raw_response.Body).Decode(&r)
defer raw_response.Body.Close()
r.RateLimits.Set(raw_response.Header)
return r, err
}
type ComplianceJobsResponse struct {
Data []entities.ComplianceJob
Includes IncludesEntity
Errors []ErrorEntity
Meta MetaEntity
RateLimits RateLimits
}
func (r *ComplianceJobsResponse) Parse(raw_response *http.Response) (*ComplianceJobsResponse, error) {
err := json.NewDecoder(raw_response.Body).Decode(&r)
defer raw_response.Body.Close()
r.RateLimits.Set(raw_response.Header)
return r, err
}