Module: Twitter::REST::Users
Constant Summary collapse
- MAX_USERS_PER_REQUEST =
100
Constants included from Utils
Twitter::REST::Utils::DEFAULT_CURSOR
Instance Method Summary collapse
-
#block(*args) ⇒ Array<Twitter::User>
Blocks the users specified by the authenticating user.
-
#block?(user, options = {}) ⇒ Boolean
Returns true if the authenticating user is blocking a target user.
-
#blocked(options = {}) ⇒ Array<Twitter::User>
Returns an array of user objects that the authenticating user is blocking.
-
#blocked_ids(options = {}) ⇒ Twitter::Cursor
Returns an array of numeric user IDs the authenticating user is blocking.
-
#contributees(*args) ⇒ Array<Twitter::User>
Returns an array of users that the specified user can contribute to.
-
#contributors(*args) ⇒ Array<Twitter::User>
Returns an array of users who can contribute to the specified account.
-
#mute(*args) ⇒ Array<Twitter::User>
Mutes the users specified by the authenticating user.
-
#muted(options = {}) ⇒ Array<Twitter::User>
Returns an array of user objects that the authenticating user is muting.
-
#muted_ids(options = {}) ⇒ Twitter::Cursor
Returns an array of numeric user IDs the authenticating user is muting.
-
#profile_banner(*args) ⇒ Twitter::ProfileBanner
Returns the available size variations of the specified user's profile banner.
-
#remove_profile_banner(options = {}) ⇒ nil
Removes the authenticating user's profile banner image.
-
#settings(options = {}) ⇒ Twitter::Settings
Updates the authenticating user's settings.
-
#unblock(*args) ⇒ Array<Twitter::User>
Un-blocks the users specified by the authenticating user.
-
#unmute(*args) ⇒ Array<Twitter::User>
Un-mutes the user specified by the authenticating user.
-
#update_delivery_device(device, options = {}) ⇒ Twitter::User
Sets which device Twitter delivers updates to for the authenticating user.
-
#update_profile(options = {}) ⇒ Twitter::User
Sets values that users are able to set under the "Account" tab of their settings page.
-
#update_profile_background_image(image, options = {}) ⇒ Twitter::User
Updates the authenticating user's profile background image.
-
#update_profile_banner(banner, options = {}) ⇒ nil
Updates the authenticating user's profile banner image.
-
#update_profile_image(image, options = {}) ⇒ Twitter::User
Updates the authenticating user's profile image.
-
#user(*args) ⇒ Twitter::User
The requested user.
-
#user?(user, options = {}) ⇒ Boolean
Returns true if the specified user exists.
-
#user_search(query, options = {}) ⇒ Array<Twitter::User>
Returns users that match the given query.
-
#users(*args) ⇒ Array<Twitter::User>
Returns extended information for up to 100 users.
-
#verify_credentials(options = {}) ⇒ Twitter::User
Returns the requesting user if authentication was successful, otherwise raises Error::Unauthorized.
Methods included from Utils
Instance Method Details
#block(*users) ⇒ Array<Twitter::User> #block(*users, options) ⇒ Array<Twitter::User>
Destroys a friendship to the blocked user if it exists.
Blocks the users specified by the authenticating user
176 177 178 |
# File 'lib/twitter/rest/users.rb', line 176 def block(*args) parallel_users_from_response(:post, "/1.1/blocks/create.json", args) end |
#block?(user, options = {}) ⇒ Boolean
Returns true if the authenticating user is blocking a target user
153 154 155 156 157 158 159 160 161 |
# File 'lib/twitter/rest/users.rb', line 153 def block?(user, = {}) user_id = case user when Integer then user when String, URI, Addressable::URI then user(user).id when Twitter::User then user.id end blocked_ids().collect(&:to_i).include?(user_id) end |
#blocked(options = {}) ⇒ Array<Twitter::User>
Returns an array of user objects that the authenticating user is blocking
125 126 127 |
# File 'lib/twitter/rest/users.rb', line 125 def blocked( = {}) perform_get_with_cursor("/1.1/blocks/list.json", , :users, Twitter::User) end |
#blocked_ids(options = {}) ⇒ Twitter::Cursor
Returns an array of numeric user IDs the authenticating user is blocking
138 139 140 141 142 |
# File 'lib/twitter/rest/users.rb', line 138 def blocked_ids(*args) arguments = Twitter::Arguments.new(args) merge_user!(arguments., arguments.pop) perform_get_with_cursor("/1.1/blocks/ids.json", arguments., :ids) end |
#contributees(options = {}) ⇒ Array<Twitter::User> #contributees(user, options = {}) ⇒ Array<Twitter::User>
Returns an array of users that the specified user can contribute to
287 288 289 |
# File 'lib/twitter/rest/users.rb', line 287 def contributees(*args) users_from_response(:get, "/1.1/users/contributees.json", args) end |
#contributors(options = {}) ⇒ Array<Twitter::User> #contributors(user, options = {}) ⇒ Array<Twitter::User>
Returns an array of users who can contribute to the specified account
305 306 307 |
# File 'lib/twitter/rest/users.rb', line 305 def contributors(*args) users_from_response(:get, "/1.1/users/contributors.json", args) end |
#mute(*users) ⇒ Array<Twitter::User> #mute(*users, options) ⇒ Array<Twitter::User>
Mutes the users specified by the authenticating user
373 374 375 |
# File 'lib/twitter/rest/users.rb', line 373 def mute(*args) parallel_users_from_response(:post, "/1.1/mutes/users/create.json", args) end |
#muted(options = {}) ⇒ Array<Twitter::User>
Returns an array of user objects that the authenticating user is muting
402 403 404 |
# File 'lib/twitter/rest/users.rb', line 402 def muted( = {}) perform_get_with_cursor("/1.1/mutes/users/list.json", , :users, Twitter::User) end |
#muted_ids(options = {}) ⇒ Twitter::Cursor
Returns an array of numeric user IDs the authenticating user is muting
415 416 417 418 419 |
# File 'lib/twitter/rest/users.rb', line 415 def muted_ids(*args) arguments = Twitter::Arguments.new(args) merge_user!(arguments., arguments.pop) perform_get_with_cursor("/1.1/mutes/users/ids.json", arguments., :ids) end |
#profile_banner(options = {}) ⇒ Twitter::ProfileBanner #profile_banner(user, options = {}) ⇒ Twitter::ProfileBanner
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.
355 356 357 358 359 |
# File 'lib/twitter/rest/users.rb', line 355 def (*args) arguments = Twitter::Arguments.new(args) merge_user!(arguments., arguments.pop || user_id) unless arguments.[:user_id] || arguments.[:screen_name] perform_get_with_object("/1.1/users/profile_banner.json", arguments., Twitter::ProfileBanner) end |
#remove_profile_banner(options = {}) ⇒ nil
Removes the authenticating user's profile banner image
317 318 319 320 |
# File 'lib/twitter/rest/users.rb', line 317 def ( = {}) perform_post("/1.1/account/remove_profile_banner.json", ) true end |
#settings(options = {}) ⇒ Twitter::Settings
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.
35 36 37 38 39 40 41 |
# File 'lib/twitter/rest/users.rb', line 35 def settings( = {}) request_method = .empty? ? :get : :post response = perform_request(request_method.to_sym, "/1.1/account/settings.json", ) # https://dev.twitter.com/issues/59 response[:trend_location] = response.fetch(:trend_location, []).first Twitter::Settings.new(response) end |
#unblock(*users) ⇒ Array<Twitter::User> #unblock(*users, options) ⇒ Array<Twitter::User>
Un-blocks the users specified by the authenticating user
192 193 194 |
# File 'lib/twitter/rest/users.rb', line 192 def unblock(*args) parallel_users_from_response(:post, "/1.1/blocks/destroy.json", args) end |
#unmute(*users) ⇒ Array<Twitter::User> #unmute(*users, options) ⇒ Array<Twitter::User>
Un-mutes the user specified by the authenticating user.
389 390 391 |
# File 'lib/twitter/rest/users.rb', line 389 def unmute(*args) parallel_users_from_response(:post, "/1.1/mutes/users/destroy.json", args) end |
#update_delivery_device(device, options = {}) ⇒ Twitter::User
Sets which device Twitter delivers updates to for the authenticating user
65 66 67 |
# File 'lib/twitter/rest/users.rb', line 65 def update_delivery_device(device, = {}) perform_post_with_object("/1.1/account/update_delivery_device.json", .merge(device:), Twitter::User) end |
#update_profile(options = {}) ⇒ Twitter::User
Only the options specified will be updated.
Sets values that users are able to set under the "Account" tab of their settings page
83 84 85 |
# File 'lib/twitter/rest/users.rb', line 83 def update_profile( = {}) perform_post_with_object("/1.1/account/update_profile.json", , Twitter::User) end |
#update_profile_background_image(image, options = {}) ⇒ Twitter::User
Updates the authenticating user's profile background image
97 98 99 |
# File 'lib/twitter/rest/users.rb', line 97 def update_profile_background_image(image, = {}) post_profile_image("/1.1/account/update_profile_background_image.json", image, ) end |
#update_profile_banner(banner, options = {}) ⇒ nil
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
339 340 341 342 |
# File 'lib/twitter/rest/users.rb', line 339 def (, = {}) perform_post("/1.1/account/update_profile_banner.json", .merge(banner:)) true end |
#update_profile_image(image, options = {}) ⇒ Twitter::User
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
112 113 114 |
# File 'lib/twitter/rest/users.rb', line 112 def update_profile_image(image, = {}) post_profile_image("/1.1/account/update_profile_image.json", image, ) end |
#user(options = {}) ⇒ Twitter::User #user(user, options = {}) ⇒ Twitter::User
Returns The requested user.
231 232 233 234 235 236 237 238 239 |
# File 'lib/twitter/rest/users.rb', line 231 def user(*args) arguments = Twitter::Arguments.new(args) if arguments.last || user_id? merge_user!(arguments., arguments.pop || user_id) perform_get_with_object("/1.1/users/show.json", arguments., Twitter::User) else verify_credentials(arguments.) end end |
#user?(user, options = {}) ⇒ Boolean
Returns true if the specified user exists
248 249 250 251 252 253 254 255 |
# File 'lib/twitter/rest/users.rb', line 248 def user?(user, = {}) = .dup merge_user!(, user) perform_get("/1.1/users/show.json", ) true rescue Twitter::Error::NotFound false end |
#user_search(query, options = {}) ⇒ Array<Twitter::User>
Returns users that match the given query
268 269 270 271 |
# File 'lib/twitter/rest/users.rb', line 268 def user_search(query, = {}) = .dup perform_get_with_objects("/1.1/users/search.json", .merge(q: query), Twitter::User) end |
#users(*users) ⇒ Array<Twitter::User> #users(*users, options) ⇒ Array<Twitter::User>
Returns extended information for up to 100 users
208 209 210 211 212 213 |
# File 'lib/twitter/rest/users.rb', line 208 def users(*args) arguments = Twitter::Arguments.new(args) flat_pmap(arguments.each_slice(MAX_USERS_PER_REQUEST)) do |users| perform_get_with_objects("/1.1/users/lookup.json", merge_users(arguments., users), Twitter::User) end end |
#verify_credentials(options = {}) ⇒ Twitter::User
Returns the requesting user if authentication was successful, otherwise raises Error::Unauthorized
52 53 54 |
# File 'lib/twitter/rest/users.rb', line 52 def verify_credentials( = {}) perform_get_with_object("/1.1/account/verify_credentials.json", , Twitter::User) end |