Module: Twitter::REST::API::Users
Constant Summary collapse
- MAX_USERS_PER_REQUEST =
100
Constants included from Utils
Twitter::REST::API::Utils::DEFAULT_CURSOR, Twitter::REST::API::Utils::URI_SUBSTRING
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
193 194 195 |
# File 'lib/twitter/rest/api/users.rb', line 193 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
167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/twitter/rest/api/users.rb', line 167 def block?(user, ={}) merge_default_cursor!() user_id = case user when Integer user when String, URI user(user).id when Twitter::User user.id end blocked_ids().map(&:to_i).include?(user_id) end |
#block(options = {}) ⇒ Array
Returns an array of numeric user ids the authenticating user is blocking
152 153 154 155 156 |
# File 'lib/twitter/rest/api/users.rb', line 152 def blocked_ids(*args) arguments = Twitter::Arguments.new(args) merge_user!(arguments., arguments.pop) cursor_from_response(:ids, nil, :get, "/1.1/blocks/ids.json", arguments.) end |
#blocking(options = {}) ⇒ Array<Twitter::User>
Returns an array of user objects that the authenticating user is blocking
139 140 141 |
# File 'lib/twitter/rest/api/users.rb', line 139 def blocking(={}) cursor_from_response(:users, Twitter::User, :get, "/1.1/blocks/list.json", ) end |
#contributees(options = {}) ⇒ Array<Twitter::User> #contributees(user, options = {}) ⇒ Array<Twitter::User>
Returns an array of users that the specified user can contribute to
307 308 309 |
# File 'lib/twitter/rest/api/users.rb', line 307 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
325 326 327 |
# File 'lib/twitter/rest/api/users.rb', line 325 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.
374 375 376 377 378 |
# File 'lib/twitter/rest/api/users.rb', line 374 def (*args) arguments = Twitter::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
337 338 339 |
# File 'lib/twitter/rest/api/users.rb', line 337 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.
32 33 34 35 36 37 38 |
# File 'lib/twitter/rest/api/users.rb', line 32 def settings(={}) request_method = .size.zero? ? :get : :post response = send(request_method.to_sym, "/1.1/account/settings.json", ) # https://dev.twitter.com/issues/59 response.update(:trend_location => Array(response[:trend_location]).first) Twitter::Settings.from_response(response) end |
#unblock(*users) ⇒ Array<Twitter::User> #unblock(*users, options) ⇒ Array<Twitter::User>
Un-blocks the users specified by the authenticating user
209 210 211 |
# File 'lib/twitter/rest/api/users.rb', line 209 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
63 64 65 |
# File 'lib/twitter/rest/api/users.rb', line 63 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
80 81 82 |
# File 'lib/twitter/rest/api/users.rb', line 80 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
94 95 96 |
# File 'lib/twitter/rest/api/users.rb', line 94 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
359 360 361 |
# File 'lib/twitter/rest/api/users.rb', line 359 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
111 112 113 |
# File 'lib/twitter/rest/api/users.rb', line 111 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
126 127 128 |
# File 'lib/twitter/rest/api/users.rb', line 126 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.
253 254 255 256 257 258 259 260 261 |
# File 'lib/twitter/rest/api/users.rb', line 253 def user(*args) arguments = Twitter::Arguments.new(args) if arguments.last merge_user!(arguments., arguments.pop) 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
270 271 272 273 274 275 276 |
# File 'lib/twitter/rest/api/users.rb', line 270 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
289 290 291 |
# File 'lib/twitter/rest/api/users.rb', line 289 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
227 228 229 230 231 232 233 |
# File 'lib/twitter/rest/api/users.rb', line 227 def users(*args) arguments = Twitter::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/rest/api/users.rb', line 49 def verify_credentials(={}) object_from_response(Twitter::User, :get, "/1.1/account/verify_credentials.json", ) end |