twitter 8.1.0 → 8.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.md +1 -1
  3. data/README.md +173 -11
  4. data/lib/twitter/arguments.rb +14 -1
  5. data/lib/twitter/base.rb +72 -11
  6. data/lib/twitter/basic_user.rb +7 -1
  7. data/lib/twitter/client.rb +94 -3
  8. data/lib/twitter/creatable.rb +11 -2
  9. data/lib/twitter/cursor.rb +58 -11
  10. data/lib/twitter/direct_message.rb +32 -4
  11. data/lib/twitter/direct_message_event.rb +34 -10
  12. data/lib/twitter/direct_messages/welcome_message.rb +22 -1
  13. data/lib/twitter/direct_messages/welcome_message_rule.rb +7 -0
  14. data/lib/twitter/direct_messages/welcome_message_rule_wrapper.rb +26 -3
  15. data/lib/twitter/direct_messages/welcome_message_wrapper.rb +36 -11
  16. data/lib/twitter/entities.rb +84 -8
  17. data/lib/twitter/entity/hashtag.rb +7 -1
  18. data/lib/twitter/entity/symbol.rb +7 -1
  19. data/lib/twitter/entity/uri.rb +2 -1
  20. data/lib/twitter/entity/user_mention.rb +20 -1
  21. data/lib/twitter/entity.rb +7 -1
  22. data/lib/twitter/enumerable.rb +20 -3
  23. data/lib/twitter/error.rb +137 -61
  24. data/lib/twitter/factory.rb +9 -5
  25. data/lib/twitter/geo/point.rb +37 -5
  26. data/lib/twitter/geo/polygon.rb +1 -0
  27. data/lib/twitter/geo.rb +16 -2
  28. data/lib/twitter/geo_factory.rb +7 -3
  29. data/lib/twitter/geo_results.rb +39 -8
  30. data/lib/twitter/headers.rb +44 -7
  31. data/lib/twitter/identity.rb +13 -3
  32. data/lib/twitter/language.rb +21 -1
  33. data/lib/twitter/list.rb +101 -11
  34. data/lib/twitter/media/animated_gif.rb +1 -0
  35. data/lib/twitter/media/photo.rb +19 -3
  36. data/lib/twitter/media/video.rb +21 -3
  37. data/lib/twitter/media/video_info.rb +15 -1
  38. data/lib/twitter/media_factory.rb +7 -3
  39. data/lib/twitter/metadata.rb +14 -1
  40. data/lib/twitter/null_object.rb +16 -14
  41. data/lib/twitter/oembed.rb +56 -2
  42. data/lib/twitter/place.rb +74 -6
  43. data/lib/twitter/premium_search_results.rb +87 -18
  44. data/lib/twitter/profile.rb +100 -44
  45. data/lib/twitter/profile_banner.rb +9 -4
  46. data/lib/twitter/rate_limit.rb +32 -3
  47. data/lib/twitter/relationship.rb +8 -5
  48. data/lib/twitter/rest/account_activity.rb +55 -26
  49. data/lib/twitter/rest/api.rb +2 -0
  50. data/lib/twitter/rest/client.rb +18 -0
  51. data/lib/twitter/rest/direct_messages/welcome_messages.rb +89 -18
  52. data/lib/twitter/rest/direct_messages.rb +158 -94
  53. data/lib/twitter/rest/favorites.rb +57 -21
  54. data/lib/twitter/rest/form_encoder.rb +57 -17
  55. data/lib/twitter/rest/friends_and_followers.rb +101 -35
  56. data/lib/twitter/rest/help.rb +13 -3
  57. data/lib/twitter/rest/lists.rb +133 -45
  58. data/lib/twitter/rest/oauth.rb +23 -17
  59. data/lib/twitter/rest/places_and_geo.rb +44 -28
  60. data/lib/twitter/rest/premium_search.rb +18 -13
  61. data/lib/twitter/rest/request.rb +171 -53
  62. data/lib/twitter/rest/saved_searches.rb +22 -7
  63. data/lib/twitter/rest/search.rb +20 -16
  64. data/lib/twitter/rest/spam_reporting.rb +5 -1
  65. data/lib/twitter/rest/suggested_users.rb +14 -5
  66. data/lib/twitter/rest/timelines.rb +92 -52
  67. data/lib/twitter/rest/trends.rb +31 -12
  68. data/lib/twitter/rest/tweets.rb +145 -88
  69. data/lib/twitter/rest/undocumented.rb +11 -2
  70. data/lib/twitter/rest/upload_utils.rb +42 -26
  71. data/lib/twitter/rest/users.rb +150 -71
  72. data/lib/twitter/rest/utils.rb +135 -39
  73. data/lib/twitter/saved_search.rb +23 -2
  74. data/lib/twitter/search_results.rb +62 -17
  75. data/lib/twitter/settings.rb +37 -11
  76. data/lib/twitter/size.rb +37 -3
  77. data/lib/twitter/source_user.rb +4 -3
  78. data/lib/twitter/streaming/client.rb +60 -8
  79. data/lib/twitter/streaming/connection.rb +55 -8
  80. data/lib/twitter/streaming/deleted_tweet.rb +8 -0
  81. data/lib/twitter/streaming/event.rb +43 -1
  82. data/lib/twitter/streaming/friend_list.rb +1 -0
  83. data/lib/twitter/streaming/message_parser.rb +20 -10
  84. data/lib/twitter/streaming/response.rb +31 -5
  85. data/lib/twitter/streaming/stall_warning.rb +23 -0
  86. data/lib/twitter/suggestion.rb +25 -1
  87. data/lib/twitter/target_user.rb +2 -1
  88. data/lib/twitter/trend.rb +29 -1
  89. data/lib/twitter/trend_results.rb +50 -7
  90. data/lib/twitter/tweet.rb +180 -21
  91. data/lib/twitter/user.rb +289 -53
  92. data/lib/twitter/utils.rb +12 -13
  93. data/lib/twitter/variant.rb +12 -1
  94. data/lib/twitter/version.rb +66 -29
  95. data/lib/twitter.rb +6 -1
  96. metadata +29 -73
  97. data/.yardopts +0 -16
  98. data/CHANGELOG.md +0 -1035
  99. data/CONTRIBUTING.md +0 -49
  100. data/twitter.gemspec +0 -57
@@ -9,164 +9,195 @@ require "twitter/utils"
9
9
 
10
10
  module Twitter
11
11
  module REST
12
+ # Methods for working with Twitter users
12
13
  module Users
13
14
  include Twitter::REST::Utils
14
15
  include Twitter::Utils
16
+
17
+ # Maximum users per request
15
18
  MAX_USERS_PER_REQUEST = 100
16
19
 
17
- # Updates the authenticating user's settings.
18
- # Or, if no options supplied, returns settings (including current trend, geo and sleep time information) for the authenticating user.
20
+ # Updates or returns the authenticating user's settings
19
21
  #
22
+ # @api public
20
23
  # @see https://dev.twitter.com/rest/reference/post/account/settings
21
- # @see https://dev.twitter.com/rest/reference/get/account/settings
22
24
  # @rate_limited Yes
23
25
  # @authentication Requires user context
24
26
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
27
+ # @example
28
+ # client.settings
25
29
  # @return [Twitter::Settings]
26
30
  # @param options [Hash] A customizable set of options.
27
- # @option options [Integer] :trend_location_woeid The Yahoo! Where On Earth ID to use as the user's default trend location. Global information is available by using 1 as the WOEID. The woeid must be one of the locations returned by {https://dev.twitter.com/rest/reference/get/trends/available GET trends/available}.
28
- # @option options [Boolean, String, Integer] :sleep_time_enabled When set to true, 't' or 1, will enable sleep time for the user. Sleep time is the time when push or SMS notifications should not be sent to the user.
29
- # @option options [Integer] :start_sleep_time The hour that sleep time should begin if it is enabled. The value for this parameter should be provided in {http://en.wikipedia.org/wiki/ISO_8601 ISO8601} format (i.e. 00-23). The time is considered to be in the same timezone as the user's time_zone setting.
30
- # @option options [Integer] :end_sleep_time The hour that sleep time should end if it is enabled. The value for this parameter should be provided in {http://en.wikipedia.org/wiki/ISO_8601 ISO8601} format (i.e. 00-23). The time is considered to be in the same timezone as the user's time_zone setting.
31
- # @option options [String] :time_zone The timezone dates and times should be displayed in for the user. The timezone must be one of the {http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html Rails TimeZone} names.
32
- # @option options [String] :lang The language which Twitter should render in for this user. The language must be specified by the appropriate two letter ISO 639-1 representation. Currently supported languages are provided by {https://dev.twitter.com/rest/reference/get/help/languages GET help/languages}.
33
- # @option options [String] :allow_contributor_request Whether to allow others to include user as contributor. Possible values include 'all' (anyone can include user), 'following' (only followers can include user) or 'none'. Also note that changes to this field require the request also include a current_password value with the user's password to successfully modify this field.
34
- # @option options [String] :current_password The user's password. This is only required when modifying the allow_contributor_request field.
31
+ # @option options [Integer] :trend_location_woeid The Yahoo! Where On Earth ID.
32
+ # @option options [Boolean, String, Integer] :sleep_time_enabled Enable sleep time.
33
+ # @option options [Integer] :start_sleep_time The hour sleep time should begin.
34
+ # @option options [Integer] :end_sleep_time The hour sleep time should end.
35
+ # @option options [String] :time_zone The timezone for the user.
36
+ # @option options [String] :lang The language which Twitter should render in.
37
+ # @option options [String] :allow_contributor_request Allow others to include user.
38
+ # @option options [String] :current_password The user's password.
35
39
  def settings(options = {})
36
40
  request_method = options.empty? ? :get : :post
37
- response = perform_request(request_method.to_sym, "/1.1/account/settings.json", options)
41
+ response = perform_request(request_method, "/1.1/account/settings.json", options)
38
42
  # https://dev.twitter.com/issues/59
39
- response[:trend_location] = response.fetch(:trend_location, []).first
40
- Twitter::Settings.new(response)
43
+ empty_array = [] # : Array[untyped]
44
+ response[:trend_location] = response.fetch(:trend_location, empty_array).first
45
+ Settings.new(response)
41
46
  end
42
47
 
43
- # Returns the requesting user if authentication was successful, otherwise raises {Twitter::Error::Unauthorized}
48
+ # Returns the requesting user if authentication was successful
44
49
  #
50
+ # @api public
45
51
  # @see https://dev.twitter.com/rest/reference/get/account/verify_credentials
46
52
  # @rate_limited Yes
47
53
  # @authentication Requires user context
48
54
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
55
+ # @example
56
+ # client.verify_credentials
49
57
  # @return [Twitter::User] The authenticated user.
50
58
  # @param options [Hash] A customizable set of options.
51
- # @option options [Boolean, String, Integer] :skip_status Do not include user's Tweets when set to true, 't' or 1.
59
+ # @option options [Boolean, String, Integer] :skip_status Do not include user's Tweets.
52
60
  def verify_credentials(options = {})
53
- perform_get_with_object("/1.1/account/verify_credentials.json", options, Twitter::User)
61
+ perform_get_with_object("/1.1/account/verify_credentials.json", options, User)
54
62
  end
55
63
 
56
64
  # Sets which device Twitter delivers updates to for the authenticating user
57
65
  #
66
+ # @api public
58
67
  # @see https://dev.twitter.com/rest/reference/post/account/update_delivery_device
59
68
  # @rate_limited No
60
69
  # @authentication Requires user context
61
70
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
71
+ # @example
72
+ # client.update_delivery_device('sms')
62
73
  # @return [Twitter::User] The authenticated user.
63
74
  # @param device [String] Must be one of: 'sms', 'none'.
64
75
  # @param options [Hash] A customizable set of options.
65
76
  def update_delivery_device(device, options = {})
66
- perform_post_with_object("/1.1/account/update_delivery_device.json", options.merge(device:), Twitter::User)
77
+ perform_post_with_object("/1.1/account/update_delivery_device.json", options.merge(device:), User)
67
78
  end
68
79
 
69
- # Sets values that users are able to set under the "Account" tab of their settings page
80
+ # Sets values that users can set in their profile settings
70
81
  #
82
+ # @api public
71
83
  # @see https://dev.twitter.com/rest/reference/post/account/update_profile
72
84
  # @note Only the options specified will be updated.
73
85
  # @rate_limited No
74
86
  # @authentication Requires user context
75
87
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
88
+ # @example
89
+ # client.update_profile(name: 'Erik Michaels-Ober')
76
90
  # @return [Twitter::User] The authenticated user.
77
91
  # @param options [Hash] A customizable set of options.
78
- # @option options [String] :name Full name associated with the profile. Maximum of 20 characters.
79
- # @option options [String] :url URL associated with the profile. Will be prepended with "http://" if not present. Maximum of 100 characters.
80
- # @option options [String] :location The city or country describing where the user of the account is located. The contents are not normalized or geocoded in any way. Maximum of 30 characters.
81
- # @option options [String] :description A description of the user owning the account. Maximum of 160 characters.
82
- # @option options [String] :profile_link_color A hex value of the color scheme used for links on user's profile page. Must be a valid hexadecimal value, and may be either three or six characters
92
+ # @option options [String] :name Full name associated with the profile.
93
+ # @option options [String] :url URL associated with the profile.
94
+ # @option options [String] :location The city or country describing the user's location.
95
+ # @option options [String] :description A description of the user.
96
+ # @option options [String] :profile_link_color A hex value for link color.
83
97
  def update_profile(options = {})
84
- perform_post_with_object("/1.1/account/update_profile.json", options, Twitter::User)
98
+ perform_post_with_object("/1.1/account/update_profile.json", options, User)
85
99
  end
86
100
 
87
101
  # Updates the authenticating user's profile background image
88
102
  #
103
+ # @api public
89
104
  # @see https://dev.twitter.com/rest/reference/post/account/update_profile_background_image
90
105
  # @rate_limited No
91
106
  # @authentication Requires user context
92
107
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
108
+ # @example
109
+ # client.update_profile_background_image(File.new('/path/to/image.png'))
93
110
  # @return [Twitter::User] The authenticated user.
94
- # @param image [File] The background image for the profile, base64-encoded. Must be a valid GIF, JPG, or PNG image of less than 800 kilobytes in size. Images with width larger than 2048 pixels will be forcibly scaled down. The image must be provided as raw multipart data, not a URL.
111
+ # @param image [File] The background image for the profile.
95
112
  # @param options [Hash] A customizable set of options.
96
- # @option options [Boolean] :tile Whether or not to tile the background image. If set to true the background image will be displayed tiled. The image will not be tiled otherwise.
113
+ # @option options [Boolean] :tile Whether or not to tile the background image.
97
114
  def update_profile_background_image(image, options = {})
98
115
  post_profile_image("/1.1/account/update_profile_background_image.json", image, options)
99
116
  end
100
117
 
101
118
  # Updates the authenticating user's profile image
102
119
  #
120
+ # @api public
103
121
  # @see https://dev.twitter.com/rest/reference/post/account/update_profile_image
104
- # @note Updates the authenticating user's profile image. Note that this method expects raw multipart data, not a URL to an image.
105
- # @note 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.
122
+ # @note This method expects raw multipart data, not a URL to an image.
106
123
  # @rate_limited No
107
124
  # @authentication Requires user context
108
125
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
126
+ # @example
127
+ # client.update_profile_image(File.new('/path/to/avatar.png'))
109
128
  # @return [Twitter::User] The authenticated user.
110
- # @param image [File] The avatar image for the profile, base64-encoded. Must be a valid GIF, JPG, or PNG image of less than 700 kilobytes in size. Images with width larger than 500 pixels will be scaled down. Animated GIFs will be converted to a static GIF of the first frame, removing the animation.
129
+ # @param image [File] The avatar image for the profile.
111
130
  # @param options [Hash] A customizable set of options.
112
131
  def update_profile_image(image, options = {})
113
132
  post_profile_image("/1.1/account/update_profile_image.json", image, options)
114
133
  end
115
134
 
116
- # Returns an array of user objects that the authenticating user is blocking
135
+ # Returns users that the authenticating user is blocking
117
136
  #
137
+ # @api public
118
138
  # @see https://dev.twitter.com/rest/reference/get/blocks/list
119
139
  # @rate_limited Yes
120
140
  # @authentication Requires user context
121
141
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
142
+ # @example
143
+ # client.blocked
122
144
  # @return [Array<Twitter::User>] User objects that the authenticating user is blocking.
123
145
  # @param options [Hash] A customizable set of options.
124
- # @option options [Boolean, String, Integer] :skip_status Do not include user's Tweets when set to true, 't' or 1.
146
+ # @option options [Boolean, String, Integer] :skip_status Do not include user's Tweets.
125
147
  def blocked(options = {})
126
- perform_get_with_cursor("/1.1/blocks/list.json", options, :users, Twitter::User)
148
+ perform_get_with_cursor("/1.1/blocks/list.json", options, :users, User)
127
149
  end
128
150
 
129
- # Returns an array of numeric user IDs the authenticating user is blocking
151
+ # Returns user IDs the authenticating user is blocking
130
152
  #
153
+ # @api public
131
154
  # @see https://dev.twitter.com/rest/reference/get/blocks/ids
132
155
  # @rate_limited Yes
133
156
  # @authentication Requires user context
134
157
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
158
+ # @example
159
+ # client.blocked_ids
135
160
  # @return [Twitter::Cursor] Numeric user IDs the authenticating user is blocking.
136
161
  # @overload blocked_ids(options = {})
137
162
  # @param options [Hash] A customizable set of options.
138
163
  def blocked_ids(*args)
139
- arguments = Twitter::Arguments.new(args)
164
+ arguments = Arguments.new(args)
140
165
  merge_user!(arguments.options, arguments.pop)
141
166
  perform_get_with_cursor("/1.1/blocks/ids.json", arguments.options, :ids)
142
167
  end
143
168
 
144
169
  # Returns true if the authenticating user is blocking a target user
145
170
  #
171
+ # @api public
146
172
  # @see https://dev.twitter.com/rest/reference/get/blocks/ids
147
173
  # @rate_limited Yes
148
174
  # @authentication Requires user context
149
175
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
150
- # @return [Boolean] true if the authenticating user is blocking the target user, otherwise false.
176
+ # @example
177
+ # client.block?('sferik')
178
+ # @return [Boolean] true if the authenticating user is blocking the target user.
151
179
  # @param user [Integer, String, URI, Twitter::User] A Twitter user ID, screen name, URI, or object.
152
180
  # @param options [Hash] A customizable set of options.
153
181
  def block?(user, options = {})
154
182
  user_id =
155
183
  case user
156
- when Integer then user
157
- when String, URI, Addressable::URI then user(user).id
158
- when Twitter::User then user.id
184
+ when Integer then user
185
+ when String, URI then user(user).id
186
+ when User then user.id
159
187
  end
160
188
  blocked_ids(options).collect(&:to_i).include?(user_id)
161
189
  end
162
190
 
163
191
  # Blocks the users specified by the authenticating user
164
192
  #
193
+ # @api public
165
194
  # @see https://dev.twitter.com/rest/reference/post/blocks/create
166
195
  # @note Destroys a friendship to the blocked user if it exists.
167
196
  # @rate_limited Yes
168
197
  # @authentication Requires user context
169
198
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
199
+ # @example
200
+ # client.block('sferik')
170
201
  # @return [Array<Twitter::User>] The blocked users.
171
202
  # @overload block(*users)
172
203
  # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
@@ -179,10 +210,13 @@ module Twitter
179
210
 
180
211
  # Un-blocks the users specified by the authenticating user
181
212
  #
213
+ # @api public
182
214
  # @see https://dev.twitter.com/rest/reference/post/blocks/destroy
183
215
  # @rate_limited No
184
216
  # @authentication Requires user context
185
217
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
218
+ # @example
219
+ # client.unblock('sferik')
186
220
  # @return [Array<Twitter::User>] The un-blocked users.
187
221
  # @overload unblock(*users)
188
222
  # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
@@ -195,10 +229,13 @@ module Twitter
195
229
 
196
230
  # Returns extended information for up to 100 users
197
231
  #
232
+ # @api public
198
233
  # @see https://dev.twitter.com/rest/reference/get/users/lookup
199
234
  # @rate_limited Yes
200
235
  # @authentication Required
201
236
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
237
+ # @example
238
+ # client.users('sferik', 'pengwynn')
202
239
  # @return [Array<Twitter::User>] The requested users.
203
240
  # @overload users(*users)
204
241
  # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
@@ -206,16 +243,21 @@ module Twitter
206
243
  # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
207
244
  # @param options [Hash] A customizable set of options.
208
245
  def users(*args)
209
- arguments = Twitter::Arguments.new(args)
246
+ arguments = Arguments.new(args)
210
247
  flat_pmap(arguments.each_slice(MAX_USERS_PER_REQUEST)) do |users|
211
- perform_get_with_objects("/1.1/users/lookup.json", merge_users(arguments.options, users), Twitter::User)
248
+ perform_get_with_objects("/1.1/users/lookup.json", merge_users(arguments.options, users), User)
212
249
  end
213
250
  end
214
251
 
252
+ # Returns extended information for a given user
253
+ #
254
+ # @api public
215
255
  # @see https://dev.twitter.com/rest/reference/get/users/show
216
256
  # @rate_limited Yes
217
257
  # @authentication Requires user context
218
258
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
259
+ # @example
260
+ # client.user('sferik')
219
261
  # @return [Twitter::User] The requested user.
220
262
  # @overload user(options = {})
221
263
  # Returns extended information for the authenticated user
@@ -229,10 +271,10 @@ module Twitter
229
271
  # @param options [Hash] A customizable set of options.
230
272
  # @option options [Boolean, String, Integer] :skip_status Do not include user's Tweets when set to true, 't' or 1.
231
273
  def user(*args)
232
- arguments = Twitter::Arguments.new(args)
274
+ arguments = Arguments.new(args)
233
275
  if arguments.last || user_id?
234
276
  merge_user!(arguments.options, arguments.pop || user_id)
235
- perform_get_with_object("/1.1/users/show.json", arguments.options, Twitter::User)
277
+ perform_get_with_object("/1.1/users/show.json", arguments.options, User)
236
278
  else
237
279
  verify_credentials(arguments.options)
238
280
  end
@@ -240,9 +282,12 @@ module Twitter
240
282
 
241
283
  # Returns true if the specified user exists
242
284
  #
285
+ # @api public
243
286
  # @rate_limited Yes
244
287
  # @authentication Requires user context
245
288
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
289
+ # @example
290
+ # client.user?('sferik')
246
291
  # @return [Boolean] true if the user exists, otherwise false.
247
292
  # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
248
293
  def user?(user, options = {})
@@ -256,26 +301,31 @@ module Twitter
256
301
 
257
302
  # Returns users that match the given query
258
303
  #
304
+ # @api public
259
305
  # @see https://dev.twitter.com/rest/reference/get/users/search
260
306
  # @rate_limited Yes
261
307
  # @authentication Requires user context
262
308
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
309
+ # @example
310
+ # client.user_search('Erik Michaels-Ober')
263
311
  # @return [Array<Twitter::User>]
264
312
  # @param query [String] The search query to run against people search.
265
313
  # @param options [Hash] A customizable set of options.
266
- # @option options [Integer] :count The number of people to retrieve. Maxiumum of 20 allowed per page.
314
+ # @option options [Integer] :count The number of people to retrieve.
267
315
  # @option options [Integer] :page Specifies the page of results to retrieve.
268
316
  def user_search(query, options = {})
269
- options = options.dup
270
- perform_get_with_objects("/1.1/users/search.json", options.merge(q: query), Twitter::User)
317
+ perform_get_with_objects("/1.1/users/search.json", options.merge(q: query), User)
271
318
  end
272
319
 
273
- # Returns an array of users that the specified user can contribute to
320
+ # Returns users that the specified user can contribute to
274
321
  #
322
+ # @api public
275
323
  # @see https://dev.twitter.com/rest/reference/get/users/contributees
276
324
  # @rate_limited Yes
277
325
  # @authentication Requires user context
278
326
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
327
+ # @example
328
+ # client.contributees
279
329
  # @return [Array<Twitter::User>]
280
330
  # @overload contributees(options = {})
281
331
  # @param options [Hash] A customizable set of options.
@@ -288,12 +338,15 @@ module Twitter
288
338
  users_from_response(:get, "/1.1/users/contributees.json", args)
289
339
  end
290
340
 
291
- # Returns an array of users who can contribute to the specified account
341
+ # Returns users who can contribute to the specified account
292
342
  #
343
+ # @api public
293
344
  # @see https://dev.twitter.com/rest/reference/get/users/contributors
294
345
  # @rate_limited Yes
295
346
  # @authentication Requires user context
296
347
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
348
+ # @example
349
+ # client.contributors
297
350
  # @return [Array<Twitter::User>]
298
351
  # @overload contributors(options = {})
299
352
  # @param options [Hash] A customizable set of options.
@@ -308,12 +361,16 @@ module Twitter
308
361
 
309
362
  # Removes the authenticating user's profile banner image
310
363
  #
364
+ # @api public
311
365
  # @see https://dev.twitter.com/rest/reference/post/account/remove_profile_banner
312
366
  # @rate_limited No
313
367
  # @authentication Requires user context
314
368
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
369
+ # @example
370
+ # client.remove_profile_banner
315
371
  # @return [nil]
316
372
  # @param options [Hash] A customizable set of options.
373
+ # rubocop:disable Naming/PredicateMethod
317
374
  def remove_profile_banner(options = {})
318
375
  perform_post("/1.1/account/remove_profile_banner.json", options)
319
376
  true
@@ -321,49 +378,58 @@ module Twitter
321
378
 
322
379
  # Updates the authenticating user's profile banner image
323
380
  #
381
+ # @api public
324
382
  # @see https://dev.twitter.com/rest/reference/post/account/update_profile_banner
325
- # @note 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.
326
- # @note Profile banner images are processed asynchronously. The profile_banner_url and its variant sizes will not necessary be available directly after upload.
383
+ # @note For best results, upload an image that is exactly 1252px by 626px.
327
384
  # @rate_limited No
328
385
  # @authentication Requires user context
329
- # @raise [Twitter::Error::BadRequest] Error raised when either an image was not provided or the image data could not be processed.
386
+ # @raise [Twitter::Error::BadRequest] Error raised when image was not provided.
330
387
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
331
- # @raise [Twitter::Error::UnprocessableEntity] Error raised when the image could not be resized or is too large.
388
+ # @raise [Twitter::Error::UnprocessableEntity] Error raised when image is too large.
389
+ # @example
390
+ # client.update_profile_banner(File.new('/path/to/banner.png'))
332
391
  # @return [nil]
333
- # @param banner [File] The Base64-encoded or raw image data being uploaded as the user's new profile banner.
392
+ # @param banner [File] The image data being uploaded as the profile banner.
334
393
  # @param options [Hash] A customizable set of options.
335
- # @option options [Integer] :width The width of the preferred section of the image being uploaded in pixels. Use with height, offset_left, and offset_top to select the desired region of the image to use.
336
- # @option options [Integer] :height The height of the preferred section of the image being uploaded in pixels. Use with width, offset_left, and offset_top to select the desired region of the image to use.
337
- # @option options [Integer] :offset_left The number of pixels by which to offset the uploaded image from the left. Use with height, width, and offset_top to select the desired region of the image to use.
338
- # @option options [Integer] :offset_top The number of pixels by which to offset the uploaded image from the top. Use with height, width, and offset_left to select the desired region of the image to use.
394
+ # @option options [Integer] :width The width of the preferred section.
395
+ # @option options [Integer] :height The height of the preferred section.
396
+ # @option options [Integer] :offset_left The offset from the left.
397
+ # @option options [Integer] :offset_top The offset from the top.
339
398
  def update_profile_banner(banner, options = {})
340
399
  perform_post("/1.1/account/update_profile_banner.json", options.merge(banner:))
341
400
  true
342
401
  end
402
+ # rubocop:enable Naming/PredicateMethod
343
403
 
344
- # Returns the available size variations of the specified user's profile banner.
404
+ # Returns the profile banner size variations for a user
345
405
  #
406
+ # @api public
346
407
  # @see https://dev.twitter.com/rest/reference/get/users/profile_banner
347
- # @note If the user has not uploaded a profile banner, a HTTP 404 will be served instead.
408
+ # @note If the user has not uploaded a profile banner, a HTTP 404 is served.
348
409
  # @rate_limited Yes
349
410
  # @authentication Requires user context
350
411
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
412
+ # @example
413
+ # client.profile_banner('sferik')
351
414
  # @return [Twitter::ProfileBanner]
352
415
  # @overload profile_banner(options = {})
353
416
  # @overload profile_banner(user, options = {})
354
417
  # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
355
418
  def profile_banner(*args)
356
- arguments = Twitter::Arguments.new(args)
357
- merge_user!(arguments.options, arguments.pop || user_id) unless arguments.options[:user_id] || arguments.options[:screen_name]
358
- perform_get_with_object("/1.1/users/profile_banner.json", arguments.options, Twitter::ProfileBanner)
419
+ arguments = Arguments.new(args)
420
+ merge_user!(arguments.options, arguments.pop || user_id) unless arguments.options.key?(:user_id) || arguments.options.key?(:screen_name)
421
+ perform_get_with_object("/1.1/users/profile_banner.json", arguments.options, ProfileBanner)
359
422
  end
360
423
 
361
424
  # Mutes the users specified by the authenticating user
362
425
  #
426
+ # @api public
363
427
  # @see https://dev.twitter.com/rest/reference/post/mutes/users/create
364
428
  # @rate_limited Yes
365
429
  # @authentication Requires user context
366
430
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
431
+ # @example
432
+ # client.mute('sferik')
367
433
  # @return [Array<Twitter::User>] The muted users.
368
434
  # @overload mute(*users)
369
435
  # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
@@ -374,12 +440,15 @@ module Twitter
374
440
  parallel_users_from_response(:post, "/1.1/mutes/users/create.json", args)
375
441
  end
376
442
 
377
- # Un-mutes the user specified by the authenticating user.
443
+ # Un-mutes the user specified by the authenticating user
378
444
  #
445
+ # @api public
379
446
  # @see https://dev.twitter.com/rest/reference/post/mutes/users/destroy
380
447
  # @rate_limited Yes
381
448
  # @authentication Requires user context
382
449
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
450
+ # @example
451
+ # client.unmute('sferik')
383
452
  # @return [Array<Twitter::User>] The un-muted users.
384
453
  # @overload unmute(*users)
385
454
  # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
@@ -390,39 +459,49 @@ module Twitter
390
459
  parallel_users_from_response(:post, "/1.1/mutes/users/destroy.json", args)
391
460
  end
392
461
 
393
- # Returns an array of user objects that the authenticating user is muting
462
+ # Returns users that the authenticating user is muting
394
463
  #
464
+ # @api public
395
465
  # @see https://dev.twitter.com/rest/reference/get/mutes/users/list
396
466
  # @rate_limited Yes
397
467
  # @authentication Requires user context
398
468
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
469
+ # @example
470
+ # client.muted
399
471
  # @return [Array<Twitter::User>] User objects that the authenticating user is muting.
400
472
  # @param options [Hash] A customizable set of options.
401
- # @option options [Boolean, String, Integer] :skip_status Do not include user's Tweets when set to true, 't' or 1.
473
+ # @option options [Boolean, String, Integer] :skip_status Do not include user's Tweets.
402
474
  def muted(options = {})
403
- perform_get_with_cursor("/1.1/mutes/users/list.json", options, :users, Twitter::User)
475
+ perform_get_with_cursor("/1.1/mutes/users/list.json", options, :users, User)
404
476
  end
405
477
 
406
- # Returns an array of numeric user IDs the authenticating user is muting
478
+ # Returns user IDs the authenticating user is muting
407
479
  #
480
+ # @api public
408
481
  # @see https://dev.twitter.com/rest/reference/get/mutes/users/ids
409
482
  # @rate_limited Yes
410
483
  # @authentication Requires user context
411
484
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
485
+ # @example
486
+ # client.muted_ids
412
487
  # @return [Twitter::Cursor] Numeric user IDs the authenticating user is muting
413
488
  # @overload muted_ids(options = {})
414
489
  # @param options [Hash] A customizable set of options.
415
490
  def muted_ids(*args)
416
- arguments = Twitter::Arguments.new(args)
491
+ arguments = Arguments.new(args)
417
492
  merge_user!(arguments.options, arguments.pop)
418
493
  perform_get_with_cursor("/1.1/mutes/users/ids.json", arguments.options, :ids)
419
494
  end
420
495
 
421
- private
496
+ private
422
497
 
498
+ # Posts a profile image update
499
+ #
500
+ # @api private
501
+ # @return [Twitter::User]
423
502
  def post_profile_image(path, image, options)
424
- response = Twitter::REST::Request.new(self, :multipart_post, path, options.merge(key: :image, file: image)).perform
425
- Twitter::User.new(response)
503
+ response = Request.new(self, :multipart_post, path, options.merge(key: :image, file: image)).perform
504
+ User.new(response)
426
505
  end
427
506
  end
428
507
  end