twitter 8.2.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 +172 -10
  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 +23 -57
  97. data/.yardopts +0 -16
  98. data/CHANGELOG.md +0 -1040
  99. data/CONTRIBUTING.md +0 -49
  100. data/twitter.gemspec +0 -40
@@ -1,6 +1,6 @@
1
- require "addressable/uri"
2
1
  require "twitter/arguments"
3
2
  require "twitter/cursor"
3
+ require "twitter/identity"
4
4
  require "twitter/rest/request"
5
5
  require "twitter/user"
6
6
  require "twitter/utils"
@@ -8,99 +8,145 @@ require "uri"
8
8
 
9
9
  module Twitter
10
10
  module REST
11
+ # Utility methods for Twitter REST API requests
11
12
  module Utils
12
13
  include Twitter::Utils
14
+
15
+ # The default cursor position for paginated requests
13
16
  DEFAULT_CURSOR = -1
14
17
 
15
- private
18
+ private
16
19
 
17
20
  # Take a URI string or Twitter::Identity object and return its ID
18
21
  #
19
- # @param object [Integer, String, URI, Twitter::Identity] An ID, URI, or object.
22
+ # @api private
23
+ # @param object [Integer, String, URI, Twitter::Identity] An ID, URI, or object
20
24
  # @return [Integer]
21
25
  def extract_id(object)
22
26
  case object
23
- when ::Integer
27
+ when Integer
24
28
  object
25
- when ::String
26
- object.split("/").last.to_i
27
- when URI, Addressable::URI
28
- object.path.split("/").last.to_i
29
- when Twitter::Identity
29
+ when String
30
+ Integer(object.split("/").last)
31
+ when URI
32
+ Integer(object.path.split("/").last) # steep:ignore NoMethod
33
+ when Identity
30
34
  object.id
31
35
  end
32
36
  end
33
37
 
38
+ # Perform a GET request
39
+ #
40
+ # @api private
34
41
  # @param path [String]
35
42
  # @param options [Hash]
43
+ # @return [Hash, Array]
36
44
  def perform_get(path, options = {})
37
45
  perform_request(:get, path, options)
38
46
  end
39
47
 
48
+ # Perform a POST request
49
+ #
50
+ # @api private
40
51
  # @param path [String]
41
52
  # @param options [Hash]
53
+ # @return [Hash, Array]
42
54
  def perform_post(path, options = {})
43
55
  perform_request(:post, path, options)
44
56
  end
45
57
 
58
+ # Perform an HTTP request
59
+ #
60
+ # @api private
46
61
  # @param request_method [Symbol]
47
62
  # @param path [String]
48
63
  # @param options [Hash]
64
+ # @param params [Hash]
65
+ # @return [Hash, Array]
49
66
  def perform_request(request_method, path, options = {}, params = nil)
50
- Twitter::REST::Request.new(self, request_method, path, options, params).perform
67
+ Request.new(self, request_method, path, options, params).perform
51
68
  end
52
69
 
70
+ # Perform a GET request and return an object
71
+ #
72
+ # @api private
53
73
  # @param path [String]
54
74
  # @param options [Hash]
55
75
  # @param klass [Class]
76
+ # @return [Object]
56
77
  def perform_get_with_object(path, options, klass)
57
78
  perform_request_with_object(:get, path, options, klass)
58
79
  end
59
80
 
81
+ # Perform a POST request and return an object
82
+ #
83
+ # @api private
60
84
  # @param path [String]
61
85
  # @param options [Hash]
62
86
  # @param klass [Class]
87
+ # @return [Object]
63
88
  def perform_post_with_object(path, options, klass)
64
89
  perform_request_with_object(:post, path, options, klass)
65
90
  end
66
91
 
92
+ # Perform a request and return an object
93
+ #
94
+ # @api private
67
95
  # @param request_method [Symbol]
68
96
  # @param path [String]
69
97
  # @param options [Hash]
70
98
  # @param klass [Class]
99
+ # @param params [Hash]
100
+ # @return [Object]
71
101
  def perform_request_with_object(request_method, path, options, klass, params = nil)
72
102
  response = perform_request(request_method, path, options, params)
73
- klass.new(response)
103
+ klass.new(response) # steep:ignore UnexpectedPositionalArgument
74
104
  end
75
105
 
106
+ # Perform a GET request and return objects
107
+ #
108
+ # @api private
76
109
  # @param path [String]
77
110
  # @param options [Hash]
78
111
  # @param klass [Class]
112
+ # @return [Array]
79
113
  def perform_get_with_objects(path, options, klass)
80
114
  perform_request_with_objects(:get, path, options, klass)
81
115
  end
82
116
 
117
+ # Perform a POST request and return objects
118
+ #
119
+ # @api private
83
120
  # @param path [String]
84
121
  # @param options [Hash]
85
122
  # @param klass [Class]
123
+ # @return [Array]
86
124
  def perform_post_with_objects(path, options, klass)
87
125
  perform_request_with_objects(:post, path, options, klass)
88
126
  end
89
127
 
128
+ # Perform a request and return objects
129
+ #
130
+ # @api private
90
131
  # @param request_method [Symbol]
91
132
  # @param path [String]
92
133
  # @param options [Hash]
93
134
  # @param klass [Class]
135
+ # @return [Array]
94
136
  def perform_request_with_objects(request_method, path, options, klass)
95
137
  perform_request(request_method, path, options).collect do |element|
96
- klass.new(element)
138
+ klass.new(element) # steep:ignore UnexpectedPositionalArgument
97
139
  end
98
140
  end
99
141
 
142
+ # Perform a GET request with cursor pagination
143
+ #
144
+ # @api private
100
145
  # @param path [String]
101
146
  # @param options [Hash]
102
147
  # @param collection_name [Symbol]
103
148
  # @param klass [Class]
149
+ # @return [Twitter::Cursor]
104
150
  def perform_get_with_cursor(path, options, collection_name, klass = nil)
105
151
  limit = options.delete(:limit)
106
152
  if options[:no_default_cursor]
@@ -109,58 +155,73 @@ module Twitter
109
155
  merge_default_cursor!(options)
110
156
  end
111
157
 
112
- request = Twitter::REST::Request.new(self, :get, path, options)
113
- Twitter::Cursor.new(collection_name.to_sym, klass, request, limit)
158
+ request = Request.new(self, :get, path, options)
159
+ Cursor.new(collection_name, klass, request, limit)
114
160
  end
115
161
 
162
+ # Perform parallel user requests
163
+ #
164
+ # @api private
116
165
  # @param request_method [Symbol]
117
166
  # @param path [String]
118
167
  # @param args [Array]
119
168
  # @return [Array<Twitter::User>]
120
169
  def parallel_users_from_response(request_method, path, args)
121
- arguments = Twitter::Arguments.new(args)
170
+ arguments = Arguments.new(args)
122
171
  pmap(arguments) do |user|
123
- perform_request_with_object(request_method, path, merge_user(arguments.options, user), Twitter::User)
172
+ perform_request_with_object(request_method, path, merge_user(arguments.options, user), User) # steep:ignore ArgumentTypeMismatch
124
173
  end
125
174
  end
126
175
 
176
+ # Get users from response
177
+ #
178
+ # @api private
127
179
  # @param request_method [Symbol]
128
180
  # @param path [String]
129
181
  # @param args [Array]
130
182
  # @return [Array<Twitter::User>]
131
183
  def users_from_response(request_method, path, args)
132
- arguments = Twitter::Arguments.new(args)
133
- merge_user!(arguments.options, arguments.pop || user_id) unless arguments.options[:user_id] || arguments.options[:screen_name]
134
- perform_request_with_objects(request_method, path, arguments.options, Twitter::User)
184
+ arguments = Arguments.new(args)
185
+ merge_user!(arguments.options, arguments.pop || user_id) unless arguments.options.key?(:user_id) || arguments.options.key?(:screen_name)
186
+ perform_request_with_objects(request_method, path, arguments.options, User)
135
187
  end
136
188
 
189
+ # Get objects from response with user
190
+ #
191
+ # @api private
137
192
  # @param klass [Class]
138
193
  # @param request_method [Symbol]
139
194
  # @param path [String]
140
195
  # @param args [Array]
141
196
  # @return [Array]
142
197
  def objects_from_response_with_user(klass, request_method, path, args)
143
- arguments = Twitter::Arguments.new(args)
198
+ arguments = Arguments.new(args)
144
199
  merge_user!(arguments.options, arguments.pop)
145
200
  perform_request_with_objects(request_method, path, arguments.options, klass)
146
201
  end
147
202
 
203
+ # Perform parallel object requests
204
+ #
205
+ # @api private
148
206
  # @param klass [Class]
149
207
  # @param request_method [Symbol]
150
208
  # @param path [String]
151
209
  # @param args [Array]
152
210
  # @return [Array]
153
211
  def parallel_objects_from_response(klass, request_method, path, args)
154
- arguments = Twitter::Arguments.new(args)
212
+ arguments = Arguments.new(args)
155
213
  pmap(arguments) do |object|
156
214
  perform_request_with_object(request_method, path, arguments.options.merge(id: extract_id(object)), klass)
157
215
  end
158
216
  end
159
217
 
218
+ # Perform multiple requests for IDs
219
+ #
220
+ # @api private
160
221
  # @param request_method [Symbol]
161
222
  # @param path [String]
162
223
  # @param ids [Array]
163
- # @return nil
224
+ # @return [nil]
164
225
  def perform_requests(request_method, path, ids)
165
226
  ids.each do |id|
166
227
  perform_request(request_method, path, id:)
@@ -168,33 +229,51 @@ module Twitter
168
229
  nil
169
230
  end
170
231
 
232
+ # Get cursor from response with user
233
+ #
234
+ # @api private
171
235
  # @param collection_name [Symbol]
172
236
  # @param klass [Class]
173
237
  # @param path [String]
174
238
  # @param args [Array]
175
239
  # @return [Twitter::Cursor]
176
240
  def cursor_from_response_with_user(collection_name, klass, path, args)
177
- arguments = Twitter::Arguments.new(args)
178
- merge_user!(arguments.options, arguments.pop || user_id) unless arguments.options[:user_id] || arguments.options[:screen_name]
241
+ arguments = Arguments.new(args)
242
+ merge_user!(arguments.options, arguments.pop || user_id) unless arguments.options.key?(:user_id) || arguments.options.key?(:screen_name)
179
243
  perform_get_with_cursor(path, arguments.options, collection_name, klass)
180
244
  end
181
245
 
246
+ # Get the current user's ID
247
+ #
248
+ # @api private
249
+ # @return [Integer]
182
250
  def user_id
183
- @user_id ||= verify_credentials(skip_status: true).id
251
+ @user_id ||= verify_credentials(skip_status: true).id # steep:ignore NoMethod,UnknownInstanceVariable
184
252
  end
185
253
 
254
+ # Check if user_id is set
255
+ #
256
+ # @api private
257
+ # @return [Boolean]
186
258
  def user_id?
187
259
  instance_variable_defined?(:@user_id)
188
260
  end
189
261
 
262
+ # Merge default cursor into options
263
+ #
264
+ # @api private
265
+ # @param options [Hash]
266
+ # @return [void]
190
267
  def merge_default_cursor!(options)
191
268
  options[:cursor] = DEFAULT_CURSOR unless options[:cursor]
192
269
  end
193
270
 
194
271
  # Take a user and merge it into the hash with the correct key
195
272
  #
273
+ # @api private
196
274
  # @param hash [Hash]
197
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
275
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object
276
+ # @param prefix [String]
198
277
  # @return [Hash]
199
278
  def merge_user(hash, user, prefix = nil)
200
279
  merge_user!(hash.dup, user, prefix)
@@ -202,8 +281,10 @@ module Twitter
202
281
 
203
282
  # Take a user and merge it into the hash with the correct key
204
283
  #
284
+ # @api private
205
285
  # @param hash [Hash]
206
- # @param user [Integer, String, URI, Twitter::User] A Twitter user ID, screen name, URI, or object.
286
+ # @param user [Integer, String, URI, Twitter::User] A Twitter user ID, screen name, URI, or object
287
+ # @param prefix [String]
207
288
  # @return [Hash]
208
289
  def merge_user!(hash, user, prefix = nil)
209
290
  case user
@@ -211,13 +292,21 @@ module Twitter
211
292
  set_compound_key("user_id", user, hash, prefix)
212
293
  when String
213
294
  set_compound_key("screen_name", user, hash, prefix)
214
- when URI, Addressable::URI
215
- set_compound_key("screen_name", user.path.split("/").last, hash, prefix)
216
- when Twitter::User
295
+ when URI
296
+ set_compound_key("screen_name", user.path.split("/").last, hash, prefix) # steep:ignore NoMethod
297
+ when User
217
298
  set_compound_key("user_id", user.id, hash, prefix)
218
299
  end
219
300
  end
220
301
 
302
+ # Set a compound key in a hash
303
+ #
304
+ # @api private
305
+ # @param key [String]
306
+ # @param value [Object]
307
+ # @param hash [Hash]
308
+ # @param prefix [String]
309
+ # @return [Hash]
221
310
  def set_compound_key(key, value, hash, prefix = nil)
222
311
  compound_key = [prefix, key].compact.join("_").to_sym
223
312
  hash[compound_key] = value
@@ -226,8 +315,9 @@ module Twitter
226
315
 
227
316
  # Take a multiple users and merge them into the hash with the correct keys
228
317
  #
318
+ # @api private
229
319
  # @param hash [Hash]
230
- # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen_names, or objects.
320
+ # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen_names, or objects
231
321
  # @return [Hash]
232
322
  def merge_users(hash, users)
233
323
  copy = hash.dup
@@ -237,24 +327,30 @@ module Twitter
237
327
 
238
328
  # Take a multiple users and merge them into the hash with the correct keys
239
329
  #
330
+ # @api private
240
331
  # @param hash [Hash]
241
- # @param users [Enumerable<Integer, String, URI, Twitter::User>] A collection of Twitter user IDs, screen_names, URIs, or objects.
242
- # @return [Hash]
332
+ # @param users [Enumerable<Integer, String, URI, Twitter::User>] A collection of Twitter user IDs, screen_names, URIs, or objects
333
+ # @return [void]
243
334
  def merge_users!(hash, users)
244
335
  user_ids, screen_names = collect_users(users.uniq)
245
336
  hash[:user_id] = user_ids.join(",") unless user_ids.empty?
246
337
  hash[:screen_name] = screen_names.join(",") unless screen_names.empty?
247
338
  end
248
339
 
340
+ # Collect users into user_ids and screen_names arrays
341
+ #
342
+ # @api private
343
+ # @param users [Enumerable]
344
+ # @return [Array<Array, Array>]
249
345
  def collect_users(users) # rubocop:disable Metrics/MethodLength
250
- user_ids = []
251
- screen_names = []
346
+ user_ids = [] # : Array[Integer]
347
+ screen_names = [] # : Array[String]
252
348
  users.each do |user|
253
349
  case user
254
- when Integer then user_ids << user
255
- when Twitter::User then user_ids << user.id
256
- when String then screen_names << user
257
- when URI, Addressable::URI then screen_names << user.path.split("/").last
350
+ when Integer then user_ids << user
351
+ when User then user_ids << user.id
352
+ when String then screen_names << user
353
+ when URI then screen_names << user.path.split("/").last # steep:ignore NoMethod
258
354
  end
259
355
  end
260
356
  [user_ids, screen_names]
@@ -2,8 +2,29 @@ require "twitter/creatable"
2
2
  require "twitter/identity"
3
3
 
4
4
  module Twitter
5
- class SavedSearch < Twitter::Identity
6
- include Twitter::Creatable
5
+ # Represents a saved search
6
+ class SavedSearch < Identity
7
+ include Creatable
8
+
9
+ # The name of the saved search
10
+ #
11
+ # @api public
12
+ # @example
13
+ # saved_search.name
14
+ # @return [String]
15
+
16
+ # The position of the saved search
17
+ #
18
+ # @api public
19
+ # @example
20
+ # saved_search.position
21
+ # @return [String]
22
+
23
+ # The query of the saved search
24
+ #
25
+ # @api public
26
+ # @example
27
+ # saved_search.query
7
28
  # @return [String]
8
29
  attr_reader :name, :position, :query
9
30
  end
@@ -5,17 +5,48 @@ require "twitter/utils"
5
5
  require "uri"
6
6
 
7
7
  module Twitter
8
+ # Represents search results from Twitter
8
9
  class SearchResults
9
- include Twitter::Enumerable
10
- include Twitter::Utils
10
+ include Enumerable
11
+ include Utils
12
+
13
+ # The raw attributes hash
14
+ #
15
+ # @api public
16
+ # @example
17
+ # results.attrs
11
18
  # @return [Hash]
19
+
20
+ # The rate limit information from the response
21
+ #
22
+ # @api public
23
+ # @example
24
+ # results.rate_limit
25
+ # @return [Twitter::RateLimit]
12
26
  attr_reader :attrs, :rate_limit
13
- alias to_h attrs
14
- alias to_hash to_h
27
+
28
+ # @!method to_h
29
+ # Returns the attributes as a hash
30
+ # @api public
31
+ # @example
32
+ # results.to_h
33
+ # @return [Hash]
34
+ alias_method :to_h, :attrs
35
+
36
+ # @!method to_hash
37
+ # Returns the attributes as a hash
38
+ # @api public
39
+ # @example
40
+ # results.to_hash
41
+ # @return [Hash]
42
+ alias_method :to_hash, :to_h
15
43
 
16
44
  # Initializes a new SearchResults object
17
45
  #
18
- # @param request [Twitter::REST::Request]
46
+ # @api public
47
+ # @example
48
+ # Twitter::SearchResults.new(request)
49
+ # @param request [Twitter::REST::Request] The request object
19
50
  # @return [Twitter::SearchResults]
20
51
  def initialize(request)
21
52
  @client = request.client
@@ -26,51 +57,65 @@ module Twitter
26
57
  self.attrs = request.perform
27
58
  end
28
59
 
29
- private
60
+ private
30
61
 
62
+ # Returns true if this is the last page of results
63
+ #
64
+ # @api private
31
65
  # @return [Boolean]
32
66
  def last?
33
67
  !next_page?
34
68
  end
35
69
 
70
+ # Returns true if there is a next page
71
+ #
72
+ # @api private
36
73
  # @return [Boolean]
37
74
  def next_page?
38
75
  !!@attrs[:search_metadata][:next_results] unless @attrs[:search_metadata].nil?
39
76
  end
40
77
 
41
- # Returns a Hash of query parameters for the next result in the search
78
+ # Returns query parameters for the next page
42
79
  #
43
- # @note Returned Hash can be merged into the previous search options list to easily access the next page.
44
- # @return [Hash] The parameters needed to fetch the next page.
80
+ # @api private
81
+ # @note Returned Hash can be merged into previous search options
82
+ # @return [Hash]
45
83
  def next_page
46
84
  query_string_to_hash(@attrs[:search_metadata][:next_results]) if next_page?
47
85
  end
48
86
 
87
+ # Fetches the next page of results
88
+ #
89
+ # @api private
49
90
  # @return [Hash]
50
91
  def fetch_next_page
51
- response = Twitter::REST::Request.new(@client, @request_method, @path, @options.merge(next_page))
92
+ response = REST::Request.new(@client, @request_method, @path, @options.merge(next_page)) # steep:ignore ArgumentTypeMismatch
52
93
  self.attrs = response.perform
53
94
  @rate_limit = response.rate_limit
54
95
  end
55
96
 
56
- # @param attrs [Hash]
97
+ # Sets the attributes and populates the collection
98
+ #
99
+ # @api private
100
+ # @param attrs [Hash] The attributes hash
57
101
  # @return [Hash]
58
102
  def attrs=(attrs)
59
103
  @attrs = attrs
60
104
  @attrs.fetch(:statuses, []).collect do |tweet|
61
105
  @collection << Tweet.new(tweet)
62
106
  end
63
- @attrs
64
107
  end
65
108
 
66
109
  # Converts query string to a hash
67
110
  #
68
- # @param query_string [String] The query string of a URL.
69
- # @return [Hash] The query string converted to a hash (with symbol keys).
70
- # @example Convert query string to a hash
71
- # query_string_to_hash("foo=bar&baz=qux") #=> {:foo=>"bar", :baz=>"qux"}
111
+ # @api private
112
+ # @param query_string [String] The query string of a URL
113
+ # @return [Hash]
72
114
  def query_string_to_hash(query_string)
73
- query = CGI.parse(URI.parse(query_string).query)
115
+ parsed_query = URI.parse(query_string).query
116
+ return {} if parsed_query.nil?
117
+
118
+ query = CGI.parse(parsed_query)
74
119
  query.to_h { |key, value| [key.to_sym, value.first] }
75
120
  end
76
121
  end
@@ -1,23 +1,49 @@
1
1
  require "twitter/base"
2
2
 
3
3
  module Twitter
4
- class Settings < Twitter::Base
4
+ # Represents Twitter account settings
5
+ class Settings < Base
6
+ # The sleep time settings
7
+ #
8
+ # @api public
9
+ # @example
10
+ # settings.sleep_time
11
+ # @return [Hash]
12
+
13
+ # The time zone settings
14
+ #
15
+ # @api public
16
+ # @example
17
+ # settings.time_zone
5
18
  # @return [Hash]
6
19
  attr_reader :sleep_time, :time_zone
20
+
21
+ # The language preference
22
+ #
23
+ # @api public
24
+ # @example
25
+ # settings.language
26
+ # @return [String]
27
+
28
+ # The screen name of the account
29
+ #
30
+ # @api public
31
+ # @example
32
+ # settings.screen_name
7
33
  # @return [String]
8
34
  attr_reader :language, :screen_name
9
35
 
10
36
  object_attr_reader :Place, :trend_location
11
37
  predicate_attr_reader :allow_contributor_request,
12
- :allow_dm_groups_from,
13
- :allow_dms_from,
14
- :always_use_https,
15
- :discoverable_by_email,
16
- :discoverable_by_mobile_phone,
17
- :display_sensitive_media,
18
- :geo_enabled,
19
- :protected,
20
- :show_all_inline_media,
21
- :use_cookie_personalization
38
+ :allow_dm_groups_from,
39
+ :allow_dms_from,
40
+ :always_use_https,
41
+ :discoverable_by_email,
42
+ :discoverable_by_mobile_phone,
43
+ :display_sensitive_media,
44
+ :geo_enabled,
45
+ :protected,
46
+ :show_all_inline_media,
47
+ :use_cookie_personalization
22
48
  end
23
49
  end
data/lib/twitter/size.rb CHANGED
@@ -2,13 +2,47 @@ require "equalizer"
2
2
  require "twitter/base"
3
3
 
4
4
  module Twitter
5
- class Size < Twitter::Base
5
+ # Represents a size for media objects
6
+ class Size < Base
6
7
  include Equalizer.new(:h, :w)
8
+
9
+ # The height in pixels
10
+ #
11
+ # @api public
12
+ # @example
13
+ # size.h
14
+ # @return [Integer]
15
+
16
+ # The width in pixels
17
+ #
18
+ # @api public
19
+ # @example
20
+ # size.w
7
21
  # @return [Integer]
8
22
  attr_reader :h, :w
23
+
24
+ # The resize method used
25
+ #
26
+ # @api public
27
+ # @example
28
+ # size.resize
9
29
  # @return [String]
10
30
  attr_reader :resize
11
- alias height h
12
- alias width w
31
+
32
+ # @!method height
33
+ # The height in pixels
34
+ # @api public
35
+ # @example
36
+ # size.height
37
+ # @return [Integer]
38
+ alias_method :height, :h
39
+
40
+ # @!method width
41
+ # The width in pixels
42
+ # @api public
43
+ # @example
44
+ # size.width
45
+ # @return [Integer]
46
+ alias_method :width, :w
13
47
  end
14
48
  end
@@ -1,9 +1,10 @@
1
1
  require "twitter/basic_user"
2
2
 
3
3
  module Twitter
4
- class SourceUser < Twitter::BasicUser
4
+ # Represents the source user in a relationship
5
+ class SourceUser < BasicUser
5
6
  predicate_attr_reader :all_replies, :blocking, :can_dm, :followed_by,
6
- :marked_spam, :muting, :notifications_enabled,
7
- :want_retweets
7
+ :marked_spam, :muting, :notifications_enabled,
8
+ :want_retweets
8
9
  end
9
10
  end