twitter 8.2.0 → 8.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.md +1 -1
- data/README.md +172 -10
- data/lib/twitter/arguments.rb +14 -1
- data/lib/twitter/base.rb +72 -11
- data/lib/twitter/basic_user.rb +7 -1
- data/lib/twitter/client.rb +94 -3
- data/lib/twitter/creatable.rb +11 -2
- data/lib/twitter/cursor.rb +58 -11
- data/lib/twitter/direct_message.rb +32 -4
- data/lib/twitter/direct_message_event.rb +34 -10
- data/lib/twitter/direct_messages/welcome_message.rb +22 -1
- data/lib/twitter/direct_messages/welcome_message_rule.rb +7 -0
- data/lib/twitter/direct_messages/welcome_message_rule_wrapper.rb +26 -3
- data/lib/twitter/direct_messages/welcome_message_wrapper.rb +36 -11
- data/lib/twitter/entities.rb +84 -8
- data/lib/twitter/entity/hashtag.rb +7 -1
- data/lib/twitter/entity/symbol.rb +7 -1
- data/lib/twitter/entity/uri.rb +2 -1
- data/lib/twitter/entity/user_mention.rb +20 -1
- data/lib/twitter/entity.rb +7 -1
- data/lib/twitter/enumerable.rb +20 -3
- data/lib/twitter/error.rb +137 -61
- data/lib/twitter/factory.rb +9 -5
- data/lib/twitter/geo/point.rb +37 -5
- data/lib/twitter/geo/polygon.rb +1 -0
- data/lib/twitter/geo.rb +16 -2
- data/lib/twitter/geo_factory.rb +7 -3
- data/lib/twitter/geo_results.rb +39 -8
- data/lib/twitter/headers.rb +44 -7
- data/lib/twitter/identity.rb +13 -3
- data/lib/twitter/language.rb +21 -1
- data/lib/twitter/list.rb +101 -11
- data/lib/twitter/media/animated_gif.rb +1 -0
- data/lib/twitter/media/photo.rb +19 -3
- data/lib/twitter/media/video.rb +21 -3
- data/lib/twitter/media/video_info.rb +15 -1
- data/lib/twitter/media_factory.rb +7 -3
- data/lib/twitter/metadata.rb +14 -1
- data/lib/twitter/null_object.rb +16 -14
- data/lib/twitter/oembed.rb +56 -2
- data/lib/twitter/place.rb +74 -6
- data/lib/twitter/premium_search_results.rb +87 -18
- data/lib/twitter/profile.rb +100 -44
- data/lib/twitter/profile_banner.rb +9 -4
- data/lib/twitter/rate_limit.rb +32 -3
- data/lib/twitter/relationship.rb +8 -5
- data/lib/twitter/rest/account_activity.rb +55 -26
- data/lib/twitter/rest/api.rb +2 -0
- data/lib/twitter/rest/client.rb +18 -0
- data/lib/twitter/rest/direct_messages/welcome_messages.rb +89 -18
- data/lib/twitter/rest/direct_messages.rb +160 -96
- data/lib/twitter/rest/favorites.rb +58 -22
- data/lib/twitter/rest/form_encoder.rb +57 -17
- data/lib/twitter/rest/friends_and_followers.rb +101 -35
- data/lib/twitter/rest/help.rb +13 -3
- data/lib/twitter/rest/lists.rb +136 -47
- data/lib/twitter/rest/oauth.rb +21 -15
- data/lib/twitter/rest/places_and_geo.rb +44 -28
- data/lib/twitter/rest/premium_search.rb +17 -12
- data/lib/twitter/rest/request.rb +173 -55
- data/lib/twitter/rest/saved_searches.rb +22 -7
- data/lib/twitter/rest/search.rb +20 -16
- data/lib/twitter/rest/spam_reporting.rb +5 -1
- data/lib/twitter/rest/suggested_users.rb +15 -6
- data/lib/twitter/rest/timelines.rb +92 -52
- data/lib/twitter/rest/trends.rb +32 -13
- data/lib/twitter/rest/tweets.rb +147 -89
- data/lib/twitter/rest/undocumented.rb +10 -1
- data/lib/twitter/rest/upload_utils.rb +45 -29
- data/lib/twitter/rest/users.rb +151 -72
- data/lib/twitter/rest/utils.rb +135 -39
- data/lib/twitter/saved_search.rb +23 -2
- data/lib/twitter/search_results.rb +66 -18
- data/lib/twitter/settings.rb +37 -11
- data/lib/twitter/size.rb +37 -3
- data/lib/twitter/source_user.rb +4 -3
- data/lib/twitter/streaming/client.rb +61 -9
- data/lib/twitter/streaming/connection.rb +54 -6
- data/lib/twitter/streaming/deleted_tweet.rb +8 -0
- data/lib/twitter/streaming/event.rb +43 -1
- data/lib/twitter/streaming/friend_list.rb +1 -0
- data/lib/twitter/streaming/message_parser.rb +20 -10
- data/lib/twitter/streaming/response.rb +31 -5
- data/lib/twitter/streaming/stall_warning.rb +23 -0
- data/lib/twitter/suggestion.rb +25 -1
- data/lib/twitter/target_user.rb +2 -1
- data/lib/twitter/trend.rb +29 -1
- data/lib/twitter/trend_results.rb +50 -7
- data/lib/twitter/tweet.rb +180 -21
- data/lib/twitter/user.rb +289 -53
- data/lib/twitter/utils.rb +12 -13
- data/lib/twitter/variant.rb +12 -1
- data/lib/twitter/version.rb +66 -29
- data/lib/twitter.rb +6 -1
- metadata +23 -57
- data/.yardopts +0 -16
- data/CHANGELOG.md +0 -1040
- data/CONTRIBUTING.md +0 -49
- data/twitter.gemspec +0 -40
data/lib/twitter/rest/lists.rb
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
require "addressable/uri"
|
|
2
1
|
require "twitter/arguments"
|
|
3
2
|
require "twitter/cursor"
|
|
4
3
|
require "twitter/error"
|
|
@@ -12,17 +11,23 @@ require "uri"
|
|
|
12
11
|
|
|
13
12
|
module Twitter
|
|
14
13
|
module REST
|
|
14
|
+
# Methods for working with Twitter lists
|
|
15
15
|
module Lists
|
|
16
16
|
include Twitter::REST::Utils
|
|
17
17
|
include Twitter::Utils
|
|
18
|
+
|
|
19
|
+
# Maximum users per request
|
|
18
20
|
MAX_USERS_PER_REQUEST = 100
|
|
19
21
|
|
|
20
|
-
# Returns all lists the
|
|
22
|
+
# Returns all lists the user subscribes to, including their own
|
|
21
23
|
#
|
|
24
|
+
# @api public
|
|
22
25
|
# @see https://dev.twitter.com/rest/reference/get/lists/list
|
|
23
26
|
# @rate_limited Yes
|
|
24
27
|
# @authentication Requires user context
|
|
25
28
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
29
|
+
# @example
|
|
30
|
+
# client.lists
|
|
26
31
|
# @return [Array<Twitter::List>]
|
|
27
32
|
# @overload lists(options = {})
|
|
28
33
|
# @param options [Hash] A customizable set of options.
|
|
@@ -32,17 +37,23 @@ module Twitter
|
|
|
32
37
|
# @param options [Hash] A customizable set of options.
|
|
33
38
|
# @option options [Boolean] :reverse Set this to true if you would like owned lists to be returned first.
|
|
34
39
|
def lists(*args)
|
|
35
|
-
objects_from_response_with_user(
|
|
40
|
+
objects_from_response_with_user(List, :get, "/1.1/lists/list.json", args)
|
|
36
41
|
end
|
|
37
|
-
|
|
42
|
+
# @!method lists_subscribed_to
|
|
43
|
+
# @api public
|
|
44
|
+
# @see #lists
|
|
45
|
+
alias_method :lists_subscribed_to, :lists
|
|
38
46
|
|
|
39
|
-
#
|
|
47
|
+
# Shows tweet timeline for members of the specified list
|
|
40
48
|
#
|
|
49
|
+
# @api public
|
|
41
50
|
# @see https://dev.twitter.com/rest/reference/get/lists/statuses
|
|
42
51
|
# @rate_limited Yes
|
|
43
52
|
# @authentication Requires user context
|
|
44
53
|
# @raise [Twitter::Error::NotFound] Error raised when supplied list is not found.
|
|
45
54
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
55
|
+
# @example
|
|
56
|
+
# client.list_timeline('twitter-engineering')
|
|
46
57
|
# @return [Array<Twitter::Tweet>]
|
|
47
58
|
# @overload list_timeline(list, options = {})
|
|
48
59
|
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
|
@@ -58,19 +69,22 @@ module Twitter
|
|
|
58
69
|
# @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
|
|
59
70
|
# @option options [Integer] :count The number of results to retrieve.
|
|
60
71
|
def list_timeline(*args)
|
|
61
|
-
arguments =
|
|
72
|
+
arguments = Arguments.new(args)
|
|
62
73
|
merge_list!(arguments.options, arguments.pop)
|
|
63
74
|
merge_owner!(arguments.options, arguments.pop)
|
|
64
|
-
perform_get_with_objects("/1.1/lists/statuses.json", arguments.options,
|
|
75
|
+
perform_get_with_objects("/1.1/lists/statuses.json", arguments.options, Tweet)
|
|
65
76
|
end
|
|
66
77
|
|
|
67
78
|
# Removes the specified member from the list
|
|
68
79
|
#
|
|
80
|
+
# @api public
|
|
69
81
|
# @see https://dev.twitter.com/rest/reference/post/lists/members/destroy
|
|
70
82
|
# @rate_limited No
|
|
71
83
|
# @authentication Requires user context
|
|
72
84
|
# @raise [Twitter::Error::NotFound] Error raised when supplied list is not found.
|
|
73
85
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
86
|
+
# @example
|
|
87
|
+
# client.remove_list_member('twitter-engineering', 'sferik')
|
|
74
88
|
# @return [Twitter::List] The list.
|
|
75
89
|
# @overload remove_list_member(list, user_to_remove, options = {})
|
|
76
90
|
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
|
@@ -85,12 +99,15 @@ module Twitter
|
|
|
85
99
|
list_from_response_with_user("/1.1/lists/members/destroy.json", args)
|
|
86
100
|
end
|
|
87
101
|
|
|
88
|
-
#
|
|
102
|
+
# Lists the lists the specified user has been added to
|
|
89
103
|
#
|
|
104
|
+
# @api public
|
|
90
105
|
# @see https://dev.twitter.com/rest/reference/get/lists/memberships
|
|
91
106
|
# @rate_limited Yes
|
|
92
107
|
# @authentication Requires user context
|
|
93
108
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
109
|
+
# @example
|
|
110
|
+
# client.memberships
|
|
94
111
|
# @return [Twitter::Cursor]
|
|
95
112
|
# @overload memberships(options = {})
|
|
96
113
|
# @param options [Hash] A customizable set of options.
|
|
@@ -102,16 +119,19 @@ module Twitter
|
|
|
102
119
|
# @option options [Integer] :count The amount of results to return per page. Defaults to 20. No more than 1000 results will ever be returned in a single page.
|
|
103
120
|
# @option options [Boolean, String, Integer] :filter_to_owned_lists When set to true, t or 1, will return just lists the authenticating user owns, and the user represented by user_id or screen_name is a member of.
|
|
104
121
|
def memberships(*args)
|
|
105
|
-
cursor_from_response_with_user(:lists,
|
|
122
|
+
cursor_from_response_with_user(:lists, List, "/1.1/lists/memberships.json", args)
|
|
106
123
|
end
|
|
107
124
|
|
|
108
125
|
# Returns the subscribers of the specified list
|
|
109
126
|
#
|
|
127
|
+
# @api public
|
|
110
128
|
# @see https://dev.twitter.com/rest/reference/get/lists/subscribers
|
|
111
129
|
# @rate_limited Yes
|
|
112
130
|
# @authentication Requires user context
|
|
113
131
|
# @raise [Twitter::Error::NotFound] Error raised when supplied list is not found.
|
|
114
132
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
133
|
+
# @example
|
|
134
|
+
# client.list_subscribers('twitter-engineering')
|
|
115
135
|
# @return [Twitter::Cursor] The subscribers of the specified list.
|
|
116
136
|
# @overload list_subscribers(list, options = {})
|
|
117
137
|
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
|
@@ -124,13 +144,16 @@ module Twitter
|
|
|
124
144
|
cursor_from_response_with_list("/1.1/lists/subscribers.json", args)
|
|
125
145
|
end
|
|
126
146
|
|
|
127
|
-
#
|
|
147
|
+
# Makes the authenticated user follow the specified list
|
|
128
148
|
#
|
|
149
|
+
# @api public
|
|
129
150
|
# @see https://dev.twitter.com/rest/reference/post/lists/subscribers/create
|
|
130
151
|
# @rate_limited No
|
|
131
152
|
# @authentication Requires user context
|
|
132
153
|
# @raise [Twitter::Error::NotFound] Error raised when supplied list is not found.
|
|
133
154
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
155
|
+
# @example
|
|
156
|
+
# client.list_subscribe('twitter-engineering')
|
|
134
157
|
# @return [Twitter::List] The specified list.
|
|
135
158
|
# @overload list_subscribe(list, options = {})
|
|
136
159
|
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
|
@@ -143,13 +166,16 @@ module Twitter
|
|
|
143
166
|
list_from_response(:post, "/1.1/lists/subscribers/create.json", args)
|
|
144
167
|
end
|
|
145
168
|
|
|
146
|
-
#
|
|
169
|
+
# Checks if a user is a subscriber of the specified list
|
|
147
170
|
#
|
|
171
|
+
# @api public
|
|
148
172
|
# @see https://dev.twitter.com/rest/reference/get/lists/subscribers/show
|
|
149
173
|
# @rate_limited Yes
|
|
150
174
|
# @authentication Requires user context
|
|
151
175
|
# @raise [Twitter::Error::NotFound] Error raised when supplied list is not found.
|
|
152
176
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
177
|
+
# @example
|
|
178
|
+
# client.list_subscriber?('twitter-engineering', 'sferik')
|
|
153
179
|
# @return [Boolean] true if user is a subscriber of the specified list, otherwise false.
|
|
154
180
|
# @overload list_subscriber?(list, user_to_check, options = {})
|
|
155
181
|
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
|
@@ -165,13 +191,16 @@ module Twitter
|
|
|
165
191
|
list_user?(:get, "/1.1/lists/subscribers/show.json", args)
|
|
166
192
|
end
|
|
167
193
|
|
|
168
|
-
# Unsubscribes the authenticated user
|
|
194
|
+
# Unsubscribes the authenticated user from the specified list
|
|
169
195
|
#
|
|
196
|
+
# @api public
|
|
170
197
|
# @see https://dev.twitter.com/rest/reference/post/lists/subscribers/destroy
|
|
171
198
|
# @rate_limited No
|
|
172
199
|
# @authentication Requires user context
|
|
173
200
|
# @raise [Twitter::Error::NotFound] Error raised when supplied list is not found.
|
|
174
201
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
202
|
+
# @example
|
|
203
|
+
# client.list_unsubscribe('twitter-engineering')
|
|
175
204
|
# @return [Twitter::List] The specified list.
|
|
176
205
|
# @overload list_unsubscribe(list, options = {})
|
|
177
206
|
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
|
@@ -186,13 +215,16 @@ module Twitter
|
|
|
186
215
|
|
|
187
216
|
# Adds specified members to a list
|
|
188
217
|
#
|
|
218
|
+
# @api public
|
|
189
219
|
# @see https://dev.twitter.com/rest/reference/post/lists/members/create_all
|
|
190
|
-
# @note Lists are limited to having 5,000 members
|
|
220
|
+
# @note Lists are limited to having 5,000 members.
|
|
191
221
|
# @rate_limited No
|
|
192
222
|
# @authentication Requires user context
|
|
193
223
|
# @raise [Twitter::Error::Forbidden] Error raised when user has already been added.
|
|
194
224
|
# @raise [Twitter::Error::NotFound] Error raised when supplied list is not found.
|
|
195
225
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
226
|
+
# @example
|
|
227
|
+
# client.add_list_members('twitter-engineering', ['sferik', 'pengwynn'])
|
|
196
228
|
# @return [Twitter::List] The list.
|
|
197
229
|
# @overload add_list_members(list, users, options = {})
|
|
198
230
|
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
|
@@ -207,13 +239,16 @@ module Twitter
|
|
|
207
239
|
list_from_response_with_users("/1.1/lists/members/create_all.json", args)
|
|
208
240
|
end
|
|
209
241
|
|
|
210
|
-
#
|
|
242
|
+
# Checks if a user is a member of the specified list
|
|
211
243
|
#
|
|
244
|
+
# @api public
|
|
212
245
|
# @see https://dev.twitter.com/rest/reference/get/lists/members/show
|
|
213
246
|
# @authentication Requires user context
|
|
214
247
|
# @rate_limited Yes
|
|
215
248
|
# @raise [Twitter::Error::NotFound] Error raised when supplied list is not found.
|
|
216
249
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
250
|
+
# @example
|
|
251
|
+
# client.list_member?('twitter-engineering', 'sferik')
|
|
217
252
|
# @return [Boolean] true if user is a member of the specified list, otherwise false.
|
|
218
253
|
# @overload list_member?(list, user_to_check, options = {})
|
|
219
254
|
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
|
@@ -230,11 +265,14 @@ module Twitter
|
|
|
230
265
|
|
|
231
266
|
# Returns the members of the specified list
|
|
232
267
|
#
|
|
268
|
+
# @api public
|
|
233
269
|
# @see https://dev.twitter.com/rest/reference/get/lists/members
|
|
234
270
|
# @rate_limited Yes
|
|
235
271
|
# @authentication Requires user context
|
|
236
272
|
# @raise [Twitter::Error::NotFound] Error raised when supplied list is not found.
|
|
237
273
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
274
|
+
# @example
|
|
275
|
+
# client.list_members('twitter-engineering')
|
|
238
276
|
# @return [Twitter::Cursor]
|
|
239
277
|
# @overload list_members(list, options = {})
|
|
240
278
|
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
|
@@ -247,14 +285,17 @@ module Twitter
|
|
|
247
285
|
cursor_from_response_with_list("/1.1/lists/members.json", args)
|
|
248
286
|
end
|
|
249
287
|
|
|
250
|
-
#
|
|
288
|
+
# Adds a member to a list
|
|
251
289
|
#
|
|
290
|
+
# @api public
|
|
252
291
|
# @see https://dev.twitter.com/rest/reference/post/lists/members/create
|
|
253
292
|
# @note Lists are limited to having 5,000 members.
|
|
254
293
|
# @rate_limited No
|
|
255
294
|
# @authentication Requires user context
|
|
256
295
|
# @raise [Twitter::Error::NotFound] Error raised when supplied list is not found.
|
|
257
296
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
297
|
+
# @example
|
|
298
|
+
# client.add_list_member('twitter-engineering', 'sferik')
|
|
258
299
|
# @return [Twitter::List] The list.
|
|
259
300
|
# @overload add_list_member(list, user_to_add, options = {})
|
|
260
301
|
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
|
@@ -271,12 +312,15 @@ module Twitter
|
|
|
271
312
|
|
|
272
313
|
# Deletes the specified list
|
|
273
314
|
#
|
|
315
|
+
# @api public
|
|
274
316
|
# @see https://dev.twitter.com/rest/reference/post/lists/destroy
|
|
275
317
|
# @note Must be owned by the authenticated user.
|
|
276
318
|
# @rate_limited No
|
|
277
319
|
# @authentication Requires user context
|
|
278
320
|
# @raise [Twitter::Error::NotFound] Error raised when supplied list is not found.
|
|
279
321
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
322
|
+
# @example
|
|
323
|
+
# client.destroy_list('twitter-engineering')
|
|
280
324
|
# @return [Twitter::List] The deleted list.
|
|
281
325
|
# @overload destroy_list(list, options = {})
|
|
282
326
|
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
|
@@ -291,11 +335,14 @@ module Twitter
|
|
|
291
335
|
|
|
292
336
|
# Updates the specified list
|
|
293
337
|
#
|
|
338
|
+
# @api public
|
|
294
339
|
# @see https://dev.twitter.com/rest/reference/post/lists/update
|
|
295
340
|
# @rate_limited No
|
|
296
341
|
# @authentication Requires user context
|
|
297
342
|
# @raise [Twitter::Error::NotFound] Error raised when supplied list is not found.
|
|
298
343
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
344
|
+
# @example
|
|
345
|
+
# client.list_update('twitter-engineering', description: 'Tweeps')
|
|
299
346
|
# @return [Twitter::List] The created list.
|
|
300
347
|
# @overload list_update(list, options = {})
|
|
301
348
|
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
|
@@ -314,28 +361,34 @@ module Twitter
|
|
|
314
361
|
|
|
315
362
|
# Creates a new list for the authenticated user
|
|
316
363
|
#
|
|
364
|
+
# @api public
|
|
317
365
|
# @see https://dev.twitter.com/rest/reference/post/lists/create
|
|
318
366
|
# @note Accounts are limited to 20 lists.
|
|
319
367
|
# @rate_limited No
|
|
320
368
|
# @authentication Requires user context
|
|
321
369
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
370
|
+
# @example
|
|
371
|
+
# client.create_list('twitter-engineering')
|
|
322
372
|
# @return [Twitter::List] The created list.
|
|
323
373
|
# @param name [String] The name for the list.
|
|
324
374
|
# @param options [Hash] A customizable set of options.
|
|
325
375
|
# @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
|
|
326
376
|
# @option options [String] :description The description to give the list.
|
|
327
377
|
def create_list(name, options = {})
|
|
328
|
-
perform_post_with_object("/1.1/lists/create.json", options.merge(name:),
|
|
378
|
+
perform_post_with_object("/1.1/lists/create.json", options.merge(name:), List)
|
|
329
379
|
end
|
|
330
380
|
|
|
331
|
-
#
|
|
381
|
+
# Shows the specified list
|
|
332
382
|
#
|
|
383
|
+
# @api public
|
|
333
384
|
# @see https://dev.twitter.com/rest/reference/get/lists/show
|
|
334
|
-
# @note Private lists
|
|
385
|
+
# @note Private lists are only shown if the authenticated user owns them.
|
|
335
386
|
# @rate_limited Yes
|
|
336
387
|
# @authentication Requires user context
|
|
337
388
|
# @raise [Twitter::Error::NotFound] Error raised when supplied list is not found.
|
|
338
389
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
390
|
+
# @example
|
|
391
|
+
# client.list('twitter-engineering')
|
|
339
392
|
# @return [Twitter::List] The specified list.
|
|
340
393
|
# @overload list(list, options = {})
|
|
341
394
|
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
|
@@ -348,12 +401,15 @@ module Twitter
|
|
|
348
401
|
list_from_response(:get, "/1.1/lists/show.json", args)
|
|
349
402
|
end
|
|
350
403
|
|
|
351
|
-
#
|
|
404
|
+
# Lists the lists the specified user follows
|
|
352
405
|
#
|
|
406
|
+
# @api public
|
|
353
407
|
# @see https://dev.twitter.com/rest/reference/get/lists/subscriptions
|
|
354
408
|
# @rate_limited Yes
|
|
355
409
|
# @authentication Requires user context
|
|
356
410
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
411
|
+
# @example
|
|
412
|
+
# client.subscriptions
|
|
357
413
|
# @return [Twitter::Cursor]
|
|
358
414
|
# @overload subscriptions(options = {})
|
|
359
415
|
# @param options [Hash] A customizable set of options.
|
|
@@ -361,16 +417,19 @@ module Twitter
|
|
|
361
417
|
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
|
362
418
|
# @param options [Hash] A customizable set of options.
|
|
363
419
|
def subscriptions(*args)
|
|
364
|
-
cursor_from_response_with_user(:lists,
|
|
420
|
+
cursor_from_response_with_user(:lists, List, "/1.1/lists/subscriptions.json", args)
|
|
365
421
|
end
|
|
366
422
|
|
|
367
423
|
# Removes specified members from the list
|
|
368
424
|
#
|
|
425
|
+
# @api public
|
|
369
426
|
# @see https://dev.twitter.com/rest/reference/post/lists/members/destroy_all
|
|
370
427
|
# @rate_limited No
|
|
371
428
|
# @authentication Requires user context
|
|
372
429
|
# @raise [Twitter::Error::NotFound] Error raised when supplied list is not found.
|
|
373
430
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
431
|
+
# @example
|
|
432
|
+
# client.remove_list_members('twitter-engineering', ['sferik'])
|
|
374
433
|
# @return [Twitter::List] The list.
|
|
375
434
|
# @overload remove_list_members(list, users, options = {})
|
|
376
435
|
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
|
@@ -387,10 +446,13 @@ module Twitter
|
|
|
387
446
|
|
|
388
447
|
# Returns the lists owned by the specified Twitter user
|
|
389
448
|
#
|
|
449
|
+
# @api public
|
|
390
450
|
# @see https://dev.twitter.com/rest/reference/get/lists/ownerships
|
|
391
451
|
# @rate_limited Yes
|
|
392
452
|
# @authentication Requires user context
|
|
393
453
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
454
|
+
# @example
|
|
455
|
+
# client.owned_lists
|
|
394
456
|
# @return [Array<Twitter::List>]
|
|
395
457
|
# @overload owned_lists(options = {})
|
|
396
458
|
# @param options [Hash] A customizable set of options.
|
|
@@ -400,78 +462,105 @@ module Twitter
|
|
|
400
462
|
# @param options [Hash] A customizable set of options.
|
|
401
463
|
# @option options [Integer] :count The amount of results to return per page. Defaults to 20. No more than 1000 results will ever be returned in a single page.
|
|
402
464
|
def owned_lists(*args)
|
|
403
|
-
cursor_from_response_with_user(:lists,
|
|
465
|
+
cursor_from_response_with_user(:lists, List, "/1.1/lists/ownerships.json", args)
|
|
404
466
|
end
|
|
405
467
|
|
|
406
|
-
|
|
468
|
+
private
|
|
407
469
|
|
|
408
|
-
#
|
|
409
|
-
#
|
|
410
|
-
# @
|
|
411
|
-
# @return [
|
|
470
|
+
# Retrieves a list from the response
|
|
471
|
+
#
|
|
472
|
+
# @api private
|
|
473
|
+
# @return [Twitter::List]
|
|
412
474
|
def list_from_response(request_method, path, args)
|
|
413
|
-
arguments =
|
|
475
|
+
arguments = Arguments.new(args)
|
|
414
476
|
merge_list!(arguments.options, arguments.pop)
|
|
415
477
|
merge_owner!(arguments.options, arguments.pop)
|
|
416
|
-
perform_request_with_object(request_method, path, arguments.options,
|
|
478
|
+
perform_request_with_object(request_method, path, arguments.options, List)
|
|
417
479
|
end
|
|
418
480
|
|
|
481
|
+
# Retrieves a cursor from the response with list
|
|
482
|
+
#
|
|
483
|
+
# @api private
|
|
484
|
+
# @return [Twitter::Cursor]
|
|
419
485
|
def cursor_from_response_with_list(path, args)
|
|
420
|
-
arguments =
|
|
486
|
+
arguments = Arguments.new(args)
|
|
421
487
|
merge_list!(arguments.options, arguments.pop)
|
|
422
488
|
merge_owner!(arguments.options, arguments.pop)
|
|
423
|
-
perform_get_with_cursor(path, arguments.options, :users,
|
|
489
|
+
perform_get_with_cursor(path, arguments.options, :users, User)
|
|
424
490
|
end
|
|
425
491
|
|
|
492
|
+
# Checks if user is a member of a list
|
|
493
|
+
#
|
|
494
|
+
# @api private
|
|
495
|
+
# @return [Boolean]
|
|
426
496
|
def list_user?(request_method, path, args)
|
|
427
|
-
arguments =
|
|
497
|
+
arguments = Arguments.new(args)
|
|
428
498
|
merge_user!(arguments.options, arguments.pop)
|
|
429
499
|
merge_list!(arguments.options, arguments.pop)
|
|
430
500
|
merge_owner!(arguments.options, arguments.pop)
|
|
431
|
-
perform_request(request_method
|
|
501
|
+
perform_request(request_method, path, arguments.options)
|
|
432
502
|
true
|
|
433
|
-
rescue
|
|
503
|
+
rescue Error::Forbidden, Error::NotFound
|
|
434
504
|
false
|
|
435
505
|
end
|
|
436
506
|
|
|
507
|
+
# Retrieves a list from response with user
|
|
508
|
+
#
|
|
509
|
+
# @api private
|
|
510
|
+
# @return [Twitter::List]
|
|
437
511
|
def list_from_response_with_user(path, args)
|
|
438
|
-
arguments =
|
|
512
|
+
arguments = Arguments.new(args)
|
|
439
513
|
merge_user!(arguments.options, arguments.pop)
|
|
440
514
|
merge_list!(arguments.options, arguments.pop)
|
|
441
515
|
merge_owner!(arguments.options, arguments.pop)
|
|
442
|
-
perform_post_with_object(path, arguments.options,
|
|
516
|
+
perform_post_with_object(path, arguments.options, List)
|
|
443
517
|
end
|
|
444
518
|
|
|
519
|
+
# Retrieves a list from response with users
|
|
520
|
+
#
|
|
521
|
+
# @api private
|
|
522
|
+
# @return [Twitter::List]
|
|
445
523
|
def list_from_response_with_users(path, args)
|
|
446
|
-
arguments = args
|
|
447
|
-
options = arguments.last.
|
|
524
|
+
arguments = args
|
|
525
|
+
options = arguments.last.instance_of?(Hash) ? arguments.pop : {} # : Hash[Symbol, untyped]
|
|
448
526
|
members = arguments.pop
|
|
449
527
|
merge_list!(options, arguments.pop)
|
|
450
528
|
merge_owner!(options, arguments.pop)
|
|
451
|
-
pmap(members.each_slice(MAX_USERS_PER_REQUEST)) do |users|
|
|
452
|
-
perform_post_with_object(path, merge_users(options, users),
|
|
453
|
-
end
|
|
529
|
+
*, result = pmap(members.each_slice(MAX_USERS_PER_REQUEST)) do |users|
|
|
530
|
+
perform_post_with_object(path, merge_users(options, users), List)
|
|
531
|
+
end
|
|
532
|
+
result
|
|
454
533
|
end
|
|
455
534
|
|
|
456
535
|
# Take a list and merge it into the hash with the correct key
|
|
457
536
|
#
|
|
537
|
+
# @api private
|
|
458
538
|
# @param hash [Hash]
|
|
459
539
|
# @param list [Integer, String, URI, Twitter::List] A Twitter list ID, slug, URI, or object.
|
|
540
|
+
# @return [void]
|
|
460
541
|
def merge_list!(hash, list)
|
|
461
542
|
case list
|
|
462
|
-
when Integer
|
|
463
|
-
when
|
|
464
|
-
when String
|
|
465
|
-
when URI
|
|
543
|
+
when Integer then hash[:list_id] = list
|
|
544
|
+
when List then merge_list_and_owner!(hash, list)
|
|
545
|
+
when String then merge_slug_and_owner!(hash, list)
|
|
546
|
+
when URI then merge_slug_and_owner!(hash, list.path) # steep:ignore NoMethod
|
|
466
547
|
end
|
|
467
548
|
end
|
|
468
549
|
|
|
550
|
+
# Merges slug and owner into hash
|
|
551
|
+
#
|
|
552
|
+
# @api private
|
|
553
|
+
# @return [void]
|
|
469
554
|
def merge_slug_and_owner!(hash, path)
|
|
470
555
|
list = path.split("/")
|
|
471
556
|
hash[:slug] = list.pop
|
|
472
557
|
hash[:owner_screen_name] = list.pop unless list.empty?
|
|
473
558
|
end
|
|
474
559
|
|
|
560
|
+
# Merges list and owner into hash
|
|
561
|
+
#
|
|
562
|
+
# @api private
|
|
563
|
+
# @return [void]
|
|
475
564
|
def merge_list_and_owner!(hash, list)
|
|
476
565
|
merge_list!(hash, list.id)
|
|
477
566
|
merge_owner!(hash, list.user)
|
|
@@ -479,11 +568,12 @@ module Twitter
|
|
|
479
568
|
|
|
480
569
|
# Take an owner and merge it into the hash with the correct key
|
|
481
570
|
#
|
|
571
|
+
# @api private
|
|
482
572
|
# @param hash [Hash]
|
|
483
573
|
# @param user[Integer, String, Twitter::User] A Twitter user ID, screen_name, or object.
|
|
484
|
-
# @return [
|
|
574
|
+
# @return [void]
|
|
485
575
|
def merge_owner!(hash, user)
|
|
486
|
-
return
|
|
576
|
+
return if hash.key?(:owner_id) || hash.key?(:owner_screen_name)
|
|
487
577
|
|
|
488
578
|
if user
|
|
489
579
|
merge_user!(hash, user, "owner")
|
|
@@ -491,7 +581,6 @@ module Twitter
|
|
|
491
581
|
else
|
|
492
582
|
hash[:owner_id] = user_id
|
|
493
583
|
end
|
|
494
|
-
hash
|
|
495
584
|
end
|
|
496
585
|
end
|
|
497
586
|
end
|
data/lib/twitter/rest/oauth.rb
CHANGED
|
@@ -3,61 +3,67 @@ require "twitter/rest/utils"
|
|
|
3
3
|
|
|
4
4
|
module Twitter
|
|
5
5
|
module REST
|
|
6
|
+
# Methods for OAuth authentication
|
|
6
7
|
module OAuth
|
|
7
8
|
include Twitter::REST::Utils
|
|
8
9
|
|
|
9
|
-
#
|
|
10
|
-
# on an application's own behalf, without a user context.
|
|
11
|
-
#
|
|
12
|
-
# Only one bearer token may exist outstanding for an application, and repeated requests to this method
|
|
13
|
-
# will yield the same already-existent token until it has been invalidated.
|
|
10
|
+
# Obtains an OAuth 2 Bearer Token for application-only auth
|
|
14
11
|
#
|
|
12
|
+
# @api public
|
|
15
13
|
# @see https://dev.twitter.com/rest/reference/post/oauth2/token
|
|
16
14
|
# @rate_limited No
|
|
17
15
|
# @authentication Required
|
|
18
16
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
17
|
+
# @example
|
|
18
|
+
# client.token
|
|
19
19
|
# @return [String] The Bearer token.
|
|
20
20
|
# @param options [Hash] A customizable set of options.
|
|
21
|
-
# @example Generate a Bearer Token
|
|
22
|
-
# client = Twitter::REST::Client.new(consumer_key: 'abc', consumer_secret: 'def')
|
|
23
|
-
# bearer_token = client.token
|
|
24
21
|
def token(options = {})
|
|
25
22
|
options = options.dup
|
|
26
23
|
options[:bearer_token_request] = true
|
|
27
24
|
options[:grant_type] ||= "client_credentials"
|
|
28
25
|
url = "https://api.twitter.com/oauth2/token"
|
|
29
|
-
headers = Twitter::Headers.new(self, :post, url, options).request_headers
|
|
26
|
+
headers = ::Twitter::Headers.new(self, :post, url, options).request_headers # steep:ignore ArgumentTypeMismatch
|
|
30
27
|
response = HTTP.headers(headers).post(url, form: options)
|
|
31
|
-
response.parse
|
|
28
|
+
response.parse.fetch("access_token")
|
|
32
29
|
end
|
|
33
|
-
|
|
30
|
+
# @!method bearer_token
|
|
31
|
+
# @api public
|
|
32
|
+
# @see #token
|
|
33
|
+
alias_method :bearer_token, :token
|
|
34
34
|
|
|
35
|
-
#
|
|
35
|
+
# Revokes an issued OAuth 2 Bearer Token
|
|
36
36
|
#
|
|
37
|
+
# @api public
|
|
37
38
|
# @see https://dev.twitter.com/rest/reference/post/oauth2/invalidate_token
|
|
38
39
|
# @rate_limited No
|
|
39
40
|
# @authentication Required
|
|
40
41
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
42
|
+
# @example
|
|
43
|
+
# client.invalidate_token('AAAA...')
|
|
41
44
|
# @param access_token [String] The bearer token to revoke.
|
|
42
45
|
# @param options [Hash] A customizable set of options.
|
|
43
46
|
# @return [String] The invalidated token. token_type should be nil.
|
|
44
47
|
def invalidate_token(access_token, options = {})
|
|
45
48
|
options = options.dup
|
|
46
49
|
options[:access_token] = access_token
|
|
47
|
-
perform_post("/oauth2/invalidate_token", options)
|
|
50
|
+
perform_post("/oauth2/invalidate_token", options).fetch(:access_token)
|
|
48
51
|
end
|
|
49
52
|
|
|
50
|
-
#
|
|
53
|
+
# Returns a reverse auth token for mobile applications
|
|
51
54
|
#
|
|
55
|
+
# @api public
|
|
52
56
|
# @see https://dev.twitter.com/rest/reference/post/oauth2/invalidate_token
|
|
53
57
|
# @rate_limited No
|
|
54
58
|
# @authentication Required
|
|
55
59
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
60
|
+
# @example
|
|
61
|
+
# client.reverse_token
|
|
56
62
|
# @return [String] The token string.
|
|
57
63
|
def reverse_token
|
|
58
64
|
options = {x_auth_mode: "reverse_auth"}
|
|
59
65
|
url = "https://api.twitter.com/oauth/request_token"
|
|
60
|
-
auth_header = Twitter::Headers.new(self, :post, url, options).oauth_auth_header.to_s
|
|
66
|
+
auth_header = ::Twitter::Headers.new(self, :post, url, options).oauth_auth_header.to_s # steep:ignore ArgumentTypeMismatch
|
|
61
67
|
HTTP.headers(authorization: auth_header).post(url, params: options).to_s
|
|
62
68
|
end
|
|
63
69
|
end
|