twitter 4.4.2 → 4.4.3

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.
Files changed (72) hide show
  1. data/CHANGELOG.md +7 -0
  2. data/lib/twitter.rb +1 -1
  3. data/lib/twitter/api/arguments.rb +13 -0
  4. data/lib/twitter/api/direct_messages.rb +8 -7
  5. data/lib/twitter/api/favorites.rb +11 -10
  6. data/lib/twitter/api/friends_and_followers.rb +16 -31
  7. data/lib/twitter/api/help.rb +1 -1
  8. data/lib/twitter/api/lists.rb +41 -51
  9. data/lib/twitter/api/places_and_geo.rb +5 -5
  10. data/lib/twitter/api/saved_searches.rb +9 -8
  11. data/lib/twitter/api/spam_reporting.rb +1 -1
  12. data/lib/twitter/api/suggested_users.rb +6 -5
  13. data/lib/twitter/api/timelines.rb +6 -8
  14. data/lib/twitter/api/trends.rb +3 -3
  15. data/lib/twitter/api/tweets.rb +14 -13
  16. data/lib/twitter/api/undocumented.rb +7 -9
  17. data/lib/twitter/api/users.rb +22 -19
  18. data/lib/twitter/api/utils.rb +61 -62
  19. data/lib/twitter/base.rb +0 -1
  20. data/lib/twitter/configurable.rb +24 -5
  21. data/lib/twitter/core_ext/kernel.rb +0 -5
  22. data/lib/twitter/cursor.rb +1 -1
  23. data/lib/twitter/default.rb +9 -5
  24. data/lib/twitter/error/configuration_error.rb +8 -0
  25. data/lib/twitter/tweet.rb +6 -3
  26. data/lib/twitter/version.rb +1 -1
  27. data/spec/fixtures/about_me.json +1 -1
  28. data/spec/fixtures/by_friends.json +1 -1
  29. data/spec/fixtures/category.json +1 -1
  30. data/spec/fixtures/contributees.json +1 -1
  31. data/spec/fixtures/direct_messages.json +1 -1
  32. data/spec/fixtures/followers_list.json +1 -1
  33. data/spec/fixtures/followers_list2.json +1 -1
  34. data/spec/fixtures/friends_list.json +1 -1
  35. data/spec/fixtures/friends_list2.json +1 -1
  36. data/spec/fixtures/lists.json +1 -1
  37. data/spec/fixtures/locations.json +1 -1
  38. data/spec/fixtures/members.json +1 -1
  39. data/spec/fixtures/memberships.json +1 -1
  40. data/spec/fixtures/memberships2.json +1 -1
  41. data/spec/fixtures/retweets.json +1 -1
  42. data/spec/fixtures/search.json +1 -1
  43. data/spec/fixtures/search_malformed.json +1 -1
  44. data/spec/fixtures/subscriptions.json +1 -1
  45. data/spec/fixtures/subscriptions2.json +1 -1
  46. data/spec/fixtures/user_timeline.json +1 -1
  47. data/spec/fixtures/users_list.json +1 -1
  48. data/spec/fixtures/users_list2.json +1 -1
  49. data/spec/twitter/api/favorites_spec.rb +4 -4
  50. data/spec/twitter/api/friends_and_followers_spec.rb +32 -28
  51. data/spec/twitter/api/suggested_users_spec.rb +1 -1
  52. data/spec/twitter/api/tweets_spec.rb +4 -4
  53. data/spec/twitter/api/users_spec.rb +6 -6
  54. data/spec/twitter/client_spec.rb +1 -1
  55. data/spec/twitter_spec.rb +24 -0
  56. data/twitter.gemspec +3 -4
  57. metadata +10 -48
  58. data/spec/fixtures/all.json +0 -1
  59. data/spec/fixtures/contributors.json +0 -1
  60. data/spec/fixtures/enhance_your_calm.text +0 -11
  61. data/spec/fixtures/favorites.json +0 -1
  62. data/spec/fixtures/image_facets.json +0 -1
  63. data/spec/fixtures/media_timeline.json +0 -1
  64. data/spec/fixtures/profile_image.text +0 -24
  65. data/spec/fixtures/recommendations.json +0 -1
  66. data/spec/fixtures/related_results.json +0 -1
  67. data/spec/fixtures/retweeted_status.json +0 -1
  68. data/spec/fixtures/retweeters_of.json +0 -1
  69. data/spec/fixtures/status_with_media.json +0 -104
  70. data/spec/fixtures/trends_current.json +0 -1
  71. data/spec/fixtures/trends_daily.json +0 -1
  72. 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
- options = extract_options!(args)
35
- if args.empty?
36
- collection_from_response(Twitter::SavedSearch, :get, "/1.1/saved_searches/list.json", options)
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
- args.flatten.threaded_map do |id|
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
- options = extract_options!(args)
91
- args.flatten.threaded_map do |id|
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
- threaded_users_from_response(:post, "/1.1/users/report_spam.json", args)
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
- options = extract_options!(args)
31
- if slug = args.pop
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
- collection_from_response(Twitter::Suggestion, :get, "/1.1/users/suggestions.json", options)
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
- collection_from_response(Twitter::User, :get, "/1.1/users/suggestions/#{slug}/members.json", options)
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
- collection_from_response(Twitter::Tweet, :get, "/1.1/statuses/mentions_timeline.json", options)
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
- objects_from_response(Twitter::Tweet, :get, "/1.1/statuses/user_timeline.json", args)
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[:include_rts] = true
76
- count = options[:count] || DEFAULT_TWEETS_PER_REQUEST
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
- collection_from_response(Twitter::Tweet, :get, "/1.1/statuses/home_timeline.json", options)
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
- collection_from_response(Twitter::Tweet, :get, "/1.1/statuses/retweets_of_me.json", options)
168
+ objects_from_response(Twitter::Tweet, :get, "/1.1/statuses/retweets_of_me.json", options)
171
169
  end
172
170
 
173
171
  private
@@ -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
- collection_from_array(Twitter::Trend, response[:body].first[:trends])
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
- collection_from_response(Twitter::Place, :get, "/1.1/trends/available.json", options)
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
- collection_from_response(Twitter::Place, :get, "/1.1/trends/closest.json", options)
58
+ objects_from_response(Twitter::Place, :get, "/1.1/trends/closest.json", options)
59
59
  end
60
60
 
61
61
  end
@@ -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
- collection_from_response(Twitter::Tweet, :get, "/1.1/statuses/retweets/#{id}.json", options)
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
- options = extract_options!(args)
148
- args.flatten.threaded_map do |id|
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
- options = extract_options!(args)
175
- args.flatten.threaded_map do |id|
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
- options = extract_options!(args)
252
- args.flatten.threaded_map do |id|
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
- options = extract_options!(args)
265
- args.flatten.threaded_map do |id|
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
- collection_from_response(Twitter::ActionFactory, :get, "/i/activity/about_me.json", options)
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
- collection_from_response(Twitter::ActionFactory, :get, "/i/activity/by_friends.json", options)
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
- options = extract_options!(args)
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
- options = extract_options!(args)
109
- args.flatten.threaded_map do |id|
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
 
@@ -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
- ids_from_response(:get, "/1.1/blocks/ids.json", args, :blocked_ids)
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
- threaded_users_from_response(:post, "/1.1/blocks/create.json", args)
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
- threaded_users_from_response(:post, "/1.1/blocks/destroy.json", args)
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
- options = extract_options!(args)
255
- method = options.delete(:method) || :post
256
- args.flatten.each_slice(MAX_USERS_PER_REQUEST).threaded_map do |users|
257
- collection_from_response(Twitter::User, method, "/1.1/users/lookup.json", merge_users(options, users))
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
- options = extract_options!(args)
283
- if user = args.pop
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
- collection_from_response(Twitter::User, :get, "/1.1/users/search.json", options.merge(:q => query))
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
- users_from_response(:get, "/1.1/users/contributees.json", args)
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
- users_from_response(:get, "/1.1/users/contributors.json", args)
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
- options = extract_options!(args)
427
- merge_user!(options, args.pop || screen_name) unless options[:user_id] || options[:screen_name]
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
@@ -1,5 +1,4 @@
1
- require 'twitter/core_ext/enumerable'
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 klass [Class]
15
- # @param array [Array]
16
- # @return [Array]
17
- def collection_from_array(klass, array)
18
- array.map do |element|
19
- klass.fetch_or_new(element)
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 params [Hash]
27
- # @return [Array]
28
- def collection_from_response(klass, request_method, path, params={})
29
- collection_from_array(klass, send(request_method.to_sym, path, params)[:body])
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 params [Hash]
36
- # @return [Object]
37
- def object_from_response(klass, request_method, path, params={})
38
- response = send(request_method.to_sym, path, params)
39
- klass.from_response(response)
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 args [Array]
48
+ # @param options [Hash]
46
49
  # @return [Array]
47
- def objects_from_response(klass, request_method, path, args)
48
- options = extract_options!(args)
49
- merge_user!(options, args.pop)
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 request_method [Symbol]
54
- # @param path [String]
55
- # @param args [Array]
56
- # @return [Array<Integer>]
57
- def ids_from_response(request_method, path, args, calling_method)
58
- options = extract_options!(args)
59
- merge_default_cursor!(options)
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 params [Hash]
69
- # @param method_name [Symbol]
70
- # @return [Twitter::Cursor]
71
- def cursor_from_response(collection_name, klass, request_method, path, params, method_name)
72
- response = send(request_method.to_sym, path, params)
73
- Twitter::Cursor.from_response(response, collection_name.to_sym, klass, self, method_name, params)
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 args [Array]
79
- # @return [Array<Twitter::User>]
80
- def users_from_response(request_method, path, args)
81
- options = extract_options!(args)
82
- merge_user!(options, args.pop || screen_name) unless options[:user_id] || options[:screen_name]
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
- # @return [Array<Twitter::User>]
90
- def threaded_users_from_response(request_method, path, args)
91
- options = extract_options!(args)
92
- args.flatten.threaded_map do |user|
93
- object_from_response(Twitter::User, request_method, path, merge_user(options, user))
94
- end
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 args [Array]
101
- # @return [Array]
102
- def threaded_object_from_response(klass, request_method, path, args)
103
- options = extract_options!(args)
104
- args.flatten.threaded_map do |id|
105
- object_from_response(klass, request_method, path, options.merge(:id => id))
106
- end
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]