twitter 4.4.2 → 4.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +7 -0
- data/lib/twitter.rb +1 -1
- data/lib/twitter/api/arguments.rb +13 -0
- data/lib/twitter/api/direct_messages.rb +8 -7
- data/lib/twitter/api/favorites.rb +11 -10
- data/lib/twitter/api/friends_and_followers.rb +16 -31
- data/lib/twitter/api/help.rb +1 -1
- data/lib/twitter/api/lists.rb +41 -51
- data/lib/twitter/api/places_and_geo.rb +5 -5
- data/lib/twitter/api/saved_searches.rb +9 -8
- data/lib/twitter/api/spam_reporting.rb +1 -1
- data/lib/twitter/api/suggested_users.rb +6 -5
- data/lib/twitter/api/timelines.rb +6 -8
- data/lib/twitter/api/trends.rb +3 -3
- data/lib/twitter/api/tweets.rb +14 -13
- data/lib/twitter/api/undocumented.rb +7 -9
- data/lib/twitter/api/users.rb +22 -19
- data/lib/twitter/api/utils.rb +61 -62
- data/lib/twitter/base.rb +0 -1
- data/lib/twitter/configurable.rb +24 -5
- data/lib/twitter/core_ext/kernel.rb +0 -5
- data/lib/twitter/cursor.rb +1 -1
- data/lib/twitter/default.rb +9 -5
- data/lib/twitter/error/configuration_error.rb +8 -0
- data/lib/twitter/tweet.rb +6 -3
- data/lib/twitter/version.rb +1 -1
- data/spec/fixtures/about_me.json +1 -1
- data/spec/fixtures/by_friends.json +1 -1
- data/spec/fixtures/category.json +1 -1
- data/spec/fixtures/contributees.json +1 -1
- data/spec/fixtures/direct_messages.json +1 -1
- data/spec/fixtures/followers_list.json +1 -1
- data/spec/fixtures/followers_list2.json +1 -1
- data/spec/fixtures/friends_list.json +1 -1
- data/spec/fixtures/friends_list2.json +1 -1
- data/spec/fixtures/lists.json +1 -1
- data/spec/fixtures/locations.json +1 -1
- data/spec/fixtures/members.json +1 -1
- data/spec/fixtures/memberships.json +1 -1
- data/spec/fixtures/memberships2.json +1 -1
- data/spec/fixtures/retweets.json +1 -1
- data/spec/fixtures/search.json +1 -1
- data/spec/fixtures/search_malformed.json +1 -1
- data/spec/fixtures/subscriptions.json +1 -1
- data/spec/fixtures/subscriptions2.json +1 -1
- data/spec/fixtures/user_timeline.json +1 -1
- data/spec/fixtures/users_list.json +1 -1
- data/spec/fixtures/users_list2.json +1 -1
- data/spec/twitter/api/favorites_spec.rb +4 -4
- data/spec/twitter/api/friends_and_followers_spec.rb +32 -28
- data/spec/twitter/api/suggested_users_spec.rb +1 -1
- data/spec/twitter/api/tweets_spec.rb +4 -4
- data/spec/twitter/api/users_spec.rb +6 -6
- data/spec/twitter/client_spec.rb +1 -1
- data/spec/twitter_spec.rb +24 -0
- data/twitter.gemspec +3 -4
- metadata +10 -48
- data/spec/fixtures/all.json +0 -1
- data/spec/fixtures/contributors.json +0 -1
- data/spec/fixtures/enhance_your_calm.text +0 -11
- data/spec/fixtures/favorites.json +0 -1
- data/spec/fixtures/image_facets.json +0 -1
- data/spec/fixtures/media_timeline.json +0 -1
- data/spec/fixtures/profile_image.text +0 -24
- data/spec/fixtures/recommendations.json +0 -1
- data/spec/fixtures/related_results.json +0 -1
- data/spec/fixtures/retweeted_status.json +0 -1
- data/spec/fixtures/retweeters_of.json +0 -1
- data/spec/fixtures/status_with_media.json +0 -104
- data/spec/fixtures/trends_current.json +0 -1
- data/spec/fixtures/trends_daily.json +0 -1
- data/spec/fixtures/trends_weekly.json +0 -1
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'twitter/api/arguments'
|
1
2
|
require 'twitter/api/utils'
|
2
3
|
require 'twitter/saved_search'
|
3
4
|
|
@@ -31,12 +32,12 @@ module Twitter
|
|
31
32
|
# @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
|
32
33
|
# @param options [Hash] A customizable set of options.
|
33
34
|
def saved_searches(*args)
|
34
|
-
|
35
|
-
if
|
36
|
-
|
35
|
+
arguments = Twitter::API::Arguments.new(args)
|
36
|
+
if arguments.empty?
|
37
|
+
objects_from_response(Twitter::SavedSearch, :get, "/1.1/saved_searches/list.json", arguments.options)
|
37
38
|
else
|
38
|
-
|
39
|
-
saved_search(id)
|
39
|
+
arguments.flatten.threaded_map do |id|
|
40
|
+
saved_search(id, arguments.options)
|
40
41
|
end
|
41
42
|
end
|
42
43
|
end
|
@@ -87,9 +88,9 @@ module Twitter
|
|
87
88
|
# @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
|
88
89
|
# @param options [Hash] A customizable set of options.
|
89
90
|
def saved_search_destroy(*args)
|
90
|
-
|
91
|
-
|
92
|
-
object_from_response(Twitter::SavedSearch, :post, "/1.1/saved_searches/destroy/#{id}.json", options)
|
91
|
+
arguments = Twitter::API::Arguments.new(args)
|
92
|
+
arguments.flatten.threaded_map do |id|
|
93
|
+
object_from_response(Twitter::SavedSearch, :post, "/1.1/saved_searches/destroy/#{id}.json", arguments.options)
|
93
94
|
end
|
94
95
|
end
|
95
96
|
|
@@ -22,7 +22,7 @@ module Twitter
|
|
22
22
|
# @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
|
23
23
|
# @param options [Hash] A customizable set of options.
|
24
24
|
def report_spam(*args)
|
25
|
-
|
25
|
+
threaded_user_objects_from_response(:post, "/1.1/users/report_spam.json", args)
|
26
26
|
end
|
27
27
|
|
28
28
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'twitter/api/arguments'
|
1
2
|
require 'twitter/api/utils'
|
2
3
|
require 'twitter/suggestion'
|
3
4
|
require 'twitter/user'
|
@@ -27,11 +28,11 @@ module Twitter
|
|
27
28
|
# @example Return the users in the Art & Design category
|
28
29
|
# Twitter.suggestions("art-design")
|
29
30
|
def suggestions(*args)
|
30
|
-
|
31
|
-
if slug =
|
32
|
-
object_from_response(Twitter::Suggestion, :get, "/1.1/users/suggestions/#{slug}.json", options)
|
31
|
+
arguments = Twitter::API::Arguments.new(args)
|
32
|
+
if slug = arguments.pop
|
33
|
+
object_from_response(Twitter::Suggestion, :get, "/1.1/users/suggestions/#{slug}.json", arguments.options)
|
33
34
|
else
|
34
|
-
|
35
|
+
objects_from_response(Twitter::Suggestion, :get, "/1.1/users/suggestions.json", arguments.options)
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
@@ -46,7 +47,7 @@ module Twitter
|
|
46
47
|
# @example Return the users in the Art & Design category and their most recent Tweet if they are not a protected user
|
47
48
|
# Twitter.suggest_users("art-design")
|
48
49
|
def suggest_users(slug, options={})
|
49
|
-
|
50
|
+
objects_from_response(Twitter::User, :get, "/1.1/users/suggestions/#{slug}/members.json", options)
|
50
51
|
end
|
51
52
|
|
52
53
|
end
|
@@ -25,7 +25,7 @@ module Twitter
|
|
25
25
|
# @example Return the 20 most recent mentions (statuses containing @username) for the authenticating user
|
26
26
|
# Twitter.mentions
|
27
27
|
def mentions_timeline(options={})
|
28
|
-
|
28
|
+
objects_from_response(Twitter::Tweet, :get, "/1.1/statuses/mentions_timeline.json", options)
|
29
29
|
end
|
30
30
|
alias mentions mentions_timeline
|
31
31
|
|
@@ -50,7 +50,7 @@ module Twitter
|
|
50
50
|
# @example Return the 20 most recent Tweets posted by @sferik
|
51
51
|
# Twitter.user_timeline('sferik')
|
52
52
|
def user_timeline(*args)
|
53
|
-
|
53
|
+
objects_from_response_with_user(Twitter::Tweet, :get, "/1.1/statuses/user_timeline.json", args)
|
54
54
|
end
|
55
55
|
|
56
56
|
# Returns the 20 most recent retweets posted by the specified user
|
@@ -72,10 +72,8 @@ module Twitter
|
|
72
72
|
# @example Return the 20 most recent retweets posted by @sferik
|
73
73
|
# Twitter.retweeted_by_user('sferik')
|
74
74
|
def retweeted_by_user(user, options={})
|
75
|
-
options
|
76
|
-
|
77
|
-
collect_with_count(count) do |count_options|
|
78
|
-
select_retweets(user_timeline(user, options.merge(count_options)))
|
75
|
+
retweets_from_timeline(options) do |opts|
|
76
|
+
user_timeline(user, opts)
|
79
77
|
end
|
80
78
|
end
|
81
79
|
alias retweeted_by retweeted_by_user
|
@@ -123,7 +121,7 @@ module Twitter
|
|
123
121
|
# @example Return the 20 most recent Tweets, including retweets if they exist, posted by the authenticating user and the users they follow
|
124
122
|
# Twitter.home_timeline
|
125
123
|
def home_timeline(options={})
|
126
|
-
|
124
|
+
objects_from_response(Twitter::Tweet, :get, "/1.1/statuses/home_timeline.json", options)
|
127
125
|
end
|
128
126
|
|
129
127
|
# Returns the 20 most recent retweets posted by users the authenticating user follow.
|
@@ -167,7 +165,7 @@ module Twitter
|
|
167
165
|
# @example Return the 20 most recent tweets of the authenticated user that have been retweeted by others
|
168
166
|
# Twitter.retweets_of_me
|
169
167
|
def retweets_of_me(options={})
|
170
|
-
|
168
|
+
objects_from_response(Twitter::Tweet, :get, "/1.1/statuses/retweets_of_me.json", options)
|
171
169
|
end
|
172
170
|
|
173
171
|
private
|
data/lib/twitter/api/trends.rb
CHANGED
@@ -22,7 +22,7 @@ module Twitter
|
|
22
22
|
def trends(id=1, options={})
|
23
23
|
options[:id] = id
|
24
24
|
response = get("/1.1/trends/place.json", options)
|
25
|
-
|
25
|
+
objects_from_array(Twitter::Trend, response[:body].first[:trends])
|
26
26
|
end
|
27
27
|
alias local_trends trends
|
28
28
|
alias trends_place trends
|
@@ -38,7 +38,7 @@ module Twitter
|
|
38
38
|
# @example Return the locations that Twitter has trending topic information for
|
39
39
|
# Twitter.trends_available
|
40
40
|
def trends_available(options={})
|
41
|
-
|
41
|
+
objects_from_response(Twitter::Place, :get, "/1.1/trends/available.json", options)
|
42
42
|
end
|
43
43
|
alias trend_locations trends_available
|
44
44
|
|
@@ -55,7 +55,7 @@ module Twitter
|
|
55
55
|
# @example Return the locations that Twitter has trending topic information for
|
56
56
|
# Twitter.trends_closest
|
57
57
|
def trends_closest(options={})
|
58
|
-
|
58
|
+
objects_from_response(Twitter::Place, :get, "/1.1/trends/closest.json", options)
|
59
59
|
end
|
60
60
|
|
61
61
|
end
|
data/lib/twitter/api/tweets.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'twitter/api/arguments'
|
1
2
|
require 'twitter/api/utils'
|
2
3
|
require 'twitter/error/already_retweeted'
|
3
4
|
require 'twitter/error/forbidden'
|
@@ -23,7 +24,7 @@ module Twitter
|
|
23
24
|
# @example Return up to 100 of the first retweets of the Tweet with the ID 28561922516
|
24
25
|
# Twitter.retweets(28561922516)
|
25
26
|
def retweets(id, options={})
|
26
|
-
|
27
|
+
objects_from_response(Twitter::Tweet, :get, "/1.1/statuses/retweets/#{id}.json", options)
|
27
28
|
end
|
28
29
|
|
29
30
|
# Show up to 100 users who retweeted the Tweet
|
@@ -144,10 +145,10 @@ module Twitter
|
|
144
145
|
# @param options [Hash] A customizable set of options.
|
145
146
|
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
|
146
147
|
def retweet(*args)
|
147
|
-
|
148
|
-
|
148
|
+
arguments = Twitter::API::Arguments.new(args)
|
149
|
+
arguments.flatten.threaded_map do |id|
|
149
150
|
begin
|
150
|
-
post_retweet(id, options)
|
151
|
+
post_retweet(id, arguments.options)
|
151
152
|
rescue Twitter::Error::Forbidden => error
|
152
153
|
raise unless error.message == Twitter::Error::AlreadyRetweeted::MESSAGE
|
153
154
|
end
|
@@ -171,10 +172,10 @@ module Twitter
|
|
171
172
|
# @param options [Hash] A customizable set of options.
|
172
173
|
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
|
173
174
|
def retweet!(*args)
|
174
|
-
|
175
|
-
|
175
|
+
arguments = Twitter::API::Arguments.new(args)
|
176
|
+
arguments.flatten.threaded_map do |id|
|
176
177
|
begin
|
177
|
-
post_retweet(id, options)
|
178
|
+
post_retweet(id, arguments.options)
|
178
179
|
rescue Twitter::Error::Forbidden => error
|
179
180
|
handle_forbidden_error(Twitter::Error::AlreadyRetweeted, error)
|
180
181
|
end
|
@@ -248,9 +249,9 @@ module Twitter
|
|
248
249
|
# @option options [String] :related A value for the TWT related parameter, as described in {https://dev.twitter.com/docs/intents Web Intents}. This value will be forwarded to all Web Intents calls.
|
249
250
|
# @option options [String] :lang Language code for the rendered embed. This will affect the text and localization of the rendered HTML.
|
250
251
|
def oembeds(*args)
|
251
|
-
|
252
|
-
|
253
|
-
object_from_response(Twitter::OEmbed, :get, "/1.1/statuses/oembed.json?id=#{id}", options)
|
252
|
+
arguments = Twitter::API::Arguments.new(args)
|
253
|
+
arguments.flatten.threaded_map do |id|
|
254
|
+
object_from_response(Twitter::OEmbed, :get, "/1.1/statuses/oembed.json?id=#{id}", arguments.options)
|
254
255
|
end
|
255
256
|
end
|
256
257
|
|
@@ -261,9 +262,9 @@ module Twitter
|
|
261
262
|
# @param args [Array]
|
262
263
|
# @return [Array<Twitter::Tweet>]
|
263
264
|
def threaded_tweets_from_response(request_method, path, args)
|
264
|
-
|
265
|
-
|
266
|
-
object_from_response(Twitter::Tweet, request_method, path + "/#{id}.json", options)
|
265
|
+
arguments = Twitter::API::Arguments.new(args)
|
266
|
+
arguments.flatten.threaded_map do |id|
|
267
|
+
object_from_response(Twitter::Tweet, request_method, path + "/#{id}.json", arguments.options)
|
267
268
|
end
|
268
269
|
end
|
269
270
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'twitter/action_factory'
|
2
|
+
require 'twitter/api/arguments'
|
2
3
|
require 'twitter/api/utils'
|
3
4
|
require 'twitter/cursor'
|
4
5
|
require 'twitter/tweet'
|
@@ -22,7 +23,7 @@ module Twitter
|
|
22
23
|
# @example Return activity about me
|
23
24
|
# Twitter.activity_about_me
|
24
25
|
def activity_about_me(options={})
|
25
|
-
|
26
|
+
objects_from_response(Twitter::ActionFactory, :get, "/i/activity/about_me.json", options)
|
26
27
|
end
|
27
28
|
|
28
29
|
# Returns activity by friends
|
@@ -38,7 +39,7 @@ module Twitter
|
|
38
39
|
# @example Return activity by friends
|
39
40
|
# Twitter.activity_by_friends
|
40
41
|
def activity_by_friends(options={})
|
41
|
-
|
42
|
+
objects_from_response(Twitter::ActionFactory, :get, "/i/activity/by_friends.json", options)
|
42
43
|
end
|
43
44
|
|
44
45
|
# @note Undocumented
|
@@ -66,10 +67,7 @@ module Twitter
|
|
66
67
|
# Twitter.following_followers_of('sferik')
|
67
68
|
# Twitter.following_followers_of(7505382) # Same as above
|
68
69
|
def following_followers_of(*args)
|
69
|
-
|
70
|
-
merge_default_cursor!(options)
|
71
|
-
merge_user!(options, args.pop || screen_name) unless options[:user_id] || options[:screen_name]
|
72
|
-
cursor_from_response(:users, Twitter::User, :get, "/users/following_followers_of.json", options, :following_followers_of)
|
70
|
+
cursor_from_response_with_user(:users, Twitter::User, :get, "/users/following_followers_of.json", args, :following_followers_of)
|
73
71
|
end
|
74
72
|
|
75
73
|
# Returns activity summary for a Tweet
|
@@ -105,9 +103,9 @@ module Twitter
|
|
105
103
|
# @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
|
106
104
|
# @param options [Hash] A customizable set of options.
|
107
105
|
def statuses_activity(*args)
|
108
|
-
|
109
|
-
|
110
|
-
status_activity(id, options)
|
106
|
+
arguments = Twitter::API::Arguments.new(args)
|
107
|
+
arguments.flatten.threaded_map do |id|
|
108
|
+
status_activity(id, arguments.options)
|
111
109
|
end
|
112
110
|
end
|
113
111
|
|
data/lib/twitter/api/users.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
require 'twitter/api/arguments'
|
1
2
|
require 'twitter/api/utils'
|
3
|
+
require 'twitter/core_ext/enumerable'
|
2
4
|
require 'twitter/error/not_found'
|
3
5
|
require 'twitter/profile_banner'
|
4
6
|
require 'twitter/settings'
|
@@ -147,7 +149,6 @@ module Twitter
|
|
147
149
|
# @example Return an array of user objects that the authenticating user is blocking
|
148
150
|
# Twitter.blocking
|
149
151
|
def blocking(options={})
|
150
|
-
merge_default_cursor!(options)
|
151
152
|
cursor_from_response(:users, Twitter::User, :get, "/1.1/blocks/list.json", options, :blocking)
|
152
153
|
end
|
153
154
|
|
@@ -163,7 +164,9 @@ module Twitter
|
|
163
164
|
# @overload block(options={})
|
164
165
|
# @param options [Hash] A customizable set of options.
|
165
166
|
def blocked_ids(*args)
|
166
|
-
|
167
|
+
arguments = Twitter::API::Arguments.new(args)
|
168
|
+
merge_user!(arguments.options, arguments.pop)
|
169
|
+
cursor_from_response(:ids, nil, :get, "/1.1/blocks/ids.json", arguments.options, :blocked_ids)
|
167
170
|
end
|
168
171
|
|
169
172
|
# Returns true if the authenticating user is blocking a target user
|
@@ -208,7 +211,7 @@ module Twitter
|
|
208
211
|
# @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
|
209
212
|
# @param options [Hash] A customizable set of options.
|
210
213
|
def block(*args)
|
211
|
-
|
214
|
+
threaded_user_objects_from_response(:post, "/1.1/blocks/create.json", args)
|
212
215
|
end
|
213
216
|
|
214
217
|
# Un-blocks the users specified by the authenticating user
|
@@ -227,7 +230,7 @@ module Twitter
|
|
227
230
|
# @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
|
228
231
|
# @param options [Hash] A customizable set of options.
|
229
232
|
def unblock(*args)
|
230
|
-
|
233
|
+
threaded_user_objects_from_response(:post, "/1.1/blocks/destroy.json", args)
|
231
234
|
end
|
232
235
|
|
233
236
|
# Returns extended information for up to 100 users
|
@@ -251,10 +254,10 @@ module Twitter
|
|
251
254
|
# Twitter.users('sferik', 'pengwynn', :method => :get) # Retrieve users with a GET request
|
252
255
|
# Twitter.users(7505382, 14100886, :method => :get) # Same as above
|
253
256
|
def users(*args)
|
254
|
-
|
255
|
-
method = options.delete(:method) || :post
|
256
|
-
|
257
|
-
|
257
|
+
arguments = Twitter::API::Arguments.new(args)
|
258
|
+
method = arguments.options.delete(:method) || :post
|
259
|
+
arguments.flatten.each_slice(MAX_USERS_PER_REQUEST).threaded_map do |users|
|
260
|
+
objects_from_response(Twitter::User, method, "/1.1/users/lookup.json", merge_users(arguments.options, users))
|
258
261
|
end.flatten
|
259
262
|
end
|
260
263
|
|
@@ -279,12 +282,12 @@ module Twitter
|
|
279
282
|
# Twitter.user('sferik')
|
280
283
|
# Twitter.user(7505382) # Same as above
|
281
284
|
def user(*args)
|
282
|
-
|
283
|
-
if user =
|
284
|
-
merge_user!(options, user)
|
285
|
-
object_from_response(Twitter::User, :get, "/1.1/users/show.json", options)
|
285
|
+
arguments = Twitter::API::Arguments.new(args)
|
286
|
+
if user = arguments.pop
|
287
|
+
merge_user!(arguments.options, user)
|
288
|
+
object_from_response(Twitter::User, :get, "/1.1/users/show.json", arguments.options)
|
286
289
|
else
|
287
|
-
verify_credentials(options)
|
290
|
+
verify_credentials(arguments.options)
|
288
291
|
end
|
289
292
|
end
|
290
293
|
|
@@ -320,7 +323,7 @@ module Twitter
|
|
320
323
|
# @example Return users that match "Erik Michaels-Ober"
|
321
324
|
# Twitter.user_search("Erik Michaels-Ober")
|
322
325
|
def user_search(query, options={})
|
323
|
-
|
326
|
+
objects_from_response(Twitter::User, :get, "/1.1/users/search.json", options.merge(:q => query))
|
324
327
|
end
|
325
328
|
|
326
329
|
# Returns an array of users that the specified user can contribute to
|
@@ -343,7 +346,7 @@ module Twitter
|
|
343
346
|
# Twitter.contributees('sferik')
|
344
347
|
# Twitter.contributees(7505382) # Same as above
|
345
348
|
def contributees(*args)
|
346
|
-
|
349
|
+
user_objects_from_response(:get, "/1.1/users/contributees.json", args)
|
347
350
|
end
|
348
351
|
|
349
352
|
# Returns an array of users who can contribute to the specified account
|
@@ -366,7 +369,7 @@ module Twitter
|
|
366
369
|
# Twitter.contributors('sferik')
|
367
370
|
# Twitter.contributors(7505382) # Same as above
|
368
371
|
def contributors(*args)
|
369
|
-
|
372
|
+
user_objects_from_response(:get, "/1.1/users/contributors.json", args)
|
370
373
|
end
|
371
374
|
|
372
375
|
# Removes the authenticating user's profile banner image
|
@@ -423,9 +426,9 @@ module Twitter
|
|
423
426
|
# Twitter.profile_banner('sferik')
|
424
427
|
# Twitter.profile_banner(7505382) # Same as above
|
425
428
|
def profile_banner(*args)
|
426
|
-
|
427
|
-
merge_user!(options,
|
428
|
-
object_from_response(Twitter::ProfileBanner, :get, "/1.1/users/profile_banner.json", options)
|
429
|
+
arguments = Twitter::API::Arguments.new(args)
|
430
|
+
merge_user!(arguments.options, arguments.pop || screen_name) unless arguments.options[:user_id] || arguments.options[:screen_name]
|
431
|
+
object_from_response(Twitter::ProfileBanner, :get, "/1.1/users/profile_banner.json", arguments.options)
|
429
432
|
end
|
430
433
|
|
431
434
|
end
|
data/lib/twitter/api/utils.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
require 'twitter/
|
2
|
-
require 'twitter/core_ext/kernel'
|
1
|
+
require 'twitter/api/arguments'
|
3
2
|
require 'twitter/cursor'
|
4
3
|
require 'twitter/user'
|
5
4
|
|
@@ -11,99 +10,103 @@ module Twitter
|
|
11
10
|
|
12
11
|
private
|
13
12
|
|
14
|
-
# @param
|
15
|
-
# @param
|
16
|
-
# @
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
# @param request_method [Symbol]
|
14
|
+
# @param path [String]
|
15
|
+
# @param args [Array]
|
16
|
+
# @return [Array<Twitter::User>]
|
17
|
+
def threaded_user_objects_from_response(request_method, path, args)
|
18
|
+
arguments = Twitter::API::Arguments.new(args)
|
19
|
+
arguments.flatten.threaded_map do |user|
|
20
|
+
object_from_response(Twitter::User, request_method, path, merge_user(arguments.options, user))
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
23
|
-
# @param klass [Class]
|
24
24
|
# @param request_method [Symbol]
|
25
25
|
# @param path [String]
|
26
|
-
# @param
|
27
|
-
# @return [Array]
|
28
|
-
def
|
29
|
-
|
26
|
+
# @param args [Array]
|
27
|
+
# @return [Array<Twitter::User>]
|
28
|
+
def user_objects_from_response(request_method, path, args)
|
29
|
+
arguments = Twitter::API::Arguments.new(args)
|
30
|
+
merge_user!(arguments.options, arguments.pop || screen_name) unless arguments.options[:user_id] || arguments.options[:screen_name]
|
31
|
+
objects_from_response(Twitter::User, request_method, path, arguments.options)
|
30
32
|
end
|
31
33
|
|
32
34
|
# @param klass [Class]
|
33
35
|
# @param request_method [Symbol]
|
34
36
|
# @param path [String]
|
35
|
-
# @param
|
36
|
-
# @return [
|
37
|
-
def
|
38
|
-
|
39
|
-
|
37
|
+
# @param args [Array]
|
38
|
+
# @return [Array]
|
39
|
+
def objects_from_response_with_user(klass, request_method, path, args)
|
40
|
+
arguments = Twitter::API::Arguments.new(args)
|
41
|
+
merge_user!(arguments.options, arguments.pop)
|
42
|
+
objects_from_response(klass, request_method, path, arguments.options)
|
40
43
|
end
|
41
44
|
|
42
45
|
# @param klass [Class]
|
43
46
|
# @param request_method [Symbol]
|
44
47
|
# @param path [String]
|
45
|
-
# @param
|
48
|
+
# @param options [Hash]
|
46
49
|
# @return [Array]
|
47
|
-
def objects_from_response(klass, request_method, path,
|
48
|
-
|
49
|
-
|
50
|
-
collection_from_response(klass, request_method, path, options)
|
50
|
+
def objects_from_response(klass, request_method, path, options={})
|
51
|
+
response = send(request_method.to_sym, path, options)[:body]
|
52
|
+
objects_from_array(klass, response)
|
51
53
|
end
|
52
54
|
|
53
|
-
# @param
|
54
|
-
# @param
|
55
|
-
# @
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
merge_user!(options, args.pop)
|
61
|
-
cursor_from_response(:ids, nil, request_method, path, options, calling_method)
|
55
|
+
# @param klass [Class]
|
56
|
+
# @param array [Array]
|
57
|
+
# @return [Array]
|
58
|
+
def objects_from_array(klass, array)
|
59
|
+
array.map do |element|
|
60
|
+
klass.fetch_or_new(element)
|
61
|
+
end
|
62
62
|
end
|
63
63
|
|
64
|
-
# @param collection_name [Symbol]
|
65
64
|
# @param klass [Class]
|
66
65
|
# @param request_method [Symbol]
|
67
66
|
# @param path [String]
|
68
|
-
# @param
|
69
|
-
# @
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
67
|
+
# @param args [Array]
|
68
|
+
# @return [Array]
|
69
|
+
def threaded_object_from_response(klass, request_method, path, args)
|
70
|
+
arguments = Twitter::API::Arguments.new(args)
|
71
|
+
arguments.flatten.threaded_map do |id|
|
72
|
+
object_from_response(klass, request_method, path, arguments.options.merge(:id => id))
|
73
|
+
end
|
74
74
|
end
|
75
75
|
|
76
|
+
# @param klass [Class]
|
76
77
|
# @param request_method [Symbol]
|
77
78
|
# @param path [String]
|
78
|
-
# @param
|
79
|
-
# @return [
|
80
|
-
def
|
81
|
-
|
82
|
-
|
83
|
-
collection_from_response(Twitter::User, request_method, path, options)
|
79
|
+
# @param options [Hash]
|
80
|
+
# @return [Object]
|
81
|
+
def object_from_response(klass, request_method, path, options={})
|
82
|
+
response = send(request_method.to_sym, path, options)
|
83
|
+
klass.from_response(response)
|
84
84
|
end
|
85
85
|
|
86
|
+
# @param collection_name [Symbol]
|
87
|
+
# @param klass [Class]
|
86
88
|
# @param request_method [Symbol]
|
87
89
|
# @param path [String]
|
88
90
|
# @param args [Array]
|
89
|
-
# @
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
91
|
+
# @param method_name [Symbol]
|
92
|
+
# @return [Twitter::Cursor]
|
93
|
+
def cursor_from_response_with_user(collection_name, klass, request_method, path, args, method_name)
|
94
|
+
arguments = Twitter::API::Arguments.new(args)
|
95
|
+
merge_user!(arguments.options, arguments.pop || screen_name) unless arguments.options[:user_id] || arguments.options[:screen_name]
|
96
|
+
cursor_from_response(collection_name, klass, request_method, path, arguments.options, method_name)
|
95
97
|
end
|
96
98
|
|
99
|
+
# @param collection_name [Symbol]
|
97
100
|
# @param klass [Class]
|
98
101
|
# @param request_method [Symbol]
|
99
102
|
# @param path [String]
|
100
|
-
# @param
|
101
|
-
# @
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
103
|
+
# @param options [Hash]
|
104
|
+
# @param method_name [Symbol]
|
105
|
+
# @return [Twitter::Cursor]
|
106
|
+
def cursor_from_response(collection_name, klass, request_method, path, options, method_name)
|
107
|
+
merge_default_cursor!(options)
|
108
|
+
response = send(request_method.to_sym, path, options)
|
109
|
+
Twitter::Cursor.from_response(response, collection_name.to_sym, klass, self, method_name, options)
|
107
110
|
end
|
108
111
|
|
109
112
|
def handle_forbidden_error(klass, error)
|
@@ -122,10 +125,6 @@ module Twitter
|
|
122
125
|
@screen_name ||= verify_credentials.screen_name
|
123
126
|
end
|
124
127
|
|
125
|
-
def extract_options!(array)
|
126
|
-
array.last.is_a?(::Hash) ? array.pop : {}
|
127
|
-
end
|
128
|
-
|
129
128
|
# Take a user and merge it into the hash with the correct key
|
130
129
|
#
|
131
130
|
# @param hash [Hash]
|