Module: Twitter::API::Users
Constant Summary
- MAX_USERS_PER_REQUEST =
100
Constants included from Utils
Twitter::API::Utils::DEFAULT_CURSOR
Instance Method Summary (collapse)
-
- (Array<Twitter::User>) block(*args)
Blocks the users specified by the authenticating user.
-
- (Boolean) block?(user, options = {})
Returns true if the authenticating user is blocking a target user.
-
- (Array) block(options = {})
Returns an array of numeric user ids the authenticating user is blocking.
-
- (Array<Twitter::User>) blocking(options = {})
Returns an array of user objects that the authenticating user is blocking.
-
- (Array<Twitter::User>) contributees(*args)
Returns an array of users that the specified user can contribute to.
-
- (Array<Twitter::User>) contributors(*args)
Returns an array of users who can contribute to the specified account.
-
- (Twitter::ProfileBanner) profile_banner(*args)
Returns the available size variations of the specified user's profile banner.
-
- (nil) remove_profile_banner(options = {})
Removes the authenticating user's profile banner image.
-
- (Twitter::Settings) settings(options = {})
Updates the authenticating user's settings.
-
- (Array<Twitter::User>) unblock(*args)
Un-blocks the users specified by the authenticating user.
-
- (Twitter::User) update_delivery_device(device, options = {})
Sets which device Twitter delivers updates to for the authenticating user.
-
- (Twitter::User) update_profile(options = {})
Sets values that users are able to set under the "Account" tab of their settings page.
-
- (Twitter::User) update_profile_background_image(image, options = {})
Updates the authenticating user's profile background image.
-
- (nil) update_profile_banner(banner, options = {})
Updates the authenticating user's profile banner image.
-
- (Twitter::User) update_profile_colors(options = {})
Sets one or more hex values that control the color scheme of the authenticating user's profile.
-
- (Twitter::User) update_profile_image(image, options = {})
Updates the authenticating user's profile image.
-
- (Twitter::User) user(*args)
The requested user.
-
- (Boolean) user?(user, options = {})
Returns true if the specified user exists.
-
- (Array<Twitter::User>) user_search(query, options = {})
Returns users that match the given query.
-
- (Array<Twitter::User>) users(*args)
Returns extended information for up to 100 users.
-
- (Twitter::User) verify_credentials(options = {})
(also: #current_user)
Returns the requesting user if authentication was successful, otherwise raises Error::Unauthorized.
Instance Method Details
- (Array<Twitter::User>) block(*users) - (Array<Twitter::User>) block(*users, options)
Destroys a friendship to the blocked user if it exists.
Blocks the users specified by the authenticating user
213 214 215 |
# File 'lib/twitter/api/users.rb', line 213 def block(*args) threaded_user_objects_from_response(:post, "/1.1/blocks/create.json", args) end |
- (Boolean) block?(user, options = {})
Returns true if the authenticating user is blocking a target user
184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/twitter/api/users.rb', line 184 def block?(user, ={}) merge_default_cursor!() user_id = case user when Integer user when String user(user).id when Twitter::User user.id end blocked_ids().all.map(&:to_i).include?(user_id) end |
- (Array) block(options = {})
Returns an array of numeric user ids the authenticating user is blocking
166 167 168 169 170 |
# File 'lib/twitter/api/users.rb', line 166 def blocked_ids(*args) arguments = Twitter::API::Arguments.new(args) merge_user!(arguments., arguments.pop) cursor_from_response(:ids, nil, :get, "/1.1/blocks/ids.json", arguments., :blocked_ids) end |
- (Array<Twitter::User>) blocking(options = {})
Returns an array of user objects that the authenticating user is blocking
151 152 153 |
# File 'lib/twitter/api/users.rb', line 151 def blocking(={}) cursor_from_response(:users, Twitter::User, :get, "/1.1/blocks/list.json", , :blocking) end |
- (Array<Twitter::User>) contributees(options = {}) - (Array<Twitter::User>) contributees(user, options = {})
Returns an array of users that the specified user can contribute to
351 352 353 |
# File 'lib/twitter/api/users.rb', line 351 def contributees(*args) user_objects_from_response(:get, "/1.1/users/contributees.json", args) end |
- (Array<Twitter::User>) contributors(options = {}) - (Array<Twitter::User>) contributors(user, options = {})
Returns an array of users who can contribute to the specified account
374 375 376 |
# File 'lib/twitter/api/users.rb', line 374 def contributors(*args) user_objects_from_response(:get, "/1.1/users/contributors.json", args) end |
- (Twitter::ProfileBanner) profile_banner(options = {}) - (Twitter::ProfileBanner) profile_banner(user, options = {})
If the user has not uploaded a profile banner, a HTTP 404 will be served instead.
Returns the available size variations of the specified user's profile banner.
431 432 433 434 435 |
# File 'lib/twitter/api/users.rb', line 431 def (*args) arguments = Twitter::API::Arguments.new(args) merge_user!(arguments., arguments.pop || screen_name) unless arguments.[:user_id] || arguments.[:screen_name] object_from_response(Twitter::ProfileBanner, :get, "/1.1/users/profile_banner.json", arguments.) end |
- (nil) remove_profile_banner(options = {})
Removes the authenticating user's profile banner image
388 389 390 |
# File 'lib/twitter/api/users.rb', line 388 def (={}) post("/1.1/account/remove_profile_banner.json", )[:body] end |
- (Twitter::Settings) settings(options = {})
Updates the authenticating user's settings. Or, if no options supplied, returns settings (including current trend, geo and sleep time information) for the authenticating user.
33 34 35 36 |
# File 'lib/twitter/api/users.rb', line 33 def settings(={}) request_method = .size.zero? ? :get : :post object_from_response(Twitter::Settings, request_method, "/1.1/account/settings.json", ) end |
- (Array<Twitter::User>) unblock(*users) - (Array<Twitter::User>) unblock(*users, options)
Un-blocks the users specified by the authenticating user
232 233 234 |
# File 'lib/twitter/api/users.rb', line 232 def unblock(*args) threaded_user_objects_from_response(:post, "/1.1/blocks/destroy.json", args) end |
- (Twitter::User) update_delivery_device(device, options = {})
Sets which device Twitter delivers updates to for the authenticating user
65 66 67 |
# File 'lib/twitter/api/users.rb', line 65 def update_delivery_device(device, ={}) object_from_response(Twitter::User, :post, "/1.1/account/update_delivery_device.json", .merge(:device => device)) end |
- (Twitter::User) update_profile(options = {})
Only the options specified will be updated.
Sets values that users are able to set under the "Account" tab of their settings page
84 85 86 |
# File 'lib/twitter/api/users.rb', line 84 def update_profile(={}) object_from_response(Twitter::User, :post, "/1.1/account/update_profile.json", ) end |
- (Twitter::User) update_profile_background_image(image, options = {})
Updates the authenticating user's profile background image
100 101 102 |
# File 'lib/twitter/api/users.rb', line 100 def update_profile_background_image(image, ={}) object_from_response(Twitter::User, :post, "/1.1/account/update_profile_background_image.json", .merge(:image => image)) end |
- (nil) update_profile_banner(banner, options = {})
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.
Profile banner images are processed asynchronously. The profile_banner_url and its variant sizes will not necessary be available directly after upload.
Updates the authenticating user's profile banner image
411 412 413 |
# File 'lib/twitter/api/users.rb', line 411 def (, ={}) post("/1.1/account/update_profile_banner.json", .merge(:banner => ))[:body] end |
- (Twitter::User) update_profile_colors(options = {})
Sets one or more hex values that control the color scheme of the authenticating user's profile
119 120 121 |
# File 'lib/twitter/api/users.rb', line 119 def update_profile_colors(={}) object_from_response(Twitter::User, :post, "/1.1/account/update_profile_colors.json", ) end |
- (Twitter::User) update_profile_image(image, options = {})
Updates the authenticating user's profile image. Note that this method expects raw multipart data, not a URL to an image.
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.
Updates the authenticating user's profile image
136 137 138 |
# File 'lib/twitter/api/users.rb', line 136 def update_profile_image(image, ={}) object_from_response(Twitter::User, :post, "/1.1/account/update_profile_image.json", .merge(:image => image)) end |
- (Twitter::User) user(options = {}) - (Twitter::User) user(user, options = {})
The requested user.
287 288 289 290 291 292 293 294 295 |
# File 'lib/twitter/api/users.rb', line 287 def user(*args) arguments = Twitter::API::Arguments.new(args) if user = arguments.pop merge_user!(arguments., user) object_from_response(Twitter::User, :get, "/1.1/users/show.json", arguments.) else verify_credentials(arguments.) end end |
- (Boolean) user?(user, options = {})
Returns true if the specified user exists
307 308 309 310 311 312 313 |
# File 'lib/twitter/api/users.rb', line 307 def user?(user, ={}) merge_user!(, user) get("/1.1/users/show.json", ) true rescue Twitter::Error::NotFound false end |
- (Array<Twitter::User>) user_search(query, options = {})
Returns users that match the given query
328 329 330 |
# File 'lib/twitter/api/users.rb', line 328 def user_search(query, ={}) objects_from_response(Twitter::User, :get, "/1.1/users/search.json", .merge(:q => query)) end |
- (Array<Twitter::User>) users(*users) - (Array<Twitter::User>) users(*users, options)
Returns extended information for up to 100 users
256 257 258 259 260 261 262 |
# File 'lib/twitter/api/users.rb', line 256 def users(*args) arguments = Twitter::API::Arguments.new(args) method = arguments..delete(:method) || :post arguments.flatten.each_slice(MAX_USERS_PER_REQUEST).threaded_map do |users| objects_from_response(Twitter::User, method, "/1.1/users/lookup.json", merge_users(arguments., users)) end.flatten end |
- (Twitter::User) verify_credentials(options = {}) Also known as: current_user
Returns the requesting user if authentication was successful, otherwise raises Error::Unauthorized
49 50 51 |
# File 'lib/twitter/api/users.rb', line 49 def verify_credentials(={}) object_from_response(Twitter::User, :get, "/1.1/account/verify_credentials.json", ) end |