forked from ryanmcgrath/twython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathendpoints.py
More file actions
427 lines (395 loc) · 11.5 KB
/
endpoints.py
File metadata and controls
427 lines (395 loc) · 11.5 KB
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
"""
A huge map of every Twitter API endpoint to a function definition in Twython.
Parameters that need to be embedded in the URL are treated with mustaches, e.g:
{{version}}, etc
When creating new endpoint definitions, keep in mind that the name of the mustache
will be replaced with the keyword that gets passed in to the function at call time.
i.e, in this case, if I pass version = 47 to any function, {{version}} will be replaced
with 47, instead of defaulting to 1.1 (said defaulting takes place at conversion time).
This map is organized the order functions are documented at:
https://dev.twitter.com/docs/api/1.1
"""
api_table = {
# Timelines
'get_mentions_timeline': {
'url': '/statuses/mentions_timeline.json',
'method': 'GET',
},
'get_user_timeline': {
'url': '/statuses/user_timeline.json',
'method': 'GET',
},
'get_home_timeline': {
'url': '/statuses/home_timeline.json',
'method': 'GET',
},
'retweeted_of_me': {
'url': '/statuses/retweets_of_me.json',
'method': 'GET',
},
# Tweets
'get_retweets': {
'url': '/statuses/retweets/{{id}}.json',
'method': 'GET',
},
'show_status': {
'url': '/statuses/show/{{id}}.json',
'method': 'GET',
},
'destroy_status': {
'url': '/statuses/destroy/{{id}}.json',
'method': 'POST',
},
'update_status': {
'url': '/statuses/update.json',
'method': 'POST',
},
'retweet': {
'url': '/statuses/retweet/{{id}}.json',
'method': 'POST',
},
'update_status_with_media': {
'url': '/statuses/update_with_media.json',
'method': 'POST',
},
'get_oembed_tweet': {
'url': '/statuses/oembed.json',
'method': 'GET',
},
'get_retweeters_ids': {
'url': '/statuses/retweeters/ids.json',
'method': 'GET',
},
# Search
'search': {
'url': '/search/tweets.json',
'method': 'GET',
},
# Direct Messages
'get_direct_messages': {
'url': '/direct_messages.json',
'method': 'GET',
},
'get_sent_messages': {
'url': '/direct_messages/sent.json',
'method': 'GET',
},
'get_direct_message': {
'url': '/direct_messages/show.json',
'method': 'GET',
},
'destroy_direct_message': {
'url': '/direct_messages/destroy.json',
'method': 'POST',
},
'send_direct_message': {
'url': '/direct_messages/new.json',
'method': 'POST',
},
# Friends & Followers
'get_user_ids_of_blocked_retweets': {
'url': '/friendships/no_retweets/ids.json',
'method': 'GET',
},
'get_friends_ids': {
'url': '/friends/ids.json',
'method': 'GET',
},
'get_followers_ids': {
'url': '/followers/ids.json',
'method': 'GET',
},
'lookup_friendships': {
'url': '/friendships/lookup.json',
'method': 'GET',
},
'get_incoming_friendship_ids': {
'url': '/friendships/incoming.json',
'method': 'GET',
},
'get_outgoing_friendship_ids': {
'url': '/friendships/outgoing.json',
'method': 'GET',
},
'create_friendship': {
'url': '/friendships/create.json',
'method': 'POST',
},
'destroy_friendship': {
'url': '/friendships/destroy.json',
'method': 'POST',
},
'update_friendship': {
'url': '/friendships/update.json',
'method': 'POST',
},
'show_friendship': {
'url': '/friendships/show.json',
'method': 'GET',
},
'get_friends_list': {
'url': '/friends/list.json',
'method': 'GET',
},
'get_followers_list': {
'url': '/followers/list.json',
'method': 'GET',
},
# Users
'get_account_settings': {
'url': '/account/settings.json',
'method': 'GET',
},
'verify_credentials': {
'url': '/account/verify_credentials.json',
'method': 'GET',
},
'update_account_settings': {
'url': '/account/settings.json',
'method': 'POST',
},
'update_delivery_service': {
'url': '/account/update_delivery_device.json',
'method': 'POST',
},
'update_profile': {
'url': '/account/update_profile.json',
'method': 'POST',
},
'update_profile_background_image': {
'url': '/account/update_profile_banner.json',
'method': 'POST',
},
'update_profile_colors': {
'url': '/account/update_profile_colors.json',
'method': 'POST',
},
'update_profile_image': {
'url': '/account/update_profile_image.json',
'method': 'POST',
},
'list_blocks': {
'url': '/blocks/list.json',
'method': 'GET',
},
'list_block_ids': {
'url': '/blocks/ids.json',
'method': 'GET',
},
'create_block': {
'url': '/blocks/create.json',
'method': 'POST',
},
'destroy_block': {
'url': '/blocks/destroy.json',
'method': 'POST',
},
'lookup_user': {
'url': '/users/lookup.json',
'method': 'GET',
},
'show_user': {
'url': '/users/show.json',
'method': 'GET',
},
'search_users': {
'url': '/users/search.json',
'method': 'GET',
},
'get_contributees': {
'url': '/users/contributees.json',
'method': 'GET',
},
'get_contributors': {
'url': '/users/contributors.json',
'method': 'GET',
},
'remove_profile_banner': {
'url': '/account/remove_profile_banner.json',
'method': 'POST',
},
'update_profile_background_image': {
'url': '/account/update_profile_background_image.json',
'method': 'POST',
},
'get_profile_banner_sizes': {
'url': '/users/profile_banner.json',
'method': 'GET',
},
# Suggested Users
'get_user_suggestions_by_slug': {
'url': '/users/suggestions/{{slug}}.json',
'method': 'GET',
},
'get_user_suggestions': {
'url': '/users/suggestions.json',
'method': 'GET',
},
'get_user_suggestions_statuses_by_slug': {
'url': '/users/suggestions/{{slug}}/members.json',
'method': 'GET',
},
# Favorites
'get_favorites': {
'url': '/favorites/list.json',
'method': 'GET',
},
'destroy_favorite': {
'url': '/favorites/destroy.json',
'method': 'POST',
},
'create_favorite': {
'url': '/favorites/create.json',
'method': 'POST',
},
# Lists
'show_lists': {
'url': '/lists/list.json',
'method': 'GET',
},
'get_list_statuses': {
'url': '/lists/statuses.json',
'method': 'GET'
},
'delete_list_member': {
'url': '/lists/members/destroy.json',
'method': 'POST',
},
'get_list_memberships': {
'url': '/lists/memberships.json',
'method': 'GET',
},
'get_list_subscribers': {
'url': '/lists/subscribers.json',
'method': 'GET',
},
'subscribe_to_list': {
'url': '/lists/subscribers/create.json',
'method': 'POST',
},
'is_list_subscriber': {
'url': '/lists/subscribers/show.json',
'method': 'GET',
},
'unsubscribe_from_list': {
'url': '/lists/subscribers/destroy.json',
'method': 'POST',
},
'create_list_members': {
'url': '/lists/members/create_all.json',
'method': 'POST'
},
'is_list_member': {
'url': '/lists/members/show.json',
'method': 'GET',
},
'get_list_members': {
'url': '/lists/members.json',
'method': 'GET',
},
'add_list_member': {
'url': '/lists/members/create.json',
'method': 'POST',
},
'delete_list': {
'url': '/lists/destroy.json',
'method': 'POST',
},
'update_list': {
'url': '/lists/update.json',
'method': 'POST',
},
'create_list': {
'url': '/lists/create.json',
'method': 'POST',
},
'get_specific_list': {
'url': '/lists/show.json',
'method': 'GET',
},
'get_list_subscriptions': {
'url': '/lists/subscriptions.json',
'method': 'GET',
},
'delete_list_members': {
'url': '/lists/members/destroy_all.json',
'method': 'POST'
},
'show_owned_lists': {
'url': '/lists/ownerships.json',
'method': 'GET'
},
# Saved Searches
'get_saved_searches': {
'url': '/saved_searches/list.json',
'method': 'GET',
},
'show_saved_search': {
'url': '/saved_searches/show/{{id}}.json',
'method': 'GET',
},
'create_saved_search': {
'url': '/saved_searches/create.json',
'method': 'POST',
},
'destroy_saved_search': {
'url': '/saved_searches/destroy/{{id}}.json',
'method': 'POST',
},
# Places & Geo
'get_geo_info': {
'url': '/geo/id/{{place_id}}.json',
'method': 'GET',
},
'reverse_geocode': {
'url': '/geo/reverse_geocode.json',
'method': 'GET',
},
'search_geo': {
'url': '/geo/search.json',
'method': 'GET',
},
'get_similar_places': {
'url': '/geo/similar_places.json',
'method': 'GET',
},
'create_place': {
'url': '/geo/place.json',
'method': 'POST',
},
# Trends
'get_place_trends': {
'url': '/trends/place.json',
'method': 'GET',
},
'get_available_trends': {
'url': '/trends/available.json',
'method': 'GET',
},
'get_closest_trends': {
'url': '/trends/closest.json',
'method': 'GET',
},
# Spam Reporting
'report_spam': {
'url': '/users/report_spam.json',
'method': 'POST',
},
}
# from https://dev.twitter.com/docs/error-codes-responses
twitter_http_status_codes = {
200: ('OK', 'Success!'),
304: ('Not Modified', 'There was no new data to return.'),
400: ('Bad Request', 'The request was invalid. An accompanying error message will explain why. This is the status code will be returned during rate limiting.'),
401: ('Unauthorized', 'Authentication credentials were missing or incorrect.'),
403: ('Forbidden', 'The request is understood, but it has been refused. An accompanying error message will explain why. This code is used when requests are being denied due to update limits.'),
404: ('Not Found', 'The URI requested is invalid or the resource requested, such as a user, does not exists.'),
406: ('Not Acceptable', 'Returned by the Search API when an invalid format is specified in the request.'),
410: ('Gone', 'This resource is gone. Used to indicate that an API endpoint has been turned off.'),
422: ('Unprocessable Entity', 'Returned when an image uploaded to POST account/update_profile_banner is unable to be processed.'),
429: ('Too Many Requests', 'Returned in API v1.1 when a request cannot be served due to the application\'s rate limit having been exhausted for the resource.'),
500: ('Internal Server Error', 'Something is broken. Please post to the group so the Twitter team can investigate.'),
502: ('Bad Gateway', 'Twitter is down or being upgraded.'),
503: ('Service Unavailable', 'The Twitter servers are up, but overloaded with requests. Try again later.'),
504: ('Gateway Timeout', 'The Twitter servers are up, but the request couldn\'t be serviced due to some failure within our stack. Try again later.'),
}