twitter 5.5.1 → 5.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/CHANGELOG.md +12 -0
  5. data/README.md +8 -10
  6. data/lib/twitter/base.rb +4 -2
  7. data/lib/twitter/client.rb +7 -5
  8. data/lib/twitter/configuration.rb +1 -1
  9. data/lib/twitter/cursor.rb +18 -17
  10. data/lib/twitter/entities.rb +27 -1
  11. data/lib/twitter/error.rb +1 -1
  12. data/lib/twitter/error/request_timeout.rb +10 -0
  13. data/lib/twitter/geo_results.rb +5 -3
  14. data/lib/twitter/media/photo.rb +1 -1
  15. data/lib/twitter/null_object.rb +8 -20
  16. data/lib/twitter/profile_banner.rb +1 -1
  17. data/lib/twitter/request.rb +47 -0
  18. data/lib/twitter/rest/api/direct_messages.rb +7 -5
  19. data/lib/twitter/rest/api/favorites.rb +7 -7
  20. data/lib/twitter/rest/api/friends_and_followers.rb +11 -9
  21. data/lib/twitter/rest/api/help.rb +4 -3
  22. data/lib/twitter/rest/api/lists.rb +9 -7
  23. data/lib/twitter/rest/api/oauth.rb +11 -5
  24. data/lib/twitter/rest/api/places_and_geo.rb +6 -5
  25. data/lib/twitter/rest/api/saved_searches.rb +8 -6
  26. data/lib/twitter/rest/api/search.rb +4 -10
  27. data/lib/twitter/rest/api/spam_reporting.rb +1 -0
  28. data/lib/twitter/rest/api/suggested_users.rb +4 -3
  29. data/lib/twitter/rest/api/timelines.rb +5 -4
  30. data/lib/twitter/rest/api/trends.rb +5 -4
  31. data/lib/twitter/rest/api/tweets.rb +19 -24
  32. data/lib/twitter/rest/api/users.rb +17 -16
  33. data/lib/twitter/rest/api/utils.rb +45 -73
  34. data/lib/twitter/rest/client.rb +34 -34
  35. data/lib/twitter/rest/request/multipart_with_file.rb +2 -0
  36. data/lib/twitter/rest/response/parse_json.rb +2 -0
  37. data/lib/twitter/rest/response/raise_error.rb +2 -0
  38. data/lib/twitter/search_results.rb +28 -60
  39. data/lib/twitter/streaming/client.rb +4 -4
  40. data/lib/twitter/suggestion.rb +1 -1
  41. data/lib/twitter/trend_results.rb +6 -4
  42. data/lib/twitter/tweet.rb +3 -3
  43. data/lib/twitter/user.rb +1 -1
  44. data/lib/twitter/utils.rb +18 -3
  45. data/lib/twitter/version.rb +2 -2
  46. data/spec/helper.rb +1 -1
  47. data/spec/twitter/error_spec.rb +1 -1
  48. data/spec/twitter/geo_factory_spec.rb +1 -1
  49. data/spec/twitter/identifiable_spec.rb +1 -1
  50. data/spec/twitter/media_factory_spec.rb +1 -1
  51. data/spec/twitter/rest/api/favorites_spec.rb +2 -2
  52. data/spec/twitter/rest/api/tweets_spec.rb +4 -4
  53. data/spec/twitter/rest/client_spec.rb +13 -25
  54. data/spec/twitter/tweet_spec.rb +69 -0
  55. data/twitter.gemspec +2 -1
  56. metadata +23 -15
  57. metadata.gz.sig +0 -0
  58. data/spec/twitter/null_object_spec.rb +0 -90
@@ -1,3 +1,4 @@
1
+ require 'twitter/request'
1
2
  require 'twitter/rest/api/utils'
2
3
  require 'twitter/user'
3
4
 
@@ -1,4 +1,5 @@
1
1
  require 'twitter/arguments'
2
+ require 'twitter/request'
2
3
  require 'twitter/rest/api/utils'
3
4
  require 'twitter/suggestion'
4
5
  require 'twitter/user'
@@ -27,9 +28,9 @@ module Twitter
27
28
  def suggestions(*args)
28
29
  arguments = Twitter::Arguments.new(args)
29
30
  if arguments.last
30
- object_from_response(Twitter::Suggestion, :get, "/1.1/users/suggestions/#{arguments.pop}.json", arguments.options)
31
+ perform_with_object(:get, "/1.1/users/suggestions/#{arguments.pop}.json", arguments.options, Twitter::Suggestion)
31
32
  else
32
- objects_from_response(Twitter::Suggestion, :get, '/1.1/users/suggestions.json', arguments.options)
33
+ perform_with_objects(:get, '/1.1/users/suggestions.json', arguments.options, Twitter::Suggestion)
33
34
  end
34
35
  end
35
36
 
@@ -42,7 +43,7 @@ module Twitter
42
43
  # @param options [Hash] A customizable set of options.
43
44
  # @return [Array<Twitter::User>]
44
45
  def suggest_users(slug, options = {})
45
- objects_from_response(Twitter::User, :get, "/1.1/users/suggestions/#{slug}/members.json", options)
46
+ perform_with_objects(:get, "/1.1/users/suggestions/#{slug}/members.json", options, Twitter::User)
46
47
  end
47
48
  end
48
49
  end
@@ -1,3 +1,4 @@
1
+ require 'twitter/request'
1
2
  require 'twitter/rest/api/utils'
2
3
  require 'twitter/tweet'
3
4
  require 'twitter/user'
@@ -24,7 +25,7 @@ module Twitter
24
25
  # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
25
26
  # @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.
26
27
  def mentions_timeline(options = {})
27
- objects_from_response(Twitter::Tweet, :get, '/1.1/statuses/mentions_timeline.json', options)
28
+ perform_with_objects(:get, '/1.1/statuses/mentions_timeline.json', options, Twitter::Tweet)
28
29
  end
29
30
  alias_method :mentions, :mentions_timeline
30
31
 
@@ -112,7 +113,7 @@ module Twitter
112
113
  # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
113
114
  # @option options [Boolean, String, Integer] :include_entities The tweet entities node will be disincluded when set to false.
114
115
  def home_timeline(options = {})
115
- objects_from_response(Twitter::Tweet, :get, '/1.1/statuses/home_timeline.json', options)
116
+ perform_with_objects(:get, '/1.1/statuses/home_timeline.json', options, Twitter::Tweet)
116
117
  end
117
118
 
118
119
  # Returns the 20 most recent retweets posted by users the authenticating user follow.
@@ -152,7 +153,7 @@ module Twitter
152
153
  # @option options [Boolean, String, Integer] :include_entities The tweet entities node will be disincluded when set to false.
153
154
  # @option options [Boolean, String, Integer] :include_user_entities The user entities node will be disincluded when set to false.
154
155
  def retweets_of_me(options = {})
155
- objects_from_response(Twitter::Tweet, :get, '/1.1/statuses/retweets_of_me.json', options)
156
+ perform_with_objects(:get, '/1.1/statuses/retweets_of_me.json', options, Twitter::Tweet)
156
157
  end
157
158
 
158
159
  private
@@ -173,7 +174,7 @@ module Twitter
173
174
 
174
175
  # @param count [Integer]
175
176
  # @return [Array<Twitter::Tweet>]
176
- def collect_with_count(count, &block)
177
+ def collect_with_count(count)
177
178
  options = {}
178
179
  options[:count] = MAX_TWEETS_PER_REQUEST
179
180
  collect_with_max_id do |max_id|
@@ -1,5 +1,6 @@
1
- require 'twitter/rest/api/utils'
2
1
  require 'twitter/place'
2
+ require 'twitter/request'
3
+ require 'twitter/rest/api/utils'
3
4
  require 'twitter/trend_results'
4
5
 
5
6
  module Twitter
@@ -20,7 +21,7 @@ module Twitter
20
21
  # @return [Array<Twitter::Trend>]
21
22
  def trends(id = 1, options = {})
22
23
  options[:id] = id
23
- object_from_response(Twitter::TrendResults, :get, '/1.1/trends/place.json', options)
24
+ perform_with_object(:get, '/1.1/trends/place.json', options, Twitter::TrendResults)
24
25
  end
25
26
  alias_method :local_trends, :trends
26
27
  alias_method :trends_place, :trends
@@ -34,7 +35,7 @@ module Twitter
34
35
  # @param options [Hash] A customizable set of options.
35
36
  # @return [Array<Twitter::Place>]
36
37
  def trends_available(options = {})
37
- objects_from_response(Twitter::Place, :get, '/1.1/trends/available.json', options)
38
+ perform_with_objects(:get, '/1.1/trends/available.json', options, Twitter::Place)
38
39
  end
39
40
  alias_method :trend_locations, :trends_available
40
41
 
@@ -49,7 +50,7 @@ module Twitter
49
50
  # @option options [Float] :long If provided with a :lat option the available trend locations will be sorted by distance, nearest to furthest, to the co-ordinate pair. The valid ranges for longitude are -180.0 to +180.0 (East is positive) inclusive.
50
51
  # @return [Array<Twitter::Place>]
51
52
  def trends_closest(options = {})
52
- objects_from_response(Twitter::Place, :get, '/1.1/trends/closest.json', options)
53
+ perform_with_objects(:get, '/1.1/trends/closest.json', options, Twitter::Place)
53
54
  end
54
55
  end
55
56
  end
@@ -3,6 +3,7 @@ require 'twitter/error/already_posted'
3
3
  require 'twitter/error/already_retweeted'
4
4
  require 'twitter/error/forbidden'
5
5
  require 'twitter/oembed'
6
+ require 'twitter/request'
6
7
  require 'twitter/rest/api/utils'
7
8
  require 'twitter/tweet'
8
9
  require 'twitter/utils'
@@ -12,6 +13,7 @@ module Twitter
12
13
  module API
13
14
  module Tweets
14
15
  include Twitter::REST::API::Utils
16
+ include Twitter::Utils
15
17
 
16
18
  # Returns up to 100 of the first retweets of a given tweet
17
19
  #
@@ -25,8 +27,7 @@ module Twitter
25
27
  # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
26
28
  # @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.
27
29
  def retweets(tweet, options = {})
28
- id = extract_id(tweet)
29
- objects_from_response(Twitter::Tweet, :get, "/1.1/statuses/retweets/#{id}.json", options)
30
+ perform_with_objects(:get, "/1.1/statuses/retweets/#{extract_id(tweet)}.json", options, Twitter::Tweet)
30
31
  end
31
32
 
32
33
  # Show up to 100 users who retweeted the Tweet
@@ -43,8 +44,8 @@ module Twitter
43
44
  # @option options [Boolean] :ids_only ('false') Only return user ids instead of full user objects.
44
45
  def retweeters_of(tweet, options = {})
45
46
  ids_only = !!options.delete(:ids_only)
46
- retweeters = retweets(tweet, options).map(&:user)
47
- ids_only ? retweeters.map(&:id) : retweeters
47
+ retweeters = retweets(tweet, options).collect(&:user)
48
+ ids_only ? retweeters.collect(&:id) : retweeters
48
49
  end
49
50
 
50
51
  # Returns a Tweet
@@ -59,8 +60,7 @@ module Twitter
59
60
  # @param options [Hash] A customizable set of options.
60
61
  # @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.
61
62
  def status(tweet, options = {})
62
- id = extract_id(tweet)
63
- object_from_response(Twitter::Tweet, :get, "/1.1/statuses/show/#{id}.json", options)
63
+ perform_with_object(:get, "/1.1/statuses/show/#{extract_id(tweet)}.json", options, Twitter::Tweet)
64
64
  end
65
65
 
66
66
  # Returns Tweets
@@ -123,7 +123,7 @@ module Twitter
123
123
  hash = options.dup
124
124
  hash[:in_reply_to_status_id] = hash.delete(:in_reply_to_status).id unless hash[:in_reply_to_status].nil?
125
125
  hash[:place_id] = hash.delete(:place).woeid unless hash[:place].nil?
126
- object_from_response(Twitter::Tweet, :post, '/1.1/statuses/update.json', hash.merge(:status => status))
126
+ perform_with_object(:post, '/1.1/statuses/update.json', hash.merge(:status => status), Twitter::Tweet)
127
127
  rescue Twitter::Error::Forbidden => error
128
128
  handle_forbidden_error(Twitter::Error::AlreadyPosted, error)
129
129
  end
@@ -143,10 +143,9 @@ module Twitter
143
143
  # @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.
144
144
  def retweet(*args)
145
145
  arguments = Twitter::Arguments.new(args)
146
- Twitter::Utils.parallel_map(arguments) do |tweet|
147
- id = extract_id(tweet)
146
+ parallel_map(arguments) do |tweet|
148
147
  begin
149
- post_retweet(id, arguments.options)
148
+ post_retweet(extract_id(tweet), arguments.options)
150
149
  rescue Twitter::Error::Forbidden => error
151
150
  raise unless error.message == Twitter::Error::AlreadyRetweeted::MESSAGE
152
151
  end
@@ -169,10 +168,9 @@ module Twitter
169
168
  # @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.
170
169
  def retweet!(*args)
171
170
  arguments = Twitter::Arguments.new(args)
172
- Twitter::Utils.parallel_map(arguments) do |tweet|
173
- id = extract_id(tweet)
171
+ parallel_map(arguments) do |tweet|
174
172
  begin
175
- post_retweet(id, arguments.options)
173
+ post_retweet(extract_id(tweet), arguments.options)
176
174
  rescue Twitter::Error::Forbidden => error
177
175
  handle_forbidden_error(Twitter::Error::AlreadyRetweeted, error)
178
176
  end
@@ -203,7 +201,7 @@ module Twitter
203
201
  hash = options.dup
204
202
  hash[:in_reply_to_status_id] = hash.delete(:in_reply_to_status).id unless hash[:in_reply_to_status].nil?
205
203
  hash[:place_id] = hash.delete(:place).woeid unless hash[:place].nil?
206
- object_from_response(Twitter::Tweet, :post, '/1.1/statuses/update_with_media.json', hash.merge('media[]' => media, 'status' => status))
204
+ perform_with_object(:post, '/1.1/statuses/update_with_media.json', hash.merge('media[]' => media, 'status' => status), Twitter::Tweet)
207
205
  rescue Twitter::Error::Forbidden => error
208
206
  handle_forbidden_error(Twitter::Error::AlreadyPosted, error)
209
207
  end
@@ -226,7 +224,7 @@ module Twitter
226
224
  # @option options [String] :lang Language code for the rendered embed. This will affect the text and localization of the rendered HTML.
227
225
  def oembed(tweet, options = {})
228
226
  options[:id] = extract_id(tweet)
229
- object_from_response(Twitter::OEmbed, :get, '/1.1/statuses/oembed.json', options)
227
+ perform_with_object(:get, '/1.1/statuses/oembed.json', options, Twitter::OEmbed)
230
228
  end
231
229
 
232
230
  # Returns oEmbeds for Tweets
@@ -250,9 +248,8 @@ module Twitter
250
248
  # @option options [String] :lang Language code for the rendered embed. This will affect the text and localization of the rendered HTML.
251
249
  def oembeds(*args)
252
250
  arguments = Twitter::Arguments.new(args)
253
- Twitter::Utils.parallel_map(arguments) do |tweet|
254
- id = extract_id(tweet)
255
- oembed(id, arguments.options)
251
+ parallel_map(arguments) do |tweet|
252
+ oembed(extract_id(tweet), arguments.options)
256
253
  end
257
254
  end
258
255
 
@@ -271,7 +268,7 @@ module Twitter
271
268
  def retweeters_ids(*args)
272
269
  arguments = Twitter::Arguments.new(args)
273
270
  arguments.options[:id] ||= extract_id(arguments.first)
274
- cursor_from_response(:ids, nil, :get, '/1.1/statuses/retweeters/ids.json', arguments.options)
271
+ perform_with_cursor(:get, '/1.1/statuses/retweeters/ids.json', arguments.options, :ids)
275
272
  end
276
273
 
277
274
  private
@@ -282,15 +279,13 @@ module Twitter
282
279
  # @return [Array<Twitter::Tweet>]
283
280
  def parallel_tweets_from_response(request_method, path, args)
284
281
  arguments = Twitter::Arguments.new(args)
285
- Twitter::Utils.parallel_map(arguments) do |tweet|
286
- id = extract_id(tweet)
287
- object_from_response(Twitter::Tweet, request_method, path + "/#{id}.json", arguments.options)
282
+ parallel_map(arguments) do |tweet|
283
+ perform_with_object(request_method, path + "/#{extract_id(tweet)}.json", arguments.options, Twitter::Tweet)
288
284
  end
289
285
  end
290
286
 
291
287
  def post_retweet(tweet, options)
292
- id = extract_id(tweet)
293
- response = post("/1.1/statuses/retweet/#{id}.json", options)
288
+ response = post("/1.1/statuses/retweet/#{extract_id(tweet)}.json", options)
294
289
  retweeted_status = response.dup
295
290
  retweeted_status[:body] = response[:body].delete(:retweeted_status)
296
291
  retweeted_status[:body][:retweeted_status] = response[:body]
@@ -1,6 +1,7 @@
1
1
  require 'twitter/arguments'
2
2
  require 'twitter/error/not_found'
3
3
  require 'twitter/profile_banner'
4
+ require 'twitter/request'
4
5
  require 'twitter/rest/api/utils'
5
6
  require 'twitter/settings'
6
7
  require 'twitter/user'
@@ -11,6 +12,7 @@ module Twitter
11
12
  module API
12
13
  module Users
13
14
  include Twitter::REST::API::Utils
15
+ include Twitter::Utils
14
16
  MAX_USERS_PER_REQUEST = 100
15
17
 
16
18
  # Updates the authenticating user's settings.
@@ -47,7 +49,7 @@ module Twitter
47
49
  # @param options [Hash] A customizable set of options.
48
50
  # @option options [Boolean, String, Integer] :skip_status Do not include user's Tweets when set to true, 't' or 1.
49
51
  def verify_credentials(options = {})
50
- object_from_response(Twitter::User, :get, '/1.1/account/verify_credentials.json', options)
52
+ perform_with_object(:get, '/1.1/account/verify_credentials.json', options, Twitter::User)
51
53
  end
52
54
  alias_method :current_user, :verify_credentials
53
55
 
@@ -61,7 +63,7 @@ module Twitter
61
63
  # @param device [String] Must be one of: 'sms', 'none'.
62
64
  # @param options [Hash] A customizable set of options.
63
65
  def update_delivery_device(device, options = {})
64
- object_from_response(Twitter::User, :post, '/1.1/account/update_delivery_device.json', options.merge(:device => device))
66
+ perform_with_object(:post, '/1.1/account/update_delivery_device.json', options.merge(:device => device), Twitter::User)
65
67
  end
66
68
 
67
69
  # Sets values that users are able to set under the "Account" tab of their settings page
@@ -78,7 +80,7 @@ module Twitter
78
80
  # @option options [String] :location The city or country describing where the user of the account is located. The contents are not normalized or geocoded in any way. Maximum of 30 characters.
79
81
  # @option options [String] :description A description of the user owning the account. Maximum of 160 characters.
80
82
  def update_profile(options = {})
81
- object_from_response(Twitter::User, :post, '/1.1/account/update_profile.json', options)
83
+ perform_with_object(:post, '/1.1/account/update_profile.json', options, Twitter::User)
82
84
  end
83
85
 
84
86
  # Updates the authenticating user's profile background image
@@ -92,7 +94,7 @@ module Twitter
92
94
  # @param options [Hash] A customizable set of options.
93
95
  # @option options [Boolean] :tile Whether or not to tile the background image. If set to true the background image will be displayed tiled. The image will not be tiled otherwise.
94
96
  def update_profile_background_image(image, options = {})
95
- object_from_response(Twitter::User, :post, '/1.1/account/update_profile_background_image.json', options.merge(:image => image))
97
+ perform_with_object(:post, '/1.1/account/update_profile_background_image.json', options.merge(:image => image), Twitter::User)
96
98
  end
97
99
 
98
100
  # Sets one or more hex values that control the color scheme of the authenticating user's profile
@@ -109,7 +111,7 @@ module Twitter
109
111
  # @option options [String] :profile_sidebar_fill_color Profile sidebar's background color.
110
112
  # @option options [String] :profile_sidebar_border_color Profile sidebar's border color.
111
113
  def update_profile_colors(options = {})
112
- object_from_response(Twitter::User, :post, '/1.1/account/update_profile_colors.json', options)
114
+ perform_with_object(:post, '/1.1/account/update_profile_colors.json', options, Twitter::User)
113
115
  end
114
116
 
115
117
  # Updates the authenticating user's profile image
@@ -124,7 +126,7 @@ module Twitter
124
126
  # @param image [File] The avatar image for the profile, base64-encoded. Must be a valid GIF, JPG, or PNG image of less than 700 kilobytes in size. Images with width larger than 500 pixels will be scaled down. Animated GIFs will be converted to a static GIF of the first frame, removing the animation.
125
127
  # @param options [Hash] A customizable set of options.
126
128
  def update_profile_image(image, options = {})
127
- object_from_response(Twitter::User, :post, '/1.1/account/update_profile_image.json', options.merge(:image => image))
129
+ perform_with_object(:post, '/1.1/account/update_profile_image.json', options.merge(:image => image), Twitter::User)
128
130
  end
129
131
 
130
132
  # Returns an array of user objects that the authenticating user is blocking
@@ -137,7 +139,7 @@ module Twitter
137
139
  # @param options [Hash] A customizable set of options.
138
140
  # @option options [Integer] :page Specifies the page of results to retrieve.
139
141
  def blocking(options = {})
140
- cursor_from_response(:users, Twitter::User, :get, '/1.1/blocks/list.json', options)
142
+ perform_with_cursor(:get, '/1.1/blocks/list.json', options, :users, Twitter::User)
141
143
  end
142
144
 
143
145
  # Returns an array of numeric user ids the authenticating user is blocking
@@ -152,7 +154,7 @@ module Twitter
152
154
  def blocked_ids(*args)
153
155
  arguments = Twitter::Arguments.new(args)
154
156
  merge_user!(arguments.options, arguments.pop)
155
- cursor_from_response(:ids, nil, :get, '/1.1/blocks/ids.json', arguments.options)
157
+ perform_with_cursor(:get, '/1.1/blocks/ids.json', arguments.options, :ids)
156
158
  end
157
159
 
158
160
  # Returns true if the authenticating user is blocking a target user
@@ -165,7 +167,6 @@ module Twitter
165
167
  # @param user [Integer, String, URI, Twitter::User] A Twitter user ID, screen name, URI, or object.
166
168
  # @param options [Hash] A customizable set of options.
167
169
  def block?(user, options = {})
168
- merge_default_cursor!(options)
169
170
  user_id = case user
170
171
  when Integer
171
172
  user
@@ -174,7 +175,7 @@ module Twitter
174
175
  when Twitter::User
175
176
  user.id
176
177
  end
177
- blocked_ids(options).map(&:to_i).include?(user_id)
178
+ blocked_ids(options).collect(&:to_i).include?(user_id)
178
179
  end
179
180
 
180
181
  # Blocks the users specified by the authenticating user
@@ -226,9 +227,9 @@ module Twitter
226
227
  # @option options [Boolean] :include_entities The tweet entities node will be disincluded when set to false.
227
228
  def users(*args)
228
229
  arguments = Twitter::Arguments.new(args)
229
- method = arguments.options.delete(:method) || :post
230
- Twitter::Utils.parallel_map(arguments.each_slice(MAX_USERS_PER_REQUEST)) do |users|
231
- objects_from_response(Twitter::User, method, '/1.1/users/lookup.json', merge_users(arguments.options, users))
230
+ request_method = arguments.options.delete(:method) || :post
231
+ parallel_map(arguments.each_slice(MAX_USERS_PER_REQUEST)) do |users|
232
+ perform_with_objects(request_method, '/1.1/users/lookup.json', merge_users(arguments.options, users), Twitter::User)
232
233
  end.flatten
233
234
  end
234
235
 
@@ -254,7 +255,7 @@ module Twitter
254
255
  arguments = Twitter::Arguments.new(args)
255
256
  if arguments.last
256
257
  merge_user!(arguments.options, arguments.pop)
257
- object_from_response(Twitter::User, :get, '/1.1/users/show.json', arguments.options)
258
+ perform_with_object(:get, '/1.1/users/show.json', arguments.options, Twitter::User)
258
259
  else
259
260
  verify_credentials(arguments.options)
260
261
  end
@@ -287,7 +288,7 @@ module Twitter
287
288
  # @option options [Integer] :count The number of people to retrieve. Maxiumum of 20 allowed per page.
288
289
  # @option options [Integer] :page Specifies the page of results to retrieve.
289
290
  def user_search(query, options = {})
290
- objects_from_response(Twitter::User, :get, '/1.1/users/search.json', options.merge(:q => query))
291
+ perform_with_objects(:get, '/1.1/users/search.json', options.merge(:q => query), Twitter::User)
291
292
  end
292
293
 
293
294
  # Returns an array of users that the specified user can contribute to
@@ -374,7 +375,7 @@ module Twitter
374
375
  def profile_banner(*args)
375
376
  arguments = Twitter::Arguments.new(args)
376
377
  merge_user!(arguments.options, arguments.pop || screen_name) unless arguments.options[:user_id] || arguments.options[:screen_name]
377
- object_from_response(Twitter::ProfileBanner, :get, '/1.1/users/profile_banner.json', arguments.options)
378
+ perform_with_object(:get, '/1.1/users/profile_banner.json', arguments.options, Twitter::ProfileBanner)
378
379
  end
379
380
  end
380
381
  end
@@ -1,6 +1,6 @@
1
1
  require 'addressable/uri'
2
2
  require 'twitter/arguments'
3
- require 'twitter/cursor'
3
+ require 'twitter/request'
4
4
  require 'twitter/user'
5
5
  require 'twitter/utils'
6
6
 
@@ -8,23 +8,9 @@ module Twitter
8
8
  module REST
9
9
  module API
10
10
  module Utils
11
- DEFAULT_CURSOR = -1
11
+ include Twitter::Utils
12
12
  URI_SUBSTRING = '://'
13
-
14
- class << self
15
- def included(base)
16
- base.extend(ClassMethods)
17
- end
18
- end
19
-
20
- module ClassMethods
21
- def deprecate_alias(new_name, old_name)
22
- define_method(new_name) do |*args, &block|
23
- warn "#{Kernel.caller.first}: [DEPRECATION] ##{new_name} is deprecated. Use ##{old_name} instead."
24
- send(old_name, *args, &block)
25
- end
26
- end
27
- end
13
+ DEFAULT_CURSOR = -1
28
14
 
29
15
  private
30
16
 
@@ -45,14 +31,42 @@ module Twitter
45
31
  end
46
32
  end
47
33
 
34
+ # @param request_method [Symbol]
35
+ # @param path [String]
36
+ # @param options [Hash]
37
+ # @param klass [Class]
38
+ def perform_with_object(request_method, path, options, klass)
39
+ request = Twitter::Request.new(self, request_method, path, options)
40
+ request.perform_with_object(klass)
41
+ end
42
+
43
+ # @param request_method [Symbol]
44
+ # @param path [String]
45
+ # @param options [Hash]
46
+ # @param klass [Class]
47
+ def perform_with_objects(request_method, path, options, klass)
48
+ request = Twitter::Request.new(self, request_method, path, options)
49
+ request.perform_with_objects(klass)
50
+ end
51
+
52
+ # @param request_method [Symbol]
53
+ # @param path [String]
54
+ # @param options [Hash]
55
+ # @param klass [Class]
56
+ def perform_with_cursor(request_method, path, options, collection_name, klass = nil) # rubocop:disable ParameterLists
57
+ merge_default_cursor!(options)
58
+ request = Twitter::Request.new(self, request_method, path, options)
59
+ request.perform_with_cursor(collection_name.to_sym, klass)
60
+ end
61
+
48
62
  # @param request_method [Symbol]
49
63
  # @param path [String]
50
64
  # @param args [Array]
51
65
  # @return [Array<Twitter::User>]
52
66
  def parallel_user_objects_from_response(request_method, path, args)
53
67
  arguments = Twitter::Arguments.new(args)
54
- Twitter::Utils.parallel_map(arguments) do |user|
55
- object_from_response(Twitter::User, request_method, path, merge_user(arguments.options, user))
68
+ parallel_map(arguments) do |user|
69
+ perform_with_object(request_method, path, merge_user(arguments.options, user), Twitter::User)
56
70
  end
57
71
  end
58
72
 
@@ -63,7 +77,7 @@ module Twitter
63
77
  def user_objects_from_response(request_method, path, args)
64
78
  arguments = Twitter::Arguments.new(args)
65
79
  merge_user!(arguments.options, arguments.pop || screen_name) unless arguments.options[:user_id] || arguments.options[:screen_name]
66
- objects_from_response(Twitter::User, request_method, path, arguments.options)
80
+ perform_with_objects(request_method, path, arguments.options, Twitter::User)
67
81
  end
68
82
 
69
83
  # @param klass [Class]
@@ -71,29 +85,10 @@ module Twitter
71
85
  # @param path [String]
72
86
  # @param args [Array]
73
87
  # @return [Array]
74
- def objects_from_response_with_user(klass, request_method, path, args) # rubocop:disable ParameterLists
88
+ def objects_from_response_with_user(klass, request_method, path, args)
75
89
  arguments = Twitter::Arguments.new(args)
76
90
  merge_user!(arguments.options, arguments.pop)
77
- objects_from_response(klass, request_method, path, arguments.options)
78
- end
79
-
80
- # @param klass [Class]
81
- # @param request_method [Symbol]
82
- # @param path [String]
83
- # @param options [Hash]
84
- # @return [Array]
85
- def objects_from_response(klass, request_method, path, options = {}) # rubocop:disable ParameterLists
86
- response = send(request_method.to_sym, path, options)[:body]
87
- objects_from_array(klass, response)
88
- end
89
-
90
- # @param klass [Class]
91
- # @param array [Array]
92
- # @return [Array]
93
- def objects_from_array(klass, array)
94
- array.map do |element|
95
- klass.new(element)
96
- end
91
+ perform_with_objects(request_method, path, arguments.options, klass)
97
92
  end
98
93
 
99
94
  # @param klass [Class]
@@ -101,24 +96,13 @@ module Twitter
101
96
  # @param path [String]
102
97
  # @param args [Array]
103
98
  # @return [Array]
104
- def parallel_objects_from_response(klass, request_method, path, args) # rubocop:disable ParameterLists
99
+ def parallel_objects_from_response(klass, request_method, path, args)
105
100
  arguments = Twitter::Arguments.new(args)
106
- Twitter::Utils.parallel_map(arguments) do |object|
107
- id = extract_id(object)
108
- object_from_response(klass, request_method, path, arguments.options.merge(:id => id))
101
+ parallel_map(arguments) do |object|
102
+ perform_with_object(request_method, path, arguments.options.merge(:id => extract_id(object)), klass)
109
103
  end
110
104
  end
111
105
 
112
- # @param klass [Class]
113
- # @param request_method [Symbol]
114
- # @param path [String]
115
- # @param options [Hash]
116
- # @return [Object]
117
- def object_from_response(klass, request_method, path, options = {}) # rubocop:disable ParameterLists
118
- response = send(request_method.to_sym, path, options)
119
- klass.from_response(response)
120
- end
121
-
122
106
  # @param collection_name [Symbol]
123
107
  # @param klass [Class]
124
108
  # @param request_method [Symbol]
@@ -128,19 +112,7 @@ module Twitter
128
112
  def cursor_from_response_with_user(collection_name, klass, request_method, path, args) # rubocop:disable ParameterLists
129
113
  arguments = Twitter::Arguments.new(args)
130
114
  merge_user!(arguments.options, arguments.pop || screen_name) unless arguments.options[:user_id] || arguments.options[:screen_name]
131
- cursor_from_response(collection_name, klass, request_method, path, arguments.options)
132
- end
133
-
134
- # @param collection_name [Symbol]
135
- # @param klass [Class]
136
- # @param request_method [Symbol]
137
- # @param path [String]
138
- # @param options [Hash]
139
- # @return [Twitter::Cursor]
140
- def cursor_from_response(collection_name, klass, request_method, path, options) # rubocop:disable ParameterLists
141
- merge_default_cursor!(options)
142
- response = send(request_method.to_sym, path, options)
143
- Twitter::Cursor.from_response(response, collection_name.to_sym, klass, self, request_method, path, options)
115
+ perform_with_cursor(request_method, path, arguments.options, collection_name, klass)
144
116
  end
145
117
 
146
118
  def handle_forbidden_error(klass, error)
@@ -148,14 +120,14 @@ module Twitter
148
120
  fail(error)
149
121
  end
150
122
 
151
- def merge_default_cursor!(options)
152
- options[:cursor] = DEFAULT_CURSOR unless options[:cursor]
153
- end
154
-
155
123
  def screen_name
156
124
  @screen_name ||= verify_credentials.screen_name
157
125
  end
158
126
 
127
+ def merge_default_cursor!(options)
128
+ options[:cursor] = DEFAULT_CURSOR unless options[:cursor]
129
+ end
130
+
159
131
  # Take a user and merge it into the hash with the correct key
160
132
  #
161
133
  # @param hash [Hash]
@@ -187,7 +159,7 @@ module Twitter
187
159
  end
188
160
  end
189
161
 
190
- def set_compound_key(key, value, hash, prefix = nil) # rubocop:disable ParameterLists
162
+ def set_compound_key(key, value, hash, prefix = nil)
191
163
  compound_key = [prefix, key].compact.join('_').to_sym
192
164
  hash[compound_key] = value
193
165
  hash