twitter 5.0.0 → 5.4.1

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 (145) hide show
  1. data/.yardopts +4 -0
  2. data/CHANGELOG.md +47 -0
  3. data/CONTRIBUTING.md +5 -5
  4. data/README.md +57 -56
  5. data/Rakefile +26 -5
  6. data/lib/twitter/arguments.rb +1 -2
  7. data/lib/twitter/base.rb +15 -18
  8. data/lib/twitter/basic_user.rb +3 -3
  9. data/lib/twitter/client.rb +9 -10
  10. data/lib/twitter/configuration.rb +5 -5
  11. data/lib/twitter/creatable.rb +0 -1
  12. data/lib/twitter/cursor.rb +9 -36
  13. data/lib/twitter/direct_message.rb +1 -1
  14. data/lib/twitter/entity/uri.rb +2 -2
  15. data/lib/twitter/enumerable.rb +10 -1
  16. data/lib/twitter/error/already_favorited.rb +1 -1
  17. data/lib/twitter/error/already_posted.rb +1 -1
  18. data/lib/twitter/error/already_retweeted.rb +1 -1
  19. data/lib/twitter/error/too_many_requests.rb +2 -2
  20. data/lib/twitter/error.rb +6 -6
  21. data/lib/twitter/factory.rb +2 -6
  22. data/lib/twitter/geo/point.rb +3 -5
  23. data/lib/twitter/geo.rb +1 -1
  24. data/lib/twitter/geo_factory.rb +1 -5
  25. data/lib/twitter/geo_results.rb +5 -8
  26. data/lib/twitter/identity.rb +1 -2
  27. data/lib/twitter/list.rb +10 -11
  28. data/lib/twitter/media/photo.rb +1 -2
  29. data/lib/twitter/media_factory.rb +1 -5
  30. data/lib/twitter/null_object.rb +4 -6
  31. data/lib/twitter/oembed.rb +1 -1
  32. data/lib/twitter/place.rb +17 -6
  33. data/lib/twitter/profile_banner.rb +1 -3
  34. data/lib/twitter/rate_limit.rb +1 -3
  35. data/lib/twitter/relationship.rb +1 -2
  36. data/lib/twitter/rest/api/direct_messages.rb +15 -15
  37. data/lib/twitter/rest/api/favorites.rb +15 -15
  38. data/lib/twitter/rest/api/friends_and_followers.rb +37 -42
  39. data/lib/twitter/rest/api/help.rb +8 -9
  40. data/lib/twitter/rest/api/lists.rb +69 -69
  41. data/lib/twitter/rest/api/oauth.rb +3 -4
  42. data/lib/twitter/rest/api/places_and_geo.rb +9 -10
  43. data/lib/twitter/rest/api/saved_searches.rb +8 -8
  44. data/lib/twitter/rest/api/search.rb +10 -2
  45. data/lib/twitter/rest/api/spam_reporting.rb +1 -2
  46. data/lib/twitter/rest/api/suggested_users.rb +4 -5
  47. data/lib/twitter/rest/api/timelines.rb +17 -18
  48. data/lib/twitter/rest/api/trends.rb +10 -11
  49. data/lib/twitter/rest/api/tweets.rb +31 -20
  50. data/lib/twitter/rest/api/undocumented.rb +6 -7
  51. data/lib/twitter/rest/api/users.rb +53 -54
  52. data/lib/twitter/rest/api/utils.rb +28 -34
  53. data/lib/twitter/rest/client.rb +8 -9
  54. data/lib/twitter/rest/request/multipart_with_file.rb +7 -5
  55. data/lib/twitter/rest/response/parse_error_json.rb +0 -2
  56. data/lib/twitter/rest/response/parse_json.rb +2 -2
  57. data/lib/twitter/rest/response/raise_error.rb +1 -3
  58. data/lib/twitter/search_results.rb +38 -56
  59. data/lib/twitter/settings.rb +2 -2
  60. data/lib/twitter/size.rb +2 -2
  61. data/lib/twitter/source_user.rb +1 -1
  62. data/lib/twitter/streaming/client.rb +69 -18
  63. data/lib/twitter/streaming/connection.rb +1 -3
  64. data/lib/twitter/streaming/deleted_tweet.rb +8 -0
  65. data/lib/twitter/streaming/event.rb +8 -8
  66. data/lib/twitter/streaming/friend_list.rb +2 -9
  67. data/lib/twitter/streaming/message_parser.rb +13 -3
  68. data/lib/twitter/streaming/response.rb +0 -2
  69. data/lib/twitter/streaming/stall_warning.rb +7 -0
  70. data/lib/twitter/suggestion.rb +0 -1
  71. data/lib/twitter/token.rb +2 -3
  72. data/lib/twitter/trend_results.rb +5 -8
  73. data/lib/twitter/tweet.rb +17 -18
  74. data/lib/twitter/user.rb +33 -35
  75. data/lib/twitter/utils.rb +14 -0
  76. data/lib/twitter/version.rb +2 -5
  77. data/lib/twitter.rb +1 -1
  78. data/spec/fixtures/forbidden.json +1 -0
  79. data/spec/fixtures/search.json +1 -1
  80. data/spec/fixtures/search2.json +1 -0
  81. data/spec/fixtures/track_streaming_user.json +2 -1
  82. data/spec/helper.rb +6 -2
  83. data/spec/twitter/base_spec.rb +9 -9
  84. data/spec/twitter/basic_user_spec.rb +6 -6
  85. data/spec/twitter/configuration_spec.rb +4 -4
  86. data/spec/twitter/cursor_spec.rb +13 -51
  87. data/spec/twitter/direct_message_spec.rb +36 -36
  88. data/spec/twitter/entity/uri_spec.rb +29 -29
  89. data/spec/twitter/error_spec.rb +21 -21
  90. data/spec/twitter/geo/point_spec.rb +9 -9
  91. data/spec/twitter/geo/polygon_spec.rb +5 -5
  92. data/spec/twitter/geo_factory_spec.rb +7 -7
  93. data/spec/twitter/geo_results_spec.rb +11 -11
  94. data/spec/twitter/geo_spec.rb +5 -5
  95. data/spec/twitter/identifiable_spec.rb +9 -9
  96. data/spec/twitter/list_spec.rb +38 -38
  97. data/spec/twitter/media/photo_spec.rb +58 -58
  98. data/spec/twitter/media_factory_spec.rb +5 -5
  99. data/spec/twitter/null_object_spec.rb +6 -6
  100. data/spec/twitter/oembed_spec.rb +68 -68
  101. data/spec/twitter/place_spec.rb +91 -62
  102. data/spec/twitter/profile_banner_spec.rb +3 -3
  103. data/spec/twitter/rate_limit_spec.rb +18 -18
  104. data/spec/twitter/relationship_spec.rb +16 -16
  105. data/spec/twitter/rest/api/direct_messages_spec.rb +61 -61
  106. data/spec/twitter/rest/api/favorites_spec.rb +93 -93
  107. data/spec/twitter/rest/api/friends_and_followers_spec.rb +357 -349
  108. data/spec/twitter/rest/api/geo_spec.rb +33 -33
  109. data/spec/twitter/rest/api/help_spec.rb +24 -24
  110. data/spec/twitter/rest/api/lists_spec.rb +487 -487
  111. data/spec/twitter/rest/api/oauth_spec.rb +30 -30
  112. data/spec/twitter/rest/api/saved_searches_spec.rb +50 -40
  113. data/spec/twitter/rest/api/search_spec.rb +27 -26
  114. data/spec/twitter/rest/api/spam_reporting_spec.rb +9 -9
  115. data/spec/twitter/rest/api/suggested_users_spec.rb +23 -23
  116. data/spec/twitter/rest/api/timelines_spec.rb +58 -58
  117. data/spec/twitter/rest/api/trends_spec.rb +26 -26
  118. data/spec/twitter/rest/api/tweets_spec.rb +304 -266
  119. data/spec/twitter/rest/api/undocumented_spec.rb +51 -51
  120. data/spec/twitter/rest/api/users_spec.rb +360 -360
  121. data/spec/twitter/rest/client_spec.rb +99 -103
  122. data/spec/twitter/saved_search_spec.rb +16 -16
  123. data/spec/twitter/search_results_spec.rb +14 -110
  124. data/spec/twitter/settings_spec.rb +8 -8
  125. data/spec/twitter/size_spec.rb +5 -5
  126. data/spec/twitter/source_user_spec.rb +6 -6
  127. data/spec/twitter/streaming/client_spec.rb +85 -54
  128. data/spec/twitter/streaming/deleted_tweet_spec.rb +23 -0
  129. data/spec/twitter/streaming/event_spec.rb +20 -22
  130. data/spec/twitter/streaming/friend_list_spec.rb +11 -0
  131. data/spec/twitter/streaming/message_parser_spec.rb +54 -0
  132. data/spec/twitter/suggestion_spec.rb +11 -11
  133. data/spec/twitter/target_user_spec.rb +6 -6
  134. data/spec/twitter/token_spec.rb +4 -4
  135. data/spec/twitter/trend_results_spec.rb +30 -30
  136. data/spec/twitter/trend_spec.rb +21 -21
  137. data/spec/twitter/tweet_spec.rb +178 -164
  138. data/spec/twitter/user_spec.rb +190 -190
  139. data/twitter.gemspec +6 -6
  140. data.tar.gz.sig +0 -0
  141. metadata +44 -16
  142. metadata.gz.sig +0 -0
  143. data/lib/twitter/core_ext/enumerable.rb +0 -10
  144. data/lib/twitter/core_ext/kernel.rb +0 -10
  145. data/spec/twitter_spec.rb +0 -0
@@ -1,5 +1,4 @@
1
1
  require 'twitter/arguments'
2
- require 'twitter/core_ext/enumerable'
3
2
  require 'twitter/cursor'
4
3
  require 'twitter/error/forbidden'
5
4
  require 'twitter/error/not_found'
@@ -7,6 +6,7 @@ require 'twitter/list'
7
6
  require 'twitter/rest/api/utils'
8
7
  require 'twitter/tweet'
9
8
  require 'twitter/user'
9
+ require 'twitter/utils'
10
10
 
11
11
  module Twitter
12
12
  module REST
@@ -14,7 +14,7 @@ module Twitter
14
14
  module Lists
15
15
  include Twitter::REST::API::Utils
16
16
  MAX_USERS_PER_REQUEST = 100
17
- URI_SUBSTRING = "://"
17
+ URI_SUBSTRING = '://'
18
18
 
19
19
  # Returns all lists the authenticating or specified user subscribes to, including their own
20
20
  #
@@ -23,17 +23,17 @@ module Twitter
23
23
  # @authentication Requires user context
24
24
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
25
25
  # @return [Array<Twitter::List>]
26
- # @overload lists(options={})
26
+ # @overload lists(options = {})
27
27
  # @param options [Hash] A customizable set of options.
28
28
  # @option options [Boolean] :reverse Set this to true if you would like owned lists to be returned first.
29
- # @overload lists(user, options={})
29
+ # @overload lists(user, options = {})
30
30
  # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
31
31
  # @param options [Hash] A customizable set of options.
32
32
  # @option options [Boolean] :reverse Set this to true if you would like owned lists to be returned first.
33
33
  def lists(*args)
34
- objects_from_response_with_user(Twitter::List, :get, "/1.1/lists/list.json", args)
34
+ objects_from_response_with_user(Twitter::List, :get, '/1.1/lists/list.json', args)
35
35
  end
36
- alias lists_subscribed_to lists
36
+ alias_method :lists_subscribed_to, :lists
37
37
 
38
38
  # Show tweet timeline for members of the specified list
39
39
  #
@@ -42,13 +42,13 @@ module Twitter
42
42
  # @authentication Requires user context
43
43
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
44
44
  # @return [Array<Twitter::Tweet>]
45
- # @overload list_timeline(list, options={})
45
+ # @overload list_timeline(list, options = {})
46
46
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
47
47
  # @param options [Hash] A customizable set of options.
48
48
  # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
49
49
  # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
50
50
  # @option options [Integer] :count The number of results to retrieve.
51
- # @overload list_timeline(user, list, options={})
51
+ # @overload list_timeline(user, list, options = {})
52
52
  # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
53
53
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
54
54
  # @param options [Hash] A customizable set of options.
@@ -59,7 +59,7 @@ module Twitter
59
59
  arguments = Twitter::Arguments.new(args)
60
60
  merge_list!(arguments.options, arguments.pop)
61
61
  merge_owner!(arguments.options, arguments.pop)
62
- objects_from_response(Twitter::Tweet, :get, "/1.1/lists/statuses.json", arguments.options)
62
+ objects_from_response(Twitter::Tweet, :get, '/1.1/lists/statuses.json', arguments.options)
63
63
  end
64
64
 
65
65
  # Removes the specified member from the list
@@ -69,17 +69,17 @@ module Twitter
69
69
  # @authentication Requires user context
70
70
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
71
71
  # @return [Twitter::List] The list.
72
- # @overload remove_list_member(list, user_to_remove, options={})
72
+ # @overload remove_list_member(list, user_to_remove, options = {})
73
73
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
74
74
  # @param user_to_remove [Integer, String] The user id or screen name of the list member to remove.
75
75
  # @param options [Hash] A customizable set of options.
76
- # @overload remove_list_member(user, list, user_to_remove, options={})
76
+ # @overload remove_list_member(user, list, user_to_remove, options = {})
77
77
  # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
78
78
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
79
79
  # @param user_to_remove [Integer, String] The user id or screen name of the list member to remove.
80
80
  # @param options [Hash] A customizable set of options.
81
81
  def remove_list_member(*args)
82
- list_from_response_with_user(:post, "/1.1/lists/members/destroy.json", args)
82
+ list_from_response_with_user(:post, '/1.1/lists/members/destroy.json', args)
83
83
  end
84
84
  deprecate_alias :list_remove_member, :remove_list_member
85
85
 
@@ -90,17 +90,17 @@ module Twitter
90
90
  # @authentication Requires user context
91
91
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
92
92
  # @return [Twitter::Cursor]
93
- # @overload memberships(options={})
93
+ # @overload memberships(options = {})
94
94
  # @param options [Hash] A customizable set of options.
95
95
  # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
96
96
  # @option options [Boolean, String, Integer] :filter_to_owned_lists When set to true, t or 1, will return just lists the authenticating user owns, and the user represented by user_id or screen_name is a member of.
97
- # @overload memberships(user, options={})
97
+ # @overload memberships(user, options = {})
98
98
  # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
99
99
  # @param options [Hash] A customizable set of options.
100
100
  # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
101
101
  # @option options [Boolean, String, Integer] :filter_to_owned_lists When set to true, t or 1, will return just lists the authenticating user owns, and the user represented by user_id or screen_name is a member of.
102
102
  def memberships(*args)
103
- cursor_from_response_with_user(:lists, Twitter::List, :get, "/1.1/lists/memberships.json", args)
103
+ cursor_from_response_with_user(:lists, Twitter::List, :get, '/1.1/lists/memberships.json', args)
104
104
  end
105
105
 
106
106
  # Returns the subscribers of the specified list
@@ -110,17 +110,17 @@ module Twitter
110
110
  # @authentication Requires user context
111
111
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
112
112
  # @return [Twitter::Cursor] The subscribers of the specified list.
113
- # @overload list_subscribers(list, options={})
113
+ # @overload list_subscribers(list, options = {})
114
114
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
115
115
  # @param options [Hash] A customizable set of options.
116
116
  # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
117
- # @overload list_subscribers(user, list, options={})
117
+ # @overload list_subscribers(user, list, options = {})
118
118
  # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
119
119
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
120
120
  # @param options [Hash] A customizable set of options.
121
121
  # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
122
122
  def list_subscribers(*args)
123
- cursor_from_response_with_list(:get, "/1.1/lists/subscribers.json", args)
123
+ cursor_from_response_with_list(:get, '/1.1/lists/subscribers.json', args)
124
124
  end
125
125
 
126
126
  # Make the authenticated user follow the specified list
@@ -130,15 +130,15 @@ module Twitter
130
130
  # @authentication Requires user context
131
131
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
132
132
  # @return [Twitter::List] The specified list.
133
- # @overload list_subscribe(list, options={})
133
+ # @overload list_subscribe(list, options = {})
134
134
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
135
135
  # @param options [Hash] A customizable set of options.
136
- # @overload list_subscribe(user, list, options={})
136
+ # @overload list_subscribe(user, list, options = {})
137
137
  # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
138
138
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
139
139
  # @param options [Hash] A customizable set of options.
140
140
  def list_subscribe(*args)
141
- list_from_response(:post, "/1.1/lists/subscribers/create.json", args)
141
+ list_from_response(:post, '/1.1/lists/subscribers/create.json', args)
142
142
  end
143
143
 
144
144
  # Check if a user is a subscriber of the specified list
@@ -148,18 +148,18 @@ module Twitter
148
148
  # @authentication Requires user context
149
149
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
150
150
  # @return [Boolean] true if user is a subscriber of the specified list, otherwise false.
151
- # @overload list_subscriber?(list, user_to_check, options={})
151
+ # @overload list_subscriber?(list, user_to_check, options = {})
152
152
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
153
153
  # @param user_to_check [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
154
154
  # @param options [Hash] A customizable set of options.
155
- # @overload list_subscriber?(user, list, user_to_check, options={})
155
+ # @overload list_subscriber?(user, list, user_to_check, options = {})
156
156
  # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
157
157
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
158
158
  # @param user_to_check [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
159
159
  # @param options [Hash] A customizable set of options.
160
160
  # @return [Boolean] true if user is a subscriber of the specified list, otherwise false.
161
161
  def list_subscriber?(*args)
162
- list_user?(:get, "/1.1/lists/subscribers/show.json", args)
162
+ list_user?(:get, '/1.1/lists/subscribers/show.json', args)
163
163
  end
164
164
 
165
165
  # Unsubscribes the authenticated user form the specified list
@@ -169,15 +169,15 @@ module Twitter
169
169
  # @authentication Requires user context
170
170
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
171
171
  # @return [Twitter::List] The specified list.
172
- # @overload list_unsubscribe(list, options={})
172
+ # @overload list_unsubscribe(list, options = {})
173
173
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
174
174
  # @param options [Hash] A customizable set of options.
175
- # @overload list_unsubscribe(user, list, options={})
175
+ # @overload list_unsubscribe(user, list, options = {})
176
176
  # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
177
177
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
178
178
  # @param options [Hash] A customizable set of options.
179
179
  def list_unsubscribe(*args)
180
- list_from_response(:post, "/1.1/lists/subscribers/destroy.json", args)
180
+ list_from_response(:post, '/1.1/lists/subscribers/destroy.json', args)
181
181
  end
182
182
 
183
183
  # Adds specified members to a list
@@ -188,17 +188,17 @@ module Twitter
188
188
  # @authentication Requires user context
189
189
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
190
190
  # @return [Twitter::List] The list.
191
- # @overload add_list_members(list, users, options={})
191
+ # @overload add_list_members(list, users, options = {})
192
192
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
193
193
  # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
194
194
  # @param options [Hash] A customizable set of options.
195
- # @overload add_list_members(user, list, users, options={})
195
+ # @overload add_list_members(user, list, users, options = {})
196
196
  # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
197
197
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
198
198
  # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
199
199
  # @param options [Hash] A customizable set of options.
200
200
  def add_list_members(*args)
201
- list_from_response_with_users(:post, "/1.1/lists/members/create_all.json", args)
201
+ list_from_response_with_users(:post, '/1.1/lists/members/create_all.json', args)
202
202
  end
203
203
  deprecate_alias :list_add_members, :add_list_members
204
204
 
@@ -209,17 +209,17 @@ module Twitter
209
209
  # @rate_limited Yes
210
210
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
211
211
  # @return [Boolean] true if user is a member of the specified list, otherwise false.
212
- # @overload list_member?(list, user_to_check, options={})
212
+ # @overload list_member?(list, user_to_check, options = {})
213
213
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
214
214
  # @param user_to_check [Integer, String] The user ID or screen name of the list member.
215
215
  # @param options [Hash] A customizable set of options.
216
- # @overload list_member?(user, list, user_to_check, options={})
216
+ # @overload list_member?(user, list, user_to_check, options = {})
217
217
  # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
218
218
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
219
219
  # @param user_to_check [Integer, String] The user ID or screen name of the list member.
220
220
  # @param options [Hash] A customizable set of options.
221
221
  def list_member?(*args)
222
- list_user?(:get, "/1.1/lists/members/show.json", args)
222
+ list_user?(:get, '/1.1/lists/members/show.json', args)
223
223
  end
224
224
 
225
225
  # Returns the members of the specified list
@@ -229,17 +229,17 @@ module Twitter
229
229
  # @authentication Requires user context
230
230
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
231
231
  # @return [Twitter::Cursor]
232
- # @overload list_members(list, options={})
232
+ # @overload list_members(list, options = {})
233
233
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
234
234
  # @param options [Hash] A customizable set of options.
235
235
  # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
236
- # @overload list_members(user, list, options={})
236
+ # @overload list_members(user, list, options = {})
237
237
  # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
238
238
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
239
239
  # @param options [Hash] A customizable set of options.
240
240
  # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
241
241
  def list_members(*args)
242
- cursor_from_response_with_list(:get, "/1.1/lists/members.json", args)
242
+ cursor_from_response_with_list(:get, '/1.1/lists/members.json', args)
243
243
  end
244
244
 
245
245
  # Add a member to a list
@@ -250,17 +250,17 @@ module Twitter
250
250
  # @authentication Requires user context
251
251
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
252
252
  # @return [Twitter::List] The list.
253
- # @overload add_list_member(list, user_to_add, options={})
253
+ # @overload add_list_member(list, user_to_add, options = {})
254
254
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
255
255
  # @param user_to_add [Integer, String] The user id or screen name to add to the list.
256
256
  # @param options [Hash] A customizable set of options.
257
- # @overload add_list_member(user, list, user_to_add, options={})
257
+ # @overload add_list_member(user, list, user_to_add, options = {})
258
258
  # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
259
259
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
260
260
  # @param user_to_add [Integer, String] The user id or screen name to add to the list.
261
261
  # @param options [Hash] A customizable set of options.
262
262
  def add_list_member(*args)
263
- list_from_response_with_user(:post, "/1.1/lists/members/create.json", args)
263
+ list_from_response_with_user(:post, '/1.1/lists/members/create.json', args)
264
264
  end
265
265
  deprecate_alias :list_add_member, :add_list_member
266
266
 
@@ -272,15 +272,15 @@ module Twitter
272
272
  # @authentication Requires user context
273
273
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
274
274
  # @return [Twitter::List] The deleted list.
275
- # @overload destroy_list(list, options={})
275
+ # @overload destroy_list(list, options = {})
276
276
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
277
277
  # @param options [Hash] A customizable set of options.
278
- # @overload destroy_list(user, list, options={})
278
+ # @overload destroy_list(user, list, options = {})
279
279
  # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
280
280
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
281
281
  # @param options [Hash] A customizable set of options.
282
282
  def destroy_list(*args)
283
- list_from_response(:post, "/1.1/lists/destroy.json", args)
283
+ list_from_response(:post, '/1.1/lists/destroy.json', args)
284
284
  end
285
285
  deprecate_alias :list_destroy, :destroy_list
286
286
 
@@ -291,19 +291,19 @@ module Twitter
291
291
  # @authentication Requires user context
292
292
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
293
293
  # @return [Twitter::List] The created list.
294
- # @overload list_update(list, options={})
294
+ # @overload list_update(list, options = {})
295
295
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
296
296
  # @param options [Hash] A customizable set of options.
297
297
  # @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
298
298
  # @option options [String] :description The description to give the list.
299
- # @overload list_update(user, list, options={})
299
+ # @overload list_update(user, list, options = {})
300
300
  # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
301
301
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
302
302
  # @param options [Hash] A customizable set of options.
303
303
  # @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
304
304
  # @option options [String] :description The description to give the list.
305
305
  def list_update(*args)
306
- list_from_response(:post, "/1.1/lists/update.json", args)
306
+ list_from_response(:post, '/1.1/lists/update.json', args)
307
307
  end
308
308
 
309
309
  # Creates a new list for the authenticated user
@@ -318,8 +318,8 @@ module Twitter
318
318
  # @param options [Hash] A customizable set of options.
319
319
  # @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
320
320
  # @option options [String] :description The description to give the list.
321
- def create_list(name, options={})
322
- object_from_response(Twitter::List, :post, "/1.1/lists/create.json", options.merge(:name => name))
321
+ def create_list(name, options = {})
322
+ object_from_response(Twitter::List, :post, '/1.1/lists/create.json', options.merge(:name => name))
323
323
  end
324
324
  deprecate_alias :list_create, :create_list
325
325
 
@@ -331,15 +331,15 @@ module Twitter
331
331
  # @authentication Requires user context
332
332
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
333
333
  # @return [Twitter::List] The specified list.
334
- # @overload list(list, options={})
334
+ # @overload list(list, options = {})
335
335
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
336
336
  # @param options [Hash] A customizable set of options.
337
- # @overload list(user, list, options={})
337
+ # @overload list(user, list, options = {})
338
338
  # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
339
339
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
340
340
  # @param options [Hash] A customizable set of options.
341
341
  def list(*args)
342
- list_from_response(:get, "/1.1/lists/show.json", args)
342
+ list_from_response(:get, '/1.1/lists/show.json', args)
343
343
  end
344
344
 
345
345
  # List the lists the specified user follows
@@ -349,15 +349,15 @@ module Twitter
349
349
  # @authentication Requires user context
350
350
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
351
351
  # @return [Twitter::Cursor]
352
- # @overload subscriptions(options={})
352
+ # @overload subscriptions(options = {})
353
353
  # @param options [Hash] A customizable set of options.
354
354
  # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
355
- # @overload subscriptions(user, options={})
355
+ # @overload subscriptions(user, options = {})
356
356
  # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
357
357
  # @param options [Hash] A customizable set of options.
358
358
  # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
359
359
  def subscriptions(*args)
360
- cursor_from_response_with_user(:lists, Twitter::List, :get, "/1.1/lists/subscriptions.json", args)
360
+ cursor_from_response_with_user(:lists, Twitter::List, :get, '/1.1/lists/subscriptions.json', args)
361
361
  end
362
362
 
363
363
  # Removes specified members from the list
@@ -367,17 +367,17 @@ module Twitter
367
367
  # @authentication Requires user context
368
368
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
369
369
  # @return [Twitter::List] The list.
370
- # @overload remove_list_members(list, users, options={})
370
+ # @overload remove_list_members(list, users, options = {})
371
371
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
372
372
  # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
373
373
  # @param options [Hash] A customizable set of options.
374
- # @overload remove_list_members(user, list, users, options={})
374
+ # @overload remove_list_members(user, list, users, options = {})
375
375
  # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
376
376
  # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
377
377
  # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
378
378
  # @param options [Hash] A customizable set of options.
379
379
  def remove_list_members(*args)
380
- list_from_response_with_users(:post, "/1.1/lists/members/destroy_all.json", args)
380
+ list_from_response_with_users(:post, '/1.1/lists/members/destroy_all.json', args)
381
381
  end
382
382
  deprecate_alias :list_remove_members, :remove_list_members
383
383
 
@@ -388,15 +388,15 @@ module Twitter
388
388
  # @authentication Requires user context
389
389
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
390
390
  # @return [Array<Twitter::List>]
391
- # @overload owned_lists(options={})
391
+ # @overload owned_lists(options = {})
392
392
  # @param options [Hash] A customizable set of options.
393
393
  # @option options [Integer] :count The amount of results to return per page. Defaults to 20. No more than 1000 results will ever be returned in a single page.
394
- # @overload owned_lists(user, options={})
394
+ # @overload owned_lists(user, options = {})
395
395
  # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
396
396
  # @param options [Hash] A customizable set of options.
397
397
  # @option options [Integer] :count The amount of results to return per page. Defaults to 20. No more than 1000 results will ever be returned in a single page.
398
398
  def owned_lists(*args)
399
- cursor_from_response_with_user(:lists, Twitter::List, :get, "/1.1/lists/ownerships.json", args)
399
+ cursor_from_response_with_user(:lists, Twitter::List, :get, '/1.1/lists/ownerships.json', args)
400
400
  end
401
401
  deprecate_alias :lists_ownerships, :owned_lists
402
402
  deprecate_alias :lists_owned, :owned_lists
@@ -441,12 +441,13 @@ module Twitter
441
441
  end
442
442
 
443
443
  def list_from_response_with_users(request_method, path, args)
444
- arguments = Twitter::Arguments.new(args)
444
+ arguments = args.dup
445
+ options = arguments.last.is_a?(::Hash) ? arguments.pop : {}
445
446
  members = arguments.pop
446
- merge_list!(arguments.options, arguments.pop)
447
- merge_owner!(arguments.options, arguments.pop)
448
- members.flatten.each_slice(MAX_USERS_PER_REQUEST).threaded_map do |users|
449
- object_from_response(Twitter::List, request_method, path, merge_users(arguments.options, users))
447
+ merge_list!(options, arguments.pop)
448
+ merge_owner!(options, arguments.pop)
449
+ Twitter::Utils.parallel_map(members.flatten.each_slice(MAX_USERS_PER_REQUEST)) do |users|
450
+ object_from_response(Twitter::List, request_method, path, merge_users(options, users))
450
451
  end.last
451
452
  end
452
453
 
@@ -455,20 +456,20 @@ module Twitter
455
456
  # @param hash [Hash]
456
457
  # @param list [Integer, String, URI, Twitter::List] A Twitter list ID, slug, URI, or object.
457
458
  # @return [Hash]
458
- def merge_list!(hash, list)
459
+ def merge_list!(hash, list) # rubocop:disable MethodLength
459
460
  case list
460
461
  when Integer
461
462
  hash[:list_id] = list
462
463
  when String
463
464
  if list[URI_SUBSTRING]
464
- list = list.split("/")
465
+ list = list.split('/')
465
466
  hash[:slug] = list.pop
466
467
  hash[:owner_screen_name] = list.pop
467
468
  else
468
469
  hash[:slug] = list
469
470
  end
470
471
  when URI
471
- list = list.path.split("/")
472
+ list = list.path.split('/')
472
473
  hash[:slug] = list.pop
473
474
  hash[:owner_screen_name] = list.pop
474
475
  when Twitter::List
@@ -486,12 +487,11 @@ module Twitter
486
487
  def merge_owner!(hash, user)
487
488
  unless hash[:owner_id] || hash[:owner_screen_name]
488
489
  user ||= screen_name
489
- merge_user!(hash, user, "owner")
490
+ merge_user!(hash, user, 'owner')
490
491
  hash[:owner_id] = hash.delete(:owner_user_id) unless hash[:owner_user_id].nil?
491
492
  end
492
493
  hash
493
494
  end
494
-
495
495
  end
496
496
  end
497
497
  end
@@ -23,9 +23,9 @@ module Twitter
23
23
  # client = Twitter::REST::Client.new(:consumer_key => "abc", :consumer_secret => 'def')
24
24
  # bearer_token = client.token
25
25
  def token
26
- object_from_response(Twitter::Token, :post, "/oauth2/token", :grant_type => "client_credentials", :bearer_token_request => true)
26
+ object_from_response(Twitter::Token, :post, '/oauth2/token', :grant_type => 'client_credentials', :bearer_token_request => true)
27
27
  end
28
- alias bearer_token token
28
+ alias_method :bearer_token, :token
29
29
 
30
30
  # Allows a registered application to revoke an issued OAuth 2 Bearer Token by presenting its client credentials.
31
31
  #
@@ -37,7 +37,7 @@ module Twitter
37
37
  # @return [Twitter::Token] The invalidated token. token_type should be nil.
38
38
  def invalidate_token(access_token)
39
39
  access_token = access_token.access_token if access_token.is_a?(Twitter::Token)
40
- object_from_response(Twitter::Token, :post, "/oauth2/invalidate_token", :access_token => access_token)
40
+ object_from_response(Twitter::Token, :post, '/oauth2/invalidate_token', :access_token => access_token)
41
41
  end
42
42
 
43
43
  # Allows a registered application to revoke an issued OAuth 2 Bearer Token by presenting its client credentials.
@@ -55,7 +55,6 @@ module Twitter
55
55
  end
56
56
  response.body
57
57
  end
58
-
59
58
  end
60
59
  end
61
60
  end
@@ -17,7 +17,7 @@ module Twitter
17
17
  # @param place_id [String] A place in the world. These IDs can be retrieved from {Twitter::REST::API::PlacesAndGeo#reverse_geocode}.
18
18
  # @param options [Hash] A customizable set of options.
19
19
  # @return [Twitter::Place] The requested place.
20
- def place(place_id, options={})
20
+ def place(place_id, options = {})
21
21
  object_from_response(Twitter::Place, :get, "/1.1/geo/id/#{place_id}.json", options)
22
22
  end
23
23
 
@@ -35,8 +35,8 @@ module Twitter
35
35
  # @option options [String] :granularity ('neighborhood') This is the minimal granularity of place types to return and must be one of: 'poi', 'neighborhood', 'city', 'admin' or 'country'.
36
36
  # @option options [Integer] :max_results A hint as to the number of results to return. This does not guarantee that the number of results returned will equal max_results, but instead informs how many "nearby" results to return. Ideally, only pass in the number of places you intend to display to the user here.
37
37
  # @return [Array<Twitter::Place>]
38
- def reverse_geocode(options={})
39
- object_from_response(Twitter::GeoResults, :get, "/1.1/geo/reverse_geocode.json", options)
38
+ def reverse_geocode(options = {})
39
+ object_from_response(Twitter::GeoResults, :get, '/1.1/geo/reverse_geocode.json', options)
40
40
  end
41
41
 
42
42
  # Search for places that can be attached to a {Twitter::REST::API::Tweets#update}
@@ -56,10 +56,10 @@ module Twitter
56
56
  # @option options [String] :contained_within This is the place_id which you would like to restrict the search results to. Setting this value means only places within the given place_id will be found.
57
57
  # @option options [String] :"attribute:street_address" This option searches for places which have this given street address. There are other well-known and application-specific attributes available. Custom attributes are also permitted.
58
58
  # @return [Array<Twitter::Place>]
59
- def geo_search(options={})
60
- object_from_response(Twitter::GeoResults, :get, "/1.1/geo/search.json", options)
59
+ def geo_search(options = {})
60
+ object_from_response(Twitter::GeoResults, :get, '/1.1/geo/search.json', options)
61
61
  end
62
- alias places_nearby geo_search
62
+ alias_method :places_nearby, :geo_search
63
63
 
64
64
  # Locates places near the given coordinates which are similar in name
65
65
  #
@@ -75,11 +75,10 @@ module Twitter
75
75
  # @option options [String] :contained_within This is the place_id which you would like to restrict the search results to. Setting this value means only places within the given place_id will be found.
76
76
  # @option options [String] :"attribute:street_address" This option searches for places which have this given street address. There are other well-known and application-specific attributes available. Custom attributes are also permitted.
77
77
  # @return [Array<Twitter::Place>]
78
- def similar_places(options={})
79
- object_from_response(Twitter::GeoResults, :get, "/1.1/geo/similar_places.json", options)
78
+ def similar_places(options = {})
79
+ object_from_response(Twitter::GeoResults, :get, '/1.1/geo/similar_places.json', options)
80
80
  end
81
- alias places_similar similar_places
82
-
81
+ alias_method :places_similar, :similar_places
83
82
  end
84
83
  end
85
84
  end
@@ -1,6 +1,7 @@
1
1
  require 'twitter/arguments'
2
2
  require 'twitter/rest/api/utils'
3
3
  require 'twitter/saved_search'
4
+ require 'twitter/utils'
4
5
 
5
6
  module Twitter
6
7
  module REST
@@ -12,7 +13,7 @@ module Twitter
12
13
  # @authentication Requires user context
13
14
  # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
14
15
  # @return [Array<Twitter::SavedSearch>] The saved searches.
15
- # @overload saved_search(options={})
16
+ # @overload saved_search(options = {})
16
17
  # Returns the authenticated user's saved search queries
17
18
  #
18
19
  # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/list
@@ -31,9 +32,9 @@ module Twitter
31
32
  def saved_searches(*args)
32
33
  arguments = Twitter::Arguments.new(args)
33
34
  if arguments.empty?
34
- objects_from_response(Twitter::SavedSearch, :get, "/1.1/saved_searches/list.json", arguments.options)
35
+ objects_from_response(Twitter::SavedSearch, :get, '/1.1/saved_searches/list.json', arguments.options)
35
36
  else
36
- arguments.flatten.threaded_map do |id|
37
+ Twitter::Utils.parallel_map(arguments) do |id|
37
38
  saved_search(id, arguments.options)
38
39
  end
39
40
  end
@@ -48,7 +49,7 @@ module Twitter
48
49
  # @return [Twitter::SavedSearch] The saved searches.
49
50
  # @param id [Integer] The ID of the saved search.
50
51
  # @param options [Hash] A customizable set of options.
51
- def saved_search(id, options={})
52
+ def saved_search(id, options = {})
52
53
  object_from_response(Twitter::SavedSearch, :get, "/1.1/saved_searches/show/#{id}.json", options)
53
54
  end
54
55
 
@@ -61,8 +62,8 @@ module Twitter
61
62
  # @return [Twitter::SavedSearch] The created saved search.
62
63
  # @param query [String] The query of the search the user would like to save.
63
64
  # @param options [Hash] A customizable set of options.
64
- def create_saved_search(query, options={})
65
- object_from_response(Twitter::SavedSearch, :post, "/1.1/saved_searches/create.json", options.merge(:query => query))
65
+ def create_saved_search(query, options = {})
66
+ object_from_response(Twitter::SavedSearch, :post, '/1.1/saved_searches/create.json', options.merge(:query => query))
66
67
  end
67
68
  deprecate_alias :saved_search_create, :create_saved_search
68
69
 
@@ -81,12 +82,11 @@ module Twitter
81
82
  # @param options [Hash] A customizable set of options.
82
83
  def destroy_saved_search(*args)
83
84
  arguments = Twitter::Arguments.new(args)
84
- arguments.flatten.threaded_map do |id|
85
+ Twitter::Utils.parallel_map(arguments) do |id|
85
86
  object_from_response(Twitter::SavedSearch, :post, "/1.1/saved_searches/destroy/#{id}.json", arguments.options)
86
87
  end
87
88
  end
88
89
  deprecate_alias :saved_search_destroy, :destroy_saved_search
89
-
90
90
  end
91
91
  end
92
92
  end
@@ -6,6 +6,7 @@ module Twitter
6
6
  module API
7
7
  module Search
8
8
  include Twitter::REST::API::Utils
9
+ MAX_TWEETS_PER_REQUEST = 100
9
10
 
10
11
  # Returns tweets that match a specified query.
11
12
  #
@@ -27,10 +28,17 @@ module Twitter
27
28
  # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
28
29
  # @option options [Boolean, String, Integer] :include_entities The tweet entities node will be disincluded when set to false.
29
30
  # @return [Twitter::SearchResults] Return tweets that match a specified query with search metadata
30
- def search(q, options={})
31
- object_from_response(Twitter::SearchResults, :get, "/1.1/search/tweets.json", options.merge(:q => q))
31
+ def search(q, options = {})
32
+ options[:count] ||= MAX_TWEETS_PER_REQUEST
33
+ search_results_from_response(:get, '/1.1/search/tweets.json', options.merge(:q => q))
32
34
  end
33
35
 
36
+ private
37
+
38
+ def search_results_from_response(request_method, path, options = {}) # rubocop:disable ParameterLists
39
+ response = send(request_method.to_sym, path, options)
40
+ Twitter::SearchResults.from_response(response, self, request_method, path, options)
41
+ end
34
42
  end
35
43
  end
36
44
  end
@@ -20,9 +20,8 @@ module Twitter
20
20
  # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
21
21
  # @param options [Hash] A customizable set of options.
22
22
  def report_spam(*args)
23
- threaded_user_objects_from_response(:post, "/1.1/users/report_spam.json", args)
23
+ threaded_user_objects_from_response(:post, '/1.1/users/report_spam.json', args)
24
24
  end
25
-
26
25
  end
27
26
  end
28
27
  end