twitter 4.2.0 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/CHANGELOG.md +4 -0
  2. data/lib/twitter/api/direct_messages.rb +150 -0
  3. data/lib/twitter/api/favorites.rb +132 -0
  4. data/lib/twitter/api/friends_and_followers.rb +259 -0
  5. data/lib/twitter/api/help.rb +64 -0
  6. data/lib/twitter/api/lists.rb +570 -0
  7. data/lib/twitter/api/places_and_geo.rb +121 -0
  8. data/lib/twitter/api/saved_searches.rb +98 -0
  9. data/lib/twitter/api/search.rb +37 -0
  10. data/lib/twitter/api/spam_reporting.rb +30 -0
  11. data/lib/twitter/api/suggested_users.rb +54 -0
  12. data/lib/twitter/api/timelines.rb +213 -0
  13. data/lib/twitter/api/trends.rb +63 -0
  14. data/lib/twitter/api/tweets.rb +284 -0
  15. data/lib/twitter/api/undocumented.rb +116 -0
  16. data/lib/twitter/api/users.rb +427 -0
  17. data/lib/twitter/api/utils.rb +111 -0
  18. data/lib/twitter/client.rb +41 -13
  19. data/lib/twitter/core_ext/enumerable.rb +1 -1
  20. data/lib/twitter/default.rb +16 -18
  21. data/lib/twitter/error/already_favorited.rb +1 -1
  22. data/lib/twitter/error/already_retweeted.rb +1 -1
  23. data/lib/twitter/profile_banner.rb +18 -0
  24. data/lib/twitter/version.rb +1 -1
  25. data/spec/fixtures/profile_banner.json +1 -0
  26. data/spec/twitter/api/direct_messages_spec.rb +32 -32
  27. data/spec/twitter/api/favorites_spec.rb +114 -0
  28. data/spec/twitter/api/{friendships_spec.rb → friends_and_followers_spec.rb} +146 -146
  29. data/spec/twitter/api/geo_spec.rb +28 -28
  30. data/spec/twitter/api/help_spec.rb +1 -1
  31. data/spec/twitter/api/lists_spec.rb +82 -82
  32. data/spec/twitter/api/saved_searches_spec.rb +1 -1
  33. data/spec/twitter/api/search_spec.rb +1 -17
  34. data/spec/twitter/api/{report_spam_spec.rb → spam_reporting_spec.rb} +1 -1
  35. data/spec/twitter/api/suggested_users_spec.rb +94 -0
  36. data/spec/twitter/api/timelines_spec.rb +138 -0
  37. data/spec/twitter/api/trends_spec.rb +1 -1
  38. data/spec/twitter/api/tweets_spec.rb +249 -0
  39. data/spec/twitter/api/undocumented_spec.rb +103 -0
  40. data/spec/twitter/api/users_spec.rb +308 -17
  41. data/spec/twitter/client_spec.rb +1 -1
  42. data/spec/twitter/profile_banner_spec.rb +13 -0
  43. data/twitter.gemspec +3 -2
  44. metadata +44 -21
  45. data/lib/twitter/api.rb +0 -2558
  46. data/spec/twitter/api/account_spec.rb +0 -152
  47. data/spec/twitter/api/activity_spec.rb +0 -37
  48. data/spec/twitter/api/blocks_spec.rb +0 -122
  49. data/spec/twitter/api/statuses_spec.rb +0 -541
@@ -0,0 +1,427 @@
1
+ require 'twitter/api/utils'
2
+ require 'twitter/error/not_found'
3
+ require 'twitter/profile_banner'
4
+ require 'twitter/settings'
5
+ require 'twitter/user'
6
+
7
+ module Twitter
8
+ module API
9
+ module Users
10
+ include Twitter::API::Utils
11
+ MAX_USERS_PER_REQUEST = 100
12
+
13
+ # Updates the authenticating user's settings.
14
+ # Or, if no options supplied, returns settings (including current trend, geo and sleep time information) for the authenticating user.
15
+ #
16
+ # @see https://dev.twitter.com/docs/api/1.1/post/account/settings
17
+ # @see https://dev.twitter.com/docs/api/1.1/get/account/settings
18
+ # @rate_limited Yes
19
+ # @authentication_required Requires user context
20
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
21
+ # @return [Twitter::Settings]
22
+ # @param options [Hash] A customizable set of options.
23
+ # @option options [Integer] :trend_location_woeid The Yahoo! Where On Earth ID to use as the user's default trend location. Global information is available by using 1 as the WOEID. The woeid must be one of the locations returned by {https://dev.twitter.com/docs/api/1.1/get/trends/available GET trends/available}.
24
+ # @option options [Boolean, String, Integer] :sleep_time_enabled When set to true, 't' or 1, will enable sleep time for the user. Sleep time is the time when push or SMS notifications should not be sent to the user.
25
+ # @option options [Integer] :start_sleep_time The hour that sleep time should begin if it is enabled. The value for this parameter should be provided in {http://en.wikipedia.org/wiki/ISO_8601 ISO8601} format (i.e. 00-23). The time is considered to be in the same timezone as the user's time_zone setting.
26
+ # @option options [Integer] :end_sleep_time The hour that sleep time should end if it is enabled. The value for this parameter should be provided in {http://en.wikipedia.org/wiki/ISO_8601 ISO8601} format (i.e. 00-23). The time is considered to be in the same timezone as the user's time_zone setting.
27
+ # @option options [String] :time_zone The timezone dates and times should be displayed in for the user. The timezone must be one of the {http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html Rails TimeZone} names.
28
+ # @option options [String] :lang The language which Twitter should render in for this user. The language must be specified by the appropriate two letter ISO 639-1 representation. Currently supported languages are provided by {https://dev.twitter.com/docs/api/1.1/get/help/languages GET help/languages}.
29
+ # @example Return the settings for the authenticating user.
30
+ # Twitter.settings
31
+ def settings(options={})
32
+ request_method = options.size.zero? ? :get : :post
33
+ object_from_response(Twitter::Settings, request_method, "/1.1/account/settings.json", options)
34
+ end
35
+
36
+ # Returns the requesting user if authentication was successful, otherwise raises {Twitter::Error::Unauthorized}
37
+ #
38
+ # @see https://dev.twitter.com/docs/api/1.1/get/account/verify_credentials
39
+ # @rate_limited Yes
40
+ # @authentication_required Requires user context
41
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
42
+ # @return [Twitter::User] The authenticated user.
43
+ # @param options [Hash] A customizable set of options.
44
+ # @option options [Boolean, String, Integer] :skip_status Do not include user's Tweets when set to true, 't' or 1.
45
+ # @example Return the requesting user if authentication was successful
46
+ # Twitter.verify_credentials
47
+ def verify_credentials(options={})
48
+ object_from_response(Twitter::User, :get, "/1.1/account/verify_credentials.json", options)
49
+ end
50
+ alias current_user verify_credentials
51
+
52
+ # Sets which device Twitter delivers updates to for the authenticating user
53
+ #
54
+ # @see https://dev.twitter.com/docs/api/1.1/post/account/update_delivery_device
55
+ # @rate_limited No
56
+ # @authentication_required Requires user context
57
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
58
+ # @return [Twitter::User] The authenticated user.
59
+ # @param device [String] Must be one of: 'sms', 'none'.
60
+ # @param options [Hash] A customizable set of options.
61
+ # @example Turn SMS updates on for the authenticating user
62
+ # Twitter.update_delivery_device('sms')
63
+ def update_delivery_device(device, options={})
64
+ object_from_response(Twitter::User, :post, "/1.1/account/update_delivery_device.json", options.merge(:device => device))
65
+ end
66
+
67
+ # Sets values that users are able to set under the "Account" tab of their settings page
68
+ #
69
+ # @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile
70
+ # @note Only the options specified will be updated.
71
+ # @rate_limited No
72
+ # @authentication_required Requires user context
73
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
74
+ # @return [Twitter::User] The authenticated user.
75
+ # @param options [Hash] A customizable set of options.
76
+ # @option options [String] :name Full name associated with the profile. Maximum of 20 characters.
77
+ # @option options [String] :url URL associated with the profile. Will be prepended with "http://" if not present. Maximum of 100 characters.
78
+ # @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
+ # @option options [String] :description A description of the user owning the account. Maximum of 160 characters.
80
+ # @example Set authenticating user's name to Erik Michaels-Ober
81
+ # Twitter.update_profile(:name => "Erik Michaels-Ober")
82
+ def update_profile(options={})
83
+ object_from_response(Twitter::User, :post, "/1.1/account/update_profile.json", options)
84
+ end
85
+
86
+ # Updates the authenticating user's profile background image
87
+ #
88
+ # @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile_background_image
89
+ # @rate_limited No
90
+ # @authentication_required Requires user context
91
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
92
+ # @return [Twitter::User] The authenticated user.
93
+ # @param image [File] The background image for the profile, base64-encoded. Must be a valid GIF, JPG, or PNG image of less than 800 kilobytes in size. Images with width larger than 2048 pixels will be forcibly scaled down. The image must be provided as raw multipart data, not a URL.
94
+ # @param options [Hash] A customizable set of options.
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.
96
+ # @example Update the authenticating user's profile background image
97
+ # Twitter.update_profile_background_image(File.new("we_concept_bg2.png"))
98
+ def update_profile_background_image(image, options={})
99
+ object_from_response(Twitter::User, :post, "/1.1/account/update_profile_background_image.json", options.merge(:image => image))
100
+ end
101
+
102
+ # Sets one or more hex values that control the color scheme of the authenticating user's profile
103
+ #
104
+ # @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile_colors
105
+ # @rate_limited No
106
+ # @authentication_required Requires user context
107
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
108
+ # @return [Twitter::User] The authenticated user.
109
+ # @param options [Hash] A customizable set of options.
110
+ # @option options [String] :profile_background_color Profile background color.
111
+ # @option options [String] :profile_text_color Profile text color.
112
+ # @option options [String] :profile_link_color Profile link color.
113
+ # @option options [String] :profile_sidebar_fill_color Profile sidebar's background color.
114
+ # @option options [String] :profile_sidebar_border_color Profile sidebar's border color.
115
+ # @example Set authenticating user's profile background to black
116
+ # Twitter.update_profile_colors(:profile_background_color => '000000')
117
+ def update_profile_colors(options={})
118
+ object_from_response(Twitter::User, :post, "/1.1/account/update_profile_colors.json", options)
119
+ end
120
+
121
+ # Updates the authenticating user's profile image
122
+ #
123
+ # @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile_image
124
+ # @note Updates the authenticating user's profile image. Note that this method expects raw multipart data, not a URL to an image.
125
+ # @note This method asynchronously processes the uploaded file before updating the user's profile image URL. You can either update your local cache the next time you request the user's information, or, at least 5 seconds after uploading the image, ask for the updated URL using GET users/show.
126
+ # @rate_limited No
127
+ # @authentication_required Requires user context
128
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
129
+ # @return [Twitter::User] The authenticated user.
130
+ # @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.
131
+ # @param options [Hash] A customizable set of options.
132
+ # @example Update the authenticating user's profile image
133
+ # Twitter.update_profile_image(File.new("me.jpeg"))
134
+ def update_profile_image(image, options={})
135
+ object_from_response(Twitter::User, :post, "/1.1/account/update_profile_image.json", options.merge(:image => image))
136
+ end
137
+
138
+ # Returns an array of user objects that the authenticating user is blocking
139
+ #
140
+ # @see https://dev.twitter.com/docs/api/1.1/get/blocks/list
141
+ # @rate_limited Yes
142
+ # @authentication_required Requires user context
143
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
144
+ # @return [Array<Twitter::User>] User objects that the authenticating user is blocking.
145
+ # @param options [Hash] A customizable set of options.
146
+ # @option options [Integer] :page Specifies the page of results to retrieve.
147
+ # @example Return an array of user objects that the authenticating user is blocking
148
+ # Twitter.blocking
149
+ def blocking(options={})
150
+ merge_default_cursor!(options)
151
+ cursor_from_response(:users, Twitter::User, :get, "/1.1/blocks/list.json", options)
152
+ end
153
+
154
+ # Returns an array of numeric user ids the authenticating user is blocking
155
+ #
156
+ # @see https://dev.twitter.com/docs/api/1.1/get/blocks/ids
157
+ # @rate_limited Yes
158
+ # @authentication_required Requires user context
159
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
160
+ # @return [Array] Numeric user ids the authenticating user is blocking.
161
+ # @param options [Hash] A customizable set of options.
162
+ # @example Return an array of numeric user ids the authenticating user is blocking
163
+ # Twitter.blocking_ids
164
+ def blocked_ids(*args)
165
+ ids_from_response(:get, "/1.1/blocks/ids.json", args)
166
+ end
167
+
168
+ # Returns true if the authenticating user is blocking a target user
169
+ #
170
+ # @see https://dev.twitter.com/docs/api/1.1/get/blocks/ids
171
+ # @rate_limited Yes
172
+ # @authentication_required Requires user context
173
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
174
+ # @return [Boolean] true if the authenticating user is blocking the target user, otherwise false.
175
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
176
+ # @param options [Hash] A customizable set of options.
177
+ # @example Check whether the authenticating user is blocking @sferik
178
+ # Twitter.block?('sferik')
179
+ # Twitter.block?(7505382) # Same as above
180
+ def block?(user, options={})
181
+ merge_default_cursor!(options)
182
+ user_id = case user
183
+ when Integer
184
+ user
185
+ when String
186
+ user(user).id
187
+ when Twitter::User
188
+ user.id
189
+ end
190
+ blocked_ids(options).all.map(&:to_i).include?(user_id)
191
+ end
192
+
193
+ # Blocks the users specified by the authenticating user
194
+ #
195
+ # @see https://dev.twitter.com/docs/api/1.1/post/blocks/create
196
+ # @note Destroys a friendship to the blocked user if it exists.
197
+ # @rate_limited Yes
198
+ # @authentication_required Requires user context
199
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
200
+ # @return [Array<Twitter::User>] The blocked users.
201
+ # @overload block(*users)
202
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
203
+ # @example Block and unfriend @sferik as the authenticating user
204
+ # Twitter.block('sferik')
205
+ # Twitter.block(7505382) # Same as above
206
+ # @overload block(*users, options)
207
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
208
+ # @param options [Hash] A customizable set of options.
209
+ def block(*args)
210
+ threaded_users_from_response(:post, "/1.1/blocks/create.json", args)
211
+ end
212
+
213
+ # Un-blocks the users specified by the authenticating user
214
+ #
215
+ # @see https://dev.twitter.com/docs/api/1.1/post/blocks/destroy
216
+ # @rate_limited No
217
+ # @authentication_required Requires user context
218
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
219
+ # @return [Array<Twitter::User>] The un-blocked users.
220
+ # @overload unblock(*users)
221
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
222
+ # @example Un-block @sferik as the authenticating user
223
+ # Twitter.unblock('sferik')
224
+ # Twitter.unblock(7505382) # Same as above
225
+ # @overload unblock(*users, options)
226
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
227
+ # @param options [Hash] A customizable set of options.
228
+ def unblock(*args)
229
+ threaded_users_from_response(:post, "/1.1/blocks/destroy.json", args)
230
+ end
231
+
232
+ # Returns extended information for up to 100 users
233
+ #
234
+ # @see https://dev.twitter.com/docs/api/1.1/get/users/lookup
235
+ # @rate_limited Yes
236
+ # @authentication_required Requires user context
237
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
238
+ # @return [Array<Twitter::User>] The requested users.
239
+ # @overload users(*users)
240
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
241
+ # @example Return extended information for @sferik and @pengwynn
242
+ # Twitter.users('sferik', 'pengwynn')
243
+ # Twitter.users(7505382, 14100886) # Same as above
244
+ # @overload users(*users, options)
245
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
246
+ # @param options [Hash] A customizable set of options.
247
+ def users(*args)
248
+ options = args.extract_options!
249
+ args.flatten.each_slice(MAX_USERS_PER_REQUEST).threaded_map do |users|
250
+ collection_from_response(Twitter::User, :post, "/1.1/users/lookup.json", options.merge_users(users))
251
+ end.flatten
252
+ end
253
+
254
+ # @see https://dev.twitter.com/docs/api/1.1/get/users/show
255
+ # @rate_limited Yes
256
+ # @authentication_required Requires user context
257
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
258
+ # @return [Twitter::User] The requested user.
259
+ # @overload user(options={})
260
+ # Returns extended information for the authenticated user
261
+ #
262
+ # @param options [Hash] A customizable set of options.
263
+ # @option options [Boolean, String, Integer] :skip_status Do not include user's Tweets when set to true, 't' or 1.
264
+ # @example Return extended information for the authenticated user
265
+ # Twitter.user
266
+ # @overload user(user, options={})
267
+ # Returns extended information for a given user
268
+ #
269
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
270
+ # @param options [Hash] A customizable set of options.
271
+ # @example Return extended information for @sferik
272
+ # Twitter.user('sferik')
273
+ # Twitter.user(7505382) # Same as above
274
+ def user(*args)
275
+ options = args.extract_options!
276
+ if user = args.pop
277
+ options.merge_user!(user)
278
+ object_from_response(Twitter::User, :get, "/1.1/users/show.json", options)
279
+ else
280
+ verify_credentials(options)
281
+ end
282
+ end
283
+
284
+ # Returns true if the specified user exists
285
+ #
286
+ # @rate_limited Yes
287
+ # @authentication_required Requires user context
288
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
289
+ # @return [Boolean] true if the user exists, otherwise false.
290
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
291
+ # @example Return true if @sferik exists
292
+ # Twitter.user?('sferik')
293
+ # Twitter.user?(7505382) # Same as above
294
+ def user?(user, options={})
295
+ options.merge_user!(user)
296
+ get("/1.1/users/show.json", options)
297
+ true
298
+ rescue Twitter::Error::NotFound
299
+ false
300
+ end
301
+
302
+ # Returns users that match the given query
303
+ #
304
+ # @see https://dev.twitter.com/docs/api/1.1/get/users/search
305
+ # @rate_limited Yes
306
+ # @authentication_required Requires user context
307
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
308
+ # @return [Array<Twitter::User>]
309
+ # @param query [String] The search query to run against people search.
310
+ # @param options [Hash] A customizable set of options.
311
+ # @option options [Integer] :count The number of people to retrieve. Maxiumum of 20 allowed per page.
312
+ # @option options [Integer] :page Specifies the page of results to retrieve.
313
+ # @example Return users that match "Erik Michaels-Ober"
314
+ # Twitter.user_search("Erik Michaels-Ober")
315
+ def user_search(query, options={})
316
+ collection_from_response(Twitter::User, :get, "/1.1/users/search.json", options.merge(:q => query))
317
+ end
318
+
319
+ # Returns an array of users that the specified user can contribute to
320
+ #
321
+ # @see https://dev.twitter.com/docs/api/1.1/get/users/contributees
322
+ # @rate_limited Yes
323
+ # @authentication_required Requires user context
324
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
325
+ # @return [Array<Twitter::User>]
326
+ # @overload contributees(options={})
327
+ # @param options [Hash] A customizable set of options.
328
+ # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
329
+ # @example Return the authenticated user's contributees
330
+ # Twitter.contributees
331
+ # @overload contributees(user, options={})
332
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
333
+ # @param options [Hash] A customizable set of options.
334
+ # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
335
+ # @example Return users @sferik can contribute to
336
+ # Twitter.contributees('sferik')
337
+ # Twitter.contributees(7505382) # Same as above
338
+ def contributees(*args)
339
+ users_from_response(:get, "/1.1/users/contributees.json", args)
340
+ end
341
+
342
+ # Returns an array of users who can contribute to the specified account
343
+ #
344
+ # @see https://dev.twitter.com/docs/api/1.1/get/users/contributors
345
+ # @rate_limited Yes
346
+ # @authentication_required Requires user context
347
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
348
+ # @return [Array<Twitter::User>]
349
+ # @overload contributors(options={})
350
+ # @param options [Hash] A customizable set of options.
351
+ # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
352
+ # @example Return the authenticated user's contributors
353
+ # Twitter.contributors
354
+ # @overload contributors(user, options={})
355
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
356
+ # @param options [Hash] A customizable set of options.
357
+ # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
358
+ # @example Return users who can contribute to @sferik's account
359
+ # Twitter.contributors('sferik')
360
+ # Twitter.contributors(7505382) # Same as above
361
+ def contributors(*args)
362
+ users_from_response(:get, "/1.1/users/contributors.json", args)
363
+ end
364
+
365
+ # Removes the authenticating user's profile banner image
366
+ #
367
+ # @see https://dev.twitter.com/docs/api/1.1/post/account/remove_profile_banner
368
+ # @rate_limited No
369
+ # @authentication_required Requires user context
370
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
371
+ # @return [nil]
372
+ # @param options [Hash] A customizable set of options.
373
+ # @example Remove the authenticating user's profile banner image
374
+ # Twitter.remove_profile_banner
375
+ def remove_profile_banner(options={})
376
+ post("/1.1/account/remove_profile_banner.json", options)[:body]
377
+ end
378
+
379
+ # Updates the authenticating user's profile banner image
380
+ #
381
+ # @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile_banner
382
+ # @note Uploads a profile banner on behalf of the authenticating user. For best results, upload an <5MB image that is exactly 1252px by 626px. Images will be resized for a number of display options. Users with an uploaded profile banner will have a profile_banner_url node in their Users objects. More information about sizing variations can be found in User Profile Images and Banners.
383
+ # @note Profile banner images are processed asynchronously. The profile_banner_url and its variant sizes will not necessary be available directly after upload.
384
+ # @rate_limited No
385
+ # @authentication_required Requires user context
386
+ # @raise [Twitter::Error::BadRequest] Error raised when either an image was not provided or the image data could not be processed.
387
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
388
+ # @raise [Twitter::Error::UnprocessableEntity] Error raised when the image could not be resized or is too large.
389
+ # @return [nil]
390
+ # @param image [File] The Base64-encoded or raw image data being uploaded as the user's new profile banner.
391
+ # @param options [Hash] A customizable set of options.
392
+ # @option options [Integer] :width The width of the preferred section of the image being uploaded in pixels. Use with height, offset_left, and offset_top to select the desired region of the image to use.
393
+ # @option options [Integer] :height The height of the preferred section of the image being uploaded in pixels. Use with width, offset_left, and offset_top to select the desired region of the image to use.
394
+ # @option options [Integer] :offset_left The number of pixels by which to offset the uploaded image from the left. Use with height, width, and offset_top to select the desired region of the image to use.
395
+ # @option options [Integer] :offset_top The number of pixels by which to offset the uploaded image from the top. Use with height, width, and offset_left to select the desired region of the image to use.
396
+ # @example Update the authenticating user's profile banner
397
+ # Twitter.update_profile_banner(File.new("me.jpeg"))
398
+ def update_profile_banner(banner, options={})
399
+ post("/1.1/account/update_profile_banner.json", options.merge(:banner => banner))[:body]
400
+ end
401
+
402
+ # Returns the available size variations of the specified user's profile banner.
403
+ #
404
+ # @see https://dev.twitter.com/docs/api/1.1/get/users/profile_banner
405
+ # @note If the user has not uploaded a profile banner, a HTTP 404 will be served instead.
406
+ # @rate_limited Yes
407
+ # @authentication_required Requires user context
408
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
409
+ # @return [Twitter::ProfileBanner]
410
+ # @overload profile_banner(options={})
411
+ # @example Return the authenticated user's profile banner
412
+ # Twitter.profile_banner
413
+ # @overload profile_banner(user, options={})
414
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
415
+ # @example Return the specified user's profile banner
416
+ # Twitter.profile_banner('sferik')
417
+ # Twitter.profile_banner(7505382) # Same as above
418
+ def profile_banner(*args)
419
+ options = args.extract_options!
420
+ options.merge_user!(args.pop || screen_name)
421
+ object_from_response(Twitter::ProfileBanner, :get, "/1.1/users/profile_banner.json", options)
422
+ end
423
+
424
+
425
+ end
426
+ end
427
+ end
@@ -0,0 +1,111 @@
1
+ require 'twitter/core_ext/array'
2
+ require 'twitter/core_ext/enumerable'
3
+ require 'twitter/core_ext/hash'
4
+ require 'twitter/core_ext/kernel'
5
+ require 'twitter/cursor'
6
+ require 'twitter/user'
7
+
8
+ module Twitter
9
+ module API
10
+ module Utils
11
+
12
+ DEFAULT_CURSOR = -1
13
+
14
+ private
15
+
16
+ # @param klass [Class]
17
+ # @param array [Array]
18
+ # @return [Array]
19
+ def collection_from_array(klass, array)
20
+ array.map do |element|
21
+ klass.fetch_or_new(element)
22
+ end
23
+ end
24
+
25
+ # @param klass [Class]
26
+ # @param request_method [Symbol]
27
+ # @param url [String]
28
+ # @param params [Hash]
29
+ # @param options [Hash]
30
+ # @return [Array]
31
+ def collection_from_response(klass, request_method, url, params={})
32
+ collection_from_array(klass, send(request_method.to_sym, url, params)[:body])
33
+ end
34
+
35
+ # @param klass [Class]
36
+ # @param request_method [Symbol]
37
+ # @param url [String]
38
+ # @param params [Hash]
39
+ # @param options [Hash]
40
+ # @return [Object]
41
+ def object_from_response(klass, request_method, url, params={})
42
+ response = send(request_method.to_sym, url, params)
43
+ klass.from_response(response)
44
+ end
45
+
46
+ # @param klass [Class]
47
+ # @param request_method [Symbol]
48
+ # @param url [String]
49
+ # @param args [Array]
50
+ # @return [Array]
51
+ def objects_from_response(klass, request_method, url, args)
52
+ options = args.extract_options!
53
+ options.merge_user!(args.pop)
54
+ collection_from_response(klass, request_method, url, options)
55
+ end
56
+
57
+ # @param request_method [Symbol]
58
+ # @param url [String]
59
+ # @param args [Array]
60
+ # @return [Array<Integer>]
61
+ def ids_from_response(request_method, url, args)
62
+ options = args.extract_options!
63
+ merge_default_cursor!(options)
64
+ options.merge_user!(args.pop)
65
+ cursor_from_response(:ids, nil, request_method, url, options, calling_method)
66
+ end
67
+
68
+ # @param collection_name [Symbol]
69
+ # @param klass [Class]
70
+ # @param request_method [Symbol]
71
+ # @param url [String]
72
+ # @param params [Hash]
73
+ # @param options [Hash]
74
+ # @return [Twitter::Cursor]
75
+ def cursor_from_response(collection_name, klass, request_method, url, params={}, method_name=calling_method)
76
+ response = send(request_method.to_sym, url, params)
77
+ Twitter::Cursor.from_response(response, collection_name.to_sym, klass, self, method_name, params)
78
+ end
79
+
80
+ # @param request_method [Symbol]
81
+ # @param url [String]
82
+ # @param args [Array]
83
+ # @return [Array<Twitter::User>]
84
+ def users_from_response(request_method, url, args)
85
+ options = args.extract_options!
86
+ options.merge_user!(args.pop || screen_name)
87
+ collection_from_response(Twitter::User, request_method, url, options)
88
+ end
89
+
90
+ # @param request_method [Symbol]
91
+ # @param url [String]
92
+ # @param args [Array]
93
+ # @return [Array<Twitter::User>]
94
+ def threaded_users_from_response(request_method, url, args)
95
+ options = args.extract_options!
96
+ args.flatten.threaded_map do |user|
97
+ object_from_response(Twitter::User, request_method, url, options.merge_user(user))
98
+ end
99
+ end
100
+
101
+ def merge_default_cursor!(options)
102
+ options[:cursor] = DEFAULT_CURSOR unless options[:cursor]
103
+ end
104
+
105
+ def screen_name
106
+ @screen_name ||= verify_credentials.screen_name
107
+ end
108
+
109
+ end
110
+ end
111
+ end