Module: Twitter::API::Users
Constant Summary collapse
- MAX_USERS_PER_REQUEST =
100
Constants included from Utils
Twitter::API::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.
-
#block(options = {}) ⇒ Array
Returns an array of numeric user ids the authenticating user is blocking.
-
#blocking(options = {}) ⇒ Array<Twitter::User>
Returns an array of user objects that 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.
-
#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.
-
#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_colors(options = {}) ⇒ Twitter::User
Sets one or more hex values that control the color scheme of the authenticating user's profile.
-
#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
(also: #current_user)
Returns the requesting user if authentication was successful, otherwise raises Error::Unauthorized.
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
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 |
#block?(user, options = {}) ⇒ Boolean
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 |
#block(options = {}) ⇒ Array
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 |
#blocking(options = {}) ⇒ Array<Twitter::User>
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 |
#contributees(options = {}) ⇒ Array<Twitter::User> #contributees(user, options = {}) ⇒ Array<Twitter::User>
Returns an array of users that the specified user can contribute to
348 349 350 |
# File 'lib/twitter/api/users.rb', line 348 def contributees(*args) user_objects_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
371 372 373 |
# File 'lib/twitter/api/users.rb', line 371 def contributors(*args) user_objects_from_response(:get, "/1.1/users/contributors.json", args) 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.
428 429 430 431 432 |
# File 'lib/twitter/api/users.rb', line 428 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 |
#remove_profile_banner(options = {}) ⇒ nil
Removes the authenticating user's profile banner image
385 386 387 |
# File 'lib/twitter/api/users.rb', line 385 def (={}) post("/1.1/account/remove_profile_banner.json", )[:body] 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.
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 |
#unblock(*users) ⇒ Array<Twitter::User> #unblock(*users, options) ⇒ Array<Twitter::User>
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 |
#update_delivery_device(device, options = {}) ⇒ Twitter::User
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 |
#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
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 |
#update_profile_background_image(image, options = {}) ⇒ Twitter::User
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 |
#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
408 409 410 |
# File 'lib/twitter/api/users.rb', line 408 def (, ={}) post("/1.1/account/update_profile_banner.json", .merge(:banner => ))[:body] end |
#update_profile_colors(options = {}) ⇒ Twitter::User
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 |
#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
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 |
#user(options = {}) ⇒ Twitter::User #user(user, options = {}) ⇒ Twitter::User
Returns The requested user.
284 285 286 287 288 289 290 291 292 |
# File 'lib/twitter/api/users.rb', line 284 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 |
#user?(user, options = {}) ⇒ Boolean
Returns true if the specified user exists
304 305 306 307 308 309 310 |
# File 'lib/twitter/api/users.rb', line 304 def user?(user, ={}) merge_user!(, user) 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
325 326 327 |
# File 'lib/twitter/api/users.rb', line 325 def user_search(query, ={}) objects_from_response(Twitter::User, :get, "/1.1/users/search.json", .merge(:q => query)) end |
#users(*users) ⇒ Array<Twitter::User> #users(*users, options) ⇒ Array<Twitter::User>
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 |
#verify_credentials(options = {}) ⇒ Twitter::User 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 |