Module: Twitter::REST::Users
Overview
Methods for working with Twitter users
Constant Summary collapse
- MAX_USERS_PER_REQUEST =
Maximum 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 users that the authenticating user is blocking.
-
#blocked_ids(options = {}) ⇒ Twitter::Cursor
Returns user IDs the authenticating user is blocking.
-
#contributees(*args) ⇒ Array<Twitter::User>
Returns users that the specified user can contribute to.
-
#contributors(*args) ⇒ Array<Twitter::User>
Returns 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 users that the authenticating user is muting.
-
#muted_ids(options = {}) ⇒ Twitter::Cursor
Returns user IDs the authenticating user is muting.
-
#profile_banner(*args) ⇒ Twitter::ProfileBanner
Returns the profile banner size variations for a user.
-
#remove_profile_banner(options = {}) ⇒ nil
Removes the authenticating user’s profile banner image.
-
#settings(options = {}) ⇒ Twitter::Settings
Updates or returns 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 can set in their profile settings.
-
#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
Returns extended information for a given 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.
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
207 208 209 |
# File 'lib/twitter/rest/users.rb', line 207 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
181 182 183 184 185 186 187 188 189 |
# File 'lib/twitter/rest/users.rb', line 181 def block?(user, = {}) user_id = case user when Integer then user when String, URI then user(user).id when User then user.id end blocked_ids().collect(&:to_i).include?(user_id) end |
#blocked(options = {}) ⇒ Array<Twitter::User>
Returns users that the authenticating user is blocking
147 148 149 |
# File 'lib/twitter/rest/users.rb', line 147 def blocked( = {}) perform_get_with_cursor("/1.1/blocks/list.json", , :users, User) end |
#blocked_ids(options = {}) ⇒ Twitter::Cursor
Returns user IDs the authenticating user is blocking
163 164 165 166 167 |
# File 'lib/twitter/rest/users.rb', line 163 def blocked_ids(*args) arguments = 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 users that the specified user can contribute to
337 338 339 |
# File 'lib/twitter/rest/users.rb', line 337 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 users who can contribute to the specified account
358 359 360 |
# File 'lib/twitter/rest/users.rb', line 358 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
439 440 441 |
# File 'lib/twitter/rest/users.rb', line 439 def mute(*args) parallel_users_from_response(:post, "/1.1/mutes/users/create.json", args) end |
#muted(options = {}) ⇒ Array<Twitter::User>
Returns users that the authenticating user is muting
474 475 476 |
# File 'lib/twitter/rest/users.rb', line 474 def muted( = {}) perform_get_with_cursor("/1.1/mutes/users/list.json", , :users, User) end |
#muted_ids(options = {}) ⇒ Twitter::Cursor
Returns user IDs the authenticating user is muting
490 491 492 493 494 |
# File 'lib/twitter/rest/users.rb', line 490 def muted_ids(*args) arguments = 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 is served.
Returns the profile banner size variations for a user
418 419 420 421 422 |
# File 'lib/twitter/rest/users.rb', line 418 def (*args) arguments = Arguments.new(args) merge_user!(arguments., arguments.pop || user_id) unless arguments..key?(:user_id) || arguments..key?(:screen_name) perform_get_with_object("/1.1/users/profile_banner.json", arguments., ProfileBanner) end |
#remove_profile_banner(options = {}) ⇒ nil
Removes the authenticating user’s profile banner image
rubocop:disable Naming/PredicateMethod
374 375 376 377 |
# File 'lib/twitter/rest/users.rb', line 374 def ( = {}) perform_post("/1.1/account/remove_profile_banner.json", ) true end |
#settings(options = {}) ⇒ Twitter::Settings
Updates or returns the authenticating user’s settings
39 40 41 42 43 44 45 46 |
# File 'lib/twitter/rest/users.rb', line 39 def settings( = {}) request_method = .empty? ? :get : :post response = perform_request(request_method, "/1.1/account/settings.json", ) # https://dev.twitter.com/issues/59 empty_array = [] # : Array[untyped] response[:trend_location] = response.fetch(:trend_location, empty_array).first Settings.new(response) end |
#unblock(*users) ⇒ Array<Twitter::User> #unblock(*users, options) ⇒ Array<Twitter::User>
Un-blocks the users specified by the authenticating user
226 227 228 |
# File 'lib/twitter/rest/users.rb', line 226 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
458 459 460 |
# File 'lib/twitter/rest/users.rb', line 458 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
76 77 78 |
# File 'lib/twitter/rest/users.rb', line 76 def update_delivery_device(device, = {}) perform_post_with_object("/1.1/account/update_delivery_device.json", .merge(device:), User) end |
#update_profile(options = {}) ⇒ Twitter::User
Only the options specified will be updated.
Sets values that users can set in their profile settings
97 98 99 |
# File 'lib/twitter/rest/users.rb', line 97 def update_profile( = {}) perform_post_with_object("/1.1/account/update_profile.json", , User) end |
#update_profile_background_image(image, options = {}) ⇒ Twitter::User
Updates the authenticating user’s profile background image
114 115 116 |
# File 'lib/twitter/rest/users.rb', line 114 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
For best results, upload an image that is exactly 1252px by 626px.
Updates the authenticating user’s profile banner image
398 399 400 401 |
# File 'lib/twitter/rest/users.rb', line 398 def (, = {}) perform_post("/1.1/account/update_profile_banner.json", .merge(banner:)) true end |
#update_profile_image(image, options = {}) ⇒ Twitter::User
This method expects raw multipart data, not a URL to an image.
Updates the authenticating user’s profile image
131 132 133 |
# File 'lib/twitter/rest/users.rb', line 131 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 extended information for a given user
273 274 275 276 277 278 279 280 281 |
# File 'lib/twitter/rest/users.rb', line 273 def user(*args) arguments = 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., User) else verify_credentials(arguments.) end end |
#user?(user, options = {}) ⇒ Boolean
Returns true if the specified user exists
293 294 295 296 297 298 299 300 |
# File 'lib/twitter/rest/users.rb', line 293 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
316 317 318 |
# File 'lib/twitter/rest/users.rb', line 316 def user_search(query, = {}) perform_get_with_objects("/1.1/users/search.json", .merge(q: query), User) end |
#users(*users) ⇒ Array<Twitter::User> #users(*users, options) ⇒ Array<Twitter::User>
Returns extended information for up to 100 users
245 246 247 248 249 250 |
# File 'lib/twitter/rest/users.rb', line 245 def users(*args) arguments = 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), User) end end |
#verify_credentials(options = {}) ⇒ Twitter::User
Returns the requesting user if authentication was successful
60 61 62 |
# File 'lib/twitter/rest/users.rb', line 60 def verify_credentials( = {}) perform_get_with_object("/1.1/account/verify_credentials.json", , User) end |