twitter 7.0.0 → 8.0.0.rc.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -4
- data/README.md +4 -6
- data/lib/twitter/base.rb +11 -11
- data/lib/twitter/basic_user.rb +3 -2
- data/lib/twitter/client.rb +3 -3
- data/lib/twitter/creatable.rb +2 -2
- data/lib/twitter/cursor.rb +3 -3
- data/lib/twitter/direct_message.rb +4 -5
- data/lib/twitter/direct_message_event.rb +3 -3
- data/lib/twitter/direct_messages/welcome_message.rb +3 -3
- data/lib/twitter/direct_messages/welcome_message_rule.rb +2 -2
- data/lib/twitter/direct_messages/welcome_message_rule_wrapper.rb +3 -3
- data/lib/twitter/direct_messages/welcome_message_wrapper.rb +3 -3
- data/lib/twitter/entities.rb +6 -6
- data/lib/twitter/entity/hashtag.rb +1 -1
- data/lib/twitter/entity/symbol.rb +1 -1
- data/lib/twitter/entity/uri.rb +1 -1
- data/lib/twitter/entity/user_mention.rb +1 -1
- data/lib/twitter/entity.rb +1 -1
- data/lib/twitter/enumerable.rb +1 -3
- data/lib/twitter/error.rb +7 -6
- data/lib/twitter/factory.rb +1 -1
- data/lib/twitter/geo/point.rb +1 -1
- data/lib/twitter/geo/polygon.rb +1 -1
- data/lib/twitter/geo.rb +2 -2
- data/lib/twitter/geo_factory.rb +3 -3
- data/lib/twitter/geo_results.rb +2 -2
- data/lib/twitter/headers.rb +4 -4
- data/lib/twitter/identity.rb +2 -2
- data/lib/twitter/language.rb +1 -1
- data/lib/twitter/list.rb +3 -2
- data/lib/twitter/media/animated_gif.rb +1 -1
- data/lib/twitter/media/photo.rb +2 -2
- data/lib/twitter/media/video.rb +3 -3
- data/lib/twitter/media/video_info.rb +2 -2
- data/lib/twitter/media_factory.rb +4 -4
- data/lib/twitter/metadata.rb +1 -1
- data/lib/twitter/null_object.rb +4 -4
- data/lib/twitter/oembed.rb +2 -1
- data/lib/twitter/place.rb +3 -3
- data/lib/twitter/premium_search_results.rb +5 -5
- data/lib/twitter/profile.rb +8 -8
- data/lib/twitter/profile_banner.rb +2 -2
- data/lib/twitter/rate_limit.rb +4 -4
- data/lib/twitter/relationship.rb +2 -1
- data/lib/twitter/rest/account_activity.rb +3 -3
- data/lib/twitter/rest/api.rb +19 -19
- data/lib/twitter/rest/client.rb +4 -4
- data/lib/twitter/rest/direct_messages/welcome_messages.rb +13 -13
- data/lib/twitter/rest/direct_messages.rb +17 -17
- data/lib/twitter/rest/favorites.rb +15 -19
- data/lib/twitter/rest/form_encoder.rb +27 -0
- data/lib/twitter/rest/friends_and_followers.rb +21 -21
- data/lib/twitter/rest/help.rb +6 -18
- data/lib/twitter/rest/lists.rb +32 -32
- data/lib/twitter/rest/oauth.rb +8 -8
- data/lib/twitter/rest/places_and_geo.rb +6 -6
- data/lib/twitter/rest/premium_search.rb +3 -3
- data/lib/twitter/rest/request.rb +28 -21
- data/lib/twitter/rest/saved_searches.rb +6 -6
- data/lib/twitter/rest/search.rb +3 -3
- data/lib/twitter/rest/spam_reporting.rb +3 -3
- data/lib/twitter/rest/suggested_users.rb +5 -5
- data/lib/twitter/rest/timelines.rb +7 -7
- data/lib/twitter/rest/trends.rb +7 -7
- data/lib/twitter/rest/tweets.rb +19 -23
- data/lib/twitter/rest/undocumented.rb +7 -7
- data/lib/twitter/rest/upload_utils.rb +13 -13
- data/lib/twitter/rest/users.rb +32 -32
- data/lib/twitter/rest/utils.rb +17 -17
- data/lib/twitter/saved_search.rb +2 -2
- data/lib/twitter/search_results.rb +6 -6
- data/lib/twitter/settings.rb +2 -1
- data/lib/twitter/size.rb +2 -2
- data/lib/twitter/source_user.rb +1 -1
- data/lib/twitter/streaming/client.rb +14 -14
- data/lib/twitter/streaming/connection.rb +4 -5
- data/lib/twitter/streaming/message_parser.rb +6 -6
- data/lib/twitter/streaming/response.rb +11 -10
- data/lib/twitter/suggestion.rb +3 -3
- data/lib/twitter/target_user.rb +1 -1
- data/lib/twitter/trend.rb +3 -2
- data/lib/twitter/trend_results.rb +5 -5
- data/lib/twitter/tweet.rb +3 -3
- data/lib/twitter/user.rb +9 -9
- data/lib/twitter/utils.rb +2 -2
- data/lib/twitter/variant.rb +2 -1
- data/lib/twitter/version.rb +3 -3
- data/lib/twitter.rb +36 -36
- data/twitter.gemspec +19 -18
- metadata +23 -22
- data/lib/twitter/configuration.rb +0 -27
data/lib/twitter/rest/lists.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
1
|
+
require "addressable/uri"
|
2
|
+
require "twitter/arguments"
|
3
|
+
require "twitter/cursor"
|
4
|
+
require "twitter/error"
|
5
|
+
require "twitter/list"
|
6
|
+
require "twitter/rest/request"
|
7
|
+
require "twitter/rest/utils"
|
8
|
+
require "twitter/tweet"
|
9
|
+
require "twitter/user"
|
10
|
+
require "twitter/utils"
|
11
|
+
require "uri"
|
12
12
|
|
13
13
|
module Twitter
|
14
14
|
module REST
|
@@ -32,7 +32,7 @@ module Twitter
|
|
32
32
|
# @param options [Hash] A customizable set of options.
|
33
33
|
# @option options [Boolean] :reverse Set this to true if you would like owned lists to be returned first.
|
34
34
|
def lists(*args)
|
35
|
-
objects_from_response_with_user(Twitter::List, :get,
|
35
|
+
objects_from_response_with_user(Twitter::List, :get, "/1.1/lists/list.json", args)
|
36
36
|
end
|
37
37
|
alias lists_subscribed_to lists
|
38
38
|
|
@@ -61,7 +61,7 @@ module Twitter
|
|
61
61
|
arguments = Twitter::Arguments.new(args)
|
62
62
|
merge_list!(arguments.options, arguments.pop)
|
63
63
|
merge_owner!(arguments.options, arguments.pop)
|
64
|
-
perform_get_with_objects(
|
64
|
+
perform_get_with_objects("/1.1/lists/statuses.json", arguments.options, Twitter::Tweet)
|
65
65
|
end
|
66
66
|
|
67
67
|
# Removes the specified member from the list
|
@@ -82,7 +82,7 @@ module Twitter
|
|
82
82
|
# @param user_to_remove [Integer, String] The user id or screen name of the list member to remove.
|
83
83
|
# @param options [Hash] A customizable set of options.
|
84
84
|
def remove_list_member(*args)
|
85
|
-
list_from_response_with_user(
|
85
|
+
list_from_response_with_user("/1.1/lists/members/destroy.json", args)
|
86
86
|
end
|
87
87
|
|
88
88
|
# List the lists the specified user has been added to
|
@@ -102,7 +102,7 @@ module Twitter
|
|
102
102
|
# @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.
|
103
103
|
# @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.
|
104
104
|
def memberships(*args)
|
105
|
-
cursor_from_response_with_user(:lists, Twitter::List,
|
105
|
+
cursor_from_response_with_user(:lists, Twitter::List, "/1.1/lists/memberships.json", args)
|
106
106
|
end
|
107
107
|
|
108
108
|
# Returns the subscribers of the specified list
|
@@ -121,7 +121,7 @@ module Twitter
|
|
121
121
|
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
122
122
|
# @param options [Hash] A customizable set of options.
|
123
123
|
def list_subscribers(*args)
|
124
|
-
cursor_from_response_with_list(
|
124
|
+
cursor_from_response_with_list("/1.1/lists/subscribers.json", args)
|
125
125
|
end
|
126
126
|
|
127
127
|
# Make the authenticated user follow the specified list
|
@@ -140,7 +140,7 @@ module Twitter
|
|
140
140
|
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
141
141
|
# @param options [Hash] A customizable set of options.
|
142
142
|
def list_subscribe(*args)
|
143
|
-
list_from_response(:post,
|
143
|
+
list_from_response(:post, "/1.1/lists/subscribers/create.json", args)
|
144
144
|
end
|
145
145
|
|
146
146
|
# Check if a user is a subscriber of the specified list
|
@@ -162,7 +162,7 @@ module Twitter
|
|
162
162
|
# @param options [Hash] A customizable set of options.
|
163
163
|
# @return [Boolean] true if user is a subscriber of the specified list, otherwise false.
|
164
164
|
def list_subscriber?(*args)
|
165
|
-
list_user?(:get,
|
165
|
+
list_user?(:get, "/1.1/lists/subscribers/show.json", args)
|
166
166
|
end
|
167
167
|
|
168
168
|
# Unsubscribes the authenticated user form the specified list
|
@@ -181,7 +181,7 @@ module Twitter
|
|
181
181
|
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
182
182
|
# @param options [Hash] A customizable set of options.
|
183
183
|
def list_unsubscribe(*args)
|
184
|
-
list_from_response(:post,
|
184
|
+
list_from_response(:post, "/1.1/lists/subscribers/destroy.json", args)
|
185
185
|
end
|
186
186
|
|
187
187
|
# Adds specified members to a list
|
@@ -204,7 +204,7 @@ module Twitter
|
|
204
204
|
# @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
|
205
205
|
# @param options [Hash] A customizable set of options.
|
206
206
|
def add_list_members(*args)
|
207
|
-
list_from_response_with_users(
|
207
|
+
list_from_response_with_users("/1.1/lists/members/create_all.json", args)
|
208
208
|
end
|
209
209
|
|
210
210
|
# Check if a user is a member of the specified list
|
@@ -225,7 +225,7 @@ module Twitter
|
|
225
225
|
# @param user_to_check [Integer, String] The user ID or screen name of the list member.
|
226
226
|
# @param options [Hash] A customizable set of options.
|
227
227
|
def list_member?(*args)
|
228
|
-
list_user?(:get,
|
228
|
+
list_user?(:get, "/1.1/lists/members/show.json", args)
|
229
229
|
end
|
230
230
|
|
231
231
|
# Returns the members of the specified list
|
@@ -244,7 +244,7 @@ module Twitter
|
|
244
244
|
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
245
245
|
# @param options [Hash] A customizable set of options.
|
246
246
|
def list_members(*args)
|
247
|
-
cursor_from_response_with_list(
|
247
|
+
cursor_from_response_with_list("/1.1/lists/members.json", args)
|
248
248
|
end
|
249
249
|
|
250
250
|
# Add a member to a list
|
@@ -266,7 +266,7 @@ module Twitter
|
|
266
266
|
# @param user_to_add [Integer, String] The user id or screen name to add to the list.
|
267
267
|
# @param options [Hash] A customizable set of options.
|
268
268
|
def add_list_member(*args)
|
269
|
-
list_from_response_with_user(
|
269
|
+
list_from_response_with_user("/1.1/lists/members/create.json", args)
|
270
270
|
end
|
271
271
|
|
272
272
|
# Deletes the specified list
|
@@ -286,7 +286,7 @@ module Twitter
|
|
286
286
|
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
287
287
|
# @param options [Hash] A customizable set of options.
|
288
288
|
def destroy_list(*args)
|
289
|
-
list_from_response(:post,
|
289
|
+
list_from_response(:post, "/1.1/lists/destroy.json", args)
|
290
290
|
end
|
291
291
|
|
292
292
|
# Updates the specified list
|
@@ -309,7 +309,7 @@ module Twitter
|
|
309
309
|
# @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
|
310
310
|
# @option options [String] :description The description to give the list.
|
311
311
|
def list_update(*args)
|
312
|
-
list_from_response(:post,
|
312
|
+
list_from_response(:post, "/1.1/lists/update.json", args)
|
313
313
|
end
|
314
314
|
|
315
315
|
# Creates a new list for the authenticated user
|
@@ -325,7 +325,7 @@ module Twitter
|
|
325
325
|
# @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
|
326
326
|
# @option options [String] :description The description to give the list.
|
327
327
|
def create_list(name, options = {})
|
328
|
-
perform_post_with_object(
|
328
|
+
perform_post_with_object("/1.1/lists/create.json", options.merge(name: name), Twitter::List)
|
329
329
|
end
|
330
330
|
|
331
331
|
# Show the specified list
|
@@ -345,7 +345,7 @@ module Twitter
|
|
345
345
|
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
|
346
346
|
# @param options [Hash] A customizable set of options.
|
347
347
|
def list(*args)
|
348
|
-
list_from_response(:get,
|
348
|
+
list_from_response(:get, "/1.1/lists/show.json", args)
|
349
349
|
end
|
350
350
|
|
351
351
|
# List the lists the specified user follows
|
@@ -361,7 +361,7 @@ module Twitter
|
|
361
361
|
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
362
362
|
# @param options [Hash] A customizable set of options.
|
363
363
|
def subscriptions(*args)
|
364
|
-
cursor_from_response_with_user(:lists, Twitter::List,
|
364
|
+
cursor_from_response_with_user(:lists, Twitter::List, "/1.1/lists/subscriptions.json", args)
|
365
365
|
end
|
366
366
|
|
367
367
|
# Removes specified members from the list
|
@@ -382,7 +382,7 @@ module Twitter
|
|
382
382
|
# @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
|
383
383
|
# @param options [Hash] A customizable set of options.
|
384
384
|
def remove_list_members(*args)
|
385
|
-
list_from_response_with_users(
|
385
|
+
list_from_response_with_users("/1.1/lists/members/destroy_all.json", args)
|
386
386
|
end
|
387
387
|
|
388
388
|
# Returns the lists owned by the specified Twitter user
|
@@ -400,7 +400,7 @@ module Twitter
|
|
400
400
|
# @param options [Hash] A customizable set of options.
|
401
401
|
# @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.
|
402
402
|
def owned_lists(*args)
|
403
|
-
cursor_from_response_with_user(:lists, Twitter::List,
|
403
|
+
cursor_from_response_with_user(:lists, Twitter::List, "/1.1/lists/ownerships.json", args)
|
404
404
|
end
|
405
405
|
|
406
406
|
private
|
@@ -467,7 +467,7 @@ module Twitter
|
|
467
467
|
end
|
468
468
|
|
469
469
|
def merge_slug_and_owner!(hash, path)
|
470
|
-
list = path.split(
|
470
|
+
list = path.split("/")
|
471
471
|
hash[:slug] = list.pop
|
472
472
|
hash[:owner_screen_name] = list.pop unless list.empty?
|
473
473
|
end
|
@@ -486,7 +486,7 @@ module Twitter
|
|
486
486
|
return hash if hash[:owner_id] || hash[:owner_screen_name]
|
487
487
|
|
488
488
|
if user
|
489
|
-
merge_user!(hash, user,
|
489
|
+
merge_user!(hash, user, "owner")
|
490
490
|
hash[:owner_id] = hash.delete(:owner_user_id) unless hash[:owner_user_id].nil?
|
491
491
|
else
|
492
492
|
hash[:owner_id] = user_id
|
data/lib/twitter/rest/oauth.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "twitter/headers"
|
2
|
+
require "twitter/rest/utils"
|
3
3
|
|
4
4
|
module Twitter
|
5
5
|
module REST
|
@@ -24,11 +24,11 @@ module Twitter
|
|
24
24
|
def token(options = {})
|
25
25
|
options = options.dup
|
26
26
|
options[:bearer_token_request] = true
|
27
|
-
options[:grant_type] ||=
|
28
|
-
url =
|
27
|
+
options[:grant_type] ||= "client_credentials"
|
28
|
+
url = "https://api.twitter.com/oauth2/token"
|
29
29
|
headers = Twitter::Headers.new(self, :post, url, options).request_headers
|
30
30
|
response = HTTP.headers(headers).post(url, form: options)
|
31
|
-
response.parse[
|
31
|
+
response.parse["access_token"]
|
32
32
|
end
|
33
33
|
alias bearer_token token
|
34
34
|
|
@@ -44,7 +44,7 @@ module Twitter
|
|
44
44
|
def invalidate_token(access_token, options = {})
|
45
45
|
options = options.dup
|
46
46
|
options[:access_token] = access_token
|
47
|
-
perform_post(
|
47
|
+
perform_post("/oauth2/invalidate_token", options)[:access_token]
|
48
48
|
end
|
49
49
|
|
50
50
|
# Allows a registered application to revoke an issued OAuth 2 Bearer Token by presenting its client credentials.
|
@@ -55,8 +55,8 @@ module Twitter
|
|
55
55
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
56
56
|
# @return [String] The token string.
|
57
57
|
def reverse_token
|
58
|
-
options = {x_auth_mode:
|
59
|
-
url =
|
58
|
+
options = {x_auth_mode: "reverse_auth"}
|
59
|
+
url = "https://api.twitter.com/oauth/request_token"
|
60
60
|
auth_header = Twitter::Headers.new(self, :post, url, options).oauth_auth_header.to_s
|
61
61
|
HTTP.headers(authorization: auth_header).post(url, params: options).to_s
|
62
62
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "twitter/geo_results"
|
2
|
+
require "twitter/place"
|
3
|
+
require "twitter/rest/utils"
|
4
4
|
|
5
5
|
module Twitter
|
6
6
|
module REST
|
@@ -35,7 +35,7 @@ module Twitter
|
|
35
35
|
# @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.
|
36
36
|
# @return [Array<Twitter::Place>]
|
37
37
|
def reverse_geocode(options = {})
|
38
|
-
perform_get_with_object(
|
38
|
+
perform_get_with_object("/1.1/geo/reverse_geocode.json", options, Twitter::GeoResults)
|
39
39
|
end
|
40
40
|
|
41
41
|
# Search for places that can be attached to a {Twitter::REST::Tweets#update}
|
@@ -56,7 +56,7 @@ module Twitter
|
|
56
56
|
# @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.
|
57
57
|
# @return [Array<Twitter::Place>]
|
58
58
|
def geo_search(options = {})
|
59
|
-
perform_get_with_object(
|
59
|
+
perform_get_with_object("/1.1/geo/search.json", options, Twitter::GeoResults)
|
60
60
|
end
|
61
61
|
alias places_nearby geo_search
|
62
62
|
|
@@ -75,7 +75,7 @@ module Twitter
|
|
75
75
|
# @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.
|
76
76
|
# @return [Array<Twitter::Place>]
|
77
77
|
def similar_places(options = {})
|
78
|
-
perform_get_with_object(
|
78
|
+
perform_get_with_object("/1.1/geo/similar_places.json", options, Twitter::GeoResults)
|
79
79
|
end
|
80
80
|
alias places_similar similar_places
|
81
81
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "twitter/rest/request"
|
2
|
+
require "twitter/premium_search_results"
|
3
3
|
|
4
4
|
module Twitter
|
5
5
|
module REST
|
@@ -24,7 +24,7 @@ module Twitter
|
|
24
24
|
options = options.clone
|
25
25
|
options[:maxResults] ||= MAX_TWEETS_PER_REQUEST
|
26
26
|
request_config[:request_method] = :json_post if request_config[:request_method].nil? || request_config[:request_method] == :post
|
27
|
-
request_config[:product] ||=
|
27
|
+
request_config[:product] ||= "30day"
|
28
28
|
path = "/1.1/tweets/search/#{request_config[:product]}/#{dev_environment}.json"
|
29
29
|
request = Twitter::REST::Request.new(self, request_config[:request_method], path, options.merge(query: query))
|
30
30
|
Twitter::PremiumSearchResults.new(request, request_config)
|
data/lib/twitter/rest/request.rb
CHANGED
@@ -1,18 +1,19 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
1
|
+
require "addressable/uri"
|
2
|
+
require "http"
|
3
|
+
require "http/form_data"
|
4
|
+
require "json"
|
5
|
+
require "openssl"
|
6
|
+
require "twitter/error"
|
7
|
+
require "twitter/headers"
|
8
|
+
require "twitter/rate_limit"
|
9
|
+
require "twitter/utils"
|
10
|
+
require "twitter/rest/form_encoder"
|
10
11
|
|
11
12
|
module Twitter
|
12
13
|
module REST
|
13
14
|
class Request # rubocop:disable Metrics/ClassLength
|
14
15
|
include Twitter::Utils
|
15
|
-
BASE_URL =
|
16
|
+
BASE_URL = "https://api.twitter.com".freeze
|
16
17
|
attr_accessor :client, :headers, :options, :path, :rate_limit,
|
17
18
|
:request_method, :uri
|
18
19
|
alias verb request_method
|
@@ -24,7 +25,7 @@ module Twitter
|
|
24
25
|
# @return [Twitter::REST::Request]
|
25
26
|
def initialize(client, request_method, path, options = {}, params = nil)
|
26
27
|
@client = client
|
27
|
-
@uri = Addressable::URI.parse(path.start_with?(
|
28
|
+
@uri = Addressable::URI.parse(path.start_with?("http") ? path : BASE_URL + path)
|
28
29
|
multipart_options = params || options
|
29
30
|
set_multipart_options!(request_method, multipart_options)
|
30
31
|
@path = uri.path
|
@@ -36,7 +37,7 @@ module Twitter
|
|
36
37
|
# @return [Array, Hash]
|
37
38
|
def perform
|
38
39
|
response = http_client.headers(@headers).public_send(@request_method, @uri.to_s, request_options)
|
39
|
-
response_body = response.body.empty? ?
|
40
|
+
response_body = response.body.empty? ? "" : symbolize_keys!(response.parse)
|
40
41
|
response_headers = response.headers
|
41
42
|
fail_or_return_response_body(response.code, response_body, response_headers)
|
42
43
|
end
|
@@ -44,7 +45,12 @@ module Twitter
|
|
44
45
|
private
|
45
46
|
|
46
47
|
def request_options
|
47
|
-
options =
|
48
|
+
options = if @options_key == :form
|
49
|
+
{form: HTTP::FormData.create(@options, encoder: Twitter::REST::FormEncoder.method(:encode))}
|
50
|
+
else
|
51
|
+
{@options_key => @options}
|
52
|
+
end
|
53
|
+
|
48
54
|
if @params
|
49
55
|
if options[:params]
|
50
56
|
options[:params].merge(@params)
|
@@ -60,7 +66,7 @@ module Twitter
|
|
60
66
|
file = options.delete(:file)
|
61
67
|
|
62
68
|
options[key] = if file.is_a?(StringIO)
|
63
|
-
HTTP::FormData::File.new(file, content_type:
|
69
|
+
HTTP::FormData::File.new(file, content_type: "video/mp4")
|
64
70
|
else
|
65
71
|
HTTP::FormData::File.new(file, filename: File.basename(file), content_type: content_type(File.basename(file)))
|
66
72
|
end
|
@@ -82,13 +88,13 @@ module Twitter
|
|
82
88
|
def content_type(basename)
|
83
89
|
case basename
|
84
90
|
when /\.gif$/i
|
85
|
-
|
91
|
+
"image/gif"
|
86
92
|
when /\.jpe?g/i
|
87
|
-
|
93
|
+
"image/jpeg"
|
88
94
|
when /\.png$/i
|
89
|
-
|
95
|
+
"image/png"
|
90
96
|
else
|
91
|
-
|
97
|
+
"application/octet-stream"
|
92
98
|
end
|
93
99
|
end
|
94
100
|
|
@@ -106,7 +112,7 @@ module Twitter
|
|
106
112
|
forbidden_error(body, headers)
|
107
113
|
elsif !klass.nil?
|
108
114
|
klass.from_response(body, headers)
|
109
|
-
elsif body
|
115
|
+
elsif body.is_a?(Hash) && (err = body.dig(:processing_info, :error))
|
110
116
|
Twitter::Error::MediaError.from_processing_response(err, headers)
|
111
117
|
end
|
112
118
|
end
|
@@ -122,11 +128,12 @@ module Twitter
|
|
122
128
|
end
|
123
129
|
|
124
130
|
def symbolize_keys!(object)
|
125
|
-
|
131
|
+
case object
|
132
|
+
when Array
|
126
133
|
object.each_with_index do |val, index|
|
127
134
|
object[index] = symbolize_keys!(val)
|
128
135
|
end
|
129
|
-
|
136
|
+
when Hash
|
130
137
|
object.dup.each_key do |key|
|
131
138
|
object[key.to_sym] = symbolize_keys!(object.delete(key))
|
132
139
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "twitter/arguments"
|
2
|
+
require "twitter/rest/utils"
|
3
|
+
require "twitter/saved_search"
|
4
|
+
require "twitter/utils"
|
5
5
|
|
6
6
|
module Twitter
|
7
7
|
module REST
|
@@ -32,7 +32,7 @@ module Twitter
|
|
32
32
|
def saved_searches(*args)
|
33
33
|
arguments = Twitter::Arguments.new(args)
|
34
34
|
if arguments.empty?
|
35
|
-
perform_get_with_objects(
|
35
|
+
perform_get_with_objects("/1.1/saved_searches/list.json", arguments.options, Twitter::SavedSearch)
|
36
36
|
else
|
37
37
|
pmap(arguments) do |id|
|
38
38
|
saved_search(id, arguments.options)
|
@@ -63,7 +63,7 @@ module Twitter
|
|
63
63
|
# @param query [String] The query of the search the user would like to save.
|
64
64
|
# @param options [Hash] A customizable set of options.
|
65
65
|
def create_saved_search(query, options = {})
|
66
|
-
perform_post_with_object(
|
66
|
+
perform_post_with_object("/1.1/saved_searches/create.json", options.merge(query: query), Twitter::SavedSearch)
|
67
67
|
end
|
68
68
|
|
69
69
|
# Destroys saved searches for the authenticated user
|
data/lib/twitter/rest/search.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "twitter/rest/request"
|
2
|
+
require "twitter/search_results"
|
3
3
|
|
4
4
|
module Twitter
|
5
5
|
module REST
|
@@ -30,7 +30,7 @@ module Twitter
|
|
30
30
|
def search(query, options = {})
|
31
31
|
options = options.dup
|
32
32
|
options[:count] ||= MAX_TWEETS_PER_REQUEST
|
33
|
-
request = Twitter::REST::Request.new(self, :get,
|
33
|
+
request = Twitter::REST::Request.new(self, :get, "/1.1/search/tweets.json", options.merge(q: query))
|
34
34
|
Twitter::SearchResults.new(request)
|
35
35
|
end
|
36
36
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "twitter/rest/utils"
|
2
|
+
require "twitter/user"
|
3
3
|
|
4
4
|
module Twitter
|
5
5
|
module REST
|
@@ -19,7 +19,7 @@ module Twitter
|
|
19
19
|
# @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
|
20
20
|
# @param options [Hash] A customizable set of options.
|
21
21
|
def report_spam(*args)
|
22
|
-
parallel_users_from_response(:post,
|
22
|
+
parallel_users_from_response(:post, "/1.1/users/report_spam.json", args)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "twitter/arguments"
|
2
|
+
require "twitter/rest/utils"
|
3
|
+
require "twitter/suggestion"
|
4
|
+
require "twitter/user"
|
5
5
|
|
6
6
|
module Twitter
|
7
7
|
module REST
|
@@ -28,7 +28,7 @@ module Twitter
|
|
28
28
|
if arguments.last
|
29
29
|
perform_get_with_object("/1.1/users/suggestions/#{arguments.pop}.json", arguments.options, Twitter::Suggestion)
|
30
30
|
else
|
31
|
-
perform_get_with_objects(
|
31
|
+
perform_get_with_objects("/1.1/users/suggestions.json", arguments.options, Twitter::Suggestion)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "twitter/rest/utils"
|
2
|
+
require "twitter/tweet"
|
3
|
+
require "twitter/user"
|
4
4
|
|
5
5
|
module Twitter
|
6
6
|
module REST
|
@@ -23,7 +23,7 @@ module Twitter
|
|
23
23
|
# @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
|
24
24
|
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
|
25
25
|
def mentions_timeline(options = {})
|
26
|
-
perform_get_with_objects(
|
26
|
+
perform_get_with_objects("/1.1/statuses/mentions_timeline.json", options, Twitter::Tweet)
|
27
27
|
end
|
28
28
|
alias mentions mentions_timeline
|
29
29
|
|
@@ -46,7 +46,7 @@ module Twitter
|
|
46
46
|
# @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
|
47
47
|
# @option options [Boolean, String, Integer] :include_rts Specifies that the timeline should include native retweets in addition to regular tweets. Note: If you're using the trim_user parameter in conjunction with include_rts, the retweets will no longer contain a full user object.
|
48
48
|
def user_timeline(*args)
|
49
|
-
objects_from_response_with_user(Twitter::Tweet, :get,
|
49
|
+
objects_from_response_with_user(Twitter::Tweet, :get, "/1.1/statuses/user_timeline.json", args)
|
50
50
|
end
|
51
51
|
|
52
52
|
# Returns the 20 most recent retweets posted by the specified user
|
@@ -110,7 +110,7 @@ module Twitter
|
|
110
110
|
# @option options [Boolean, String, Integer] :include_rts Specifies that the timeline should include native retweets in addition to regular tweets. Note: If you're using the trim_user parameter in conjunction with include_rts, the retweets will no longer contain a full user object.
|
111
111
|
# @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
|
112
112
|
def home_timeline(options = {})
|
113
|
-
perform_get_with_objects(
|
113
|
+
perform_get_with_objects("/1.1/statuses/home_timeline.json", options, Twitter::Tweet)
|
114
114
|
end
|
115
115
|
|
116
116
|
# Returns the 20 most recent retweets posted by users the authenticating user follow.
|
@@ -148,7 +148,7 @@ module Twitter
|
|
148
148
|
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
|
149
149
|
# @option options [Boolean, String, Integer] :include_user_entities The user entities node will be disincluded when set to false.
|
150
150
|
def retweets_of_me(options = {})
|
151
|
-
perform_get_with_objects(
|
151
|
+
perform_get_with_objects("/1.1/statuses/retweets_of_me.json", options, Twitter::Tweet)
|
152
152
|
end
|
153
153
|
|
154
154
|
private
|
data/lib/twitter/rest/trends.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "twitter/place"
|
2
|
+
require "twitter/rest/request"
|
3
|
+
require "twitter/rest/utils"
|
4
|
+
require "twitter/trend_results"
|
5
5
|
|
6
6
|
module Twitter
|
7
7
|
module REST
|
@@ -21,7 +21,7 @@ module Twitter
|
|
21
21
|
def trends(id = 1, options = {})
|
22
22
|
options = options.dup
|
23
23
|
options[:id] = id
|
24
|
-
response = perform_get(
|
24
|
+
response = perform_get("/1.1/trends/place.json", options).first
|
25
25
|
Twitter::TrendResults.new(response)
|
26
26
|
end
|
27
27
|
alias local_trends trends
|
@@ -36,7 +36,7 @@ module Twitter
|
|
36
36
|
# @param options [Hash] A customizable set of options.
|
37
37
|
# @return [Array<Twitter::Place>]
|
38
38
|
def trends_available(options = {})
|
39
|
-
perform_get_with_objects(
|
39
|
+
perform_get_with_objects("/1.1/trends/available.json", options, Twitter::Place)
|
40
40
|
end
|
41
41
|
alias trend_locations trends_available
|
42
42
|
|
@@ -51,7 +51,7 @@ module Twitter
|
|
51
51
|
# @option options [Float] :long If provided with a :lat option the available trend locations will be sorted by distance, nearest to furthest, to the co-ordinate pair. The valid ranges for longitude are -180.0 to +180.0 (East is positive) inclusive.
|
52
52
|
# @return [Array<Twitter::Place>]
|
53
53
|
def trends_closest(options = {})
|
54
|
-
perform_get_with_objects(
|
54
|
+
perform_get_with_objects("/1.1/trends/closest.json", options, Twitter::Place)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|