twitter 5.6.0 → 5.7.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.
- data.tar.gz.sig +0 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +8 -0
- data/README.md +3 -3
- data/Rakefile +1 -1
- data/lib/twitter/base.rb +0 -8
- data/lib/twitter/client.rb +2 -1
- data/lib/twitter/cursor.rb +2 -15
- data/lib/twitter/error.rb +90 -18
- data/lib/twitter/geo_results.rb +0 -10
- data/lib/twitter/request.rb +4 -4
- data/lib/twitter/rest/api.rb +43 -0
- data/lib/twitter/rest/client.rb +10 -44
- data/lib/twitter/rest/direct_messages.rb +138 -0
- data/lib/twitter/rest/favorites.rb +108 -0
- data/lib/twitter/rest/friends_and_followers.rb +281 -0
- data/lib/twitter/rest/help.rb +56 -0
- data/lib/twitter/rest/lists.rb +497 -0
- data/lib/twitter/rest/oauth.rb +65 -0
- data/lib/twitter/rest/places_and_geo.rb +84 -0
- data/lib/twitter/rest/request/multipart_with_file.rb +5 -5
- data/lib/twitter/rest/response/parse_json.rb +2 -4
- data/lib/twitter/rest/response/raise_error.rb +24 -15
- data/lib/twitter/rest/saved_searches.rb +93 -0
- data/lib/twitter/rest/search.rb +37 -0
- data/lib/twitter/rest/spam_reporting.rb +27 -0
- data/lib/twitter/rest/suggested_users.rb +49 -0
- data/lib/twitter/rest/timelines.rb +200 -0
- data/lib/twitter/rest/trends.rb +57 -0
- data/lib/twitter/rest/tweets.rb +309 -0
- data/lib/twitter/rest/undocumented.rb +49 -0
- data/lib/twitter/rest/users.rb +383 -0
- data/lib/twitter/rest/utils.rb +205 -0
- data/lib/twitter/search_results.rb +2 -13
- data/lib/twitter/trend_results.rb +0 -10
- data/lib/twitter/version.rb +1 -1
- data/spec/helper.rb +1 -1
- data/spec/twitter/error_spec.rb +26 -42
- data/spec/twitter/rest/{api/direct_messages_spec.rb → direct_messages_spec.rb} +1 -1
- data/spec/twitter/rest/{api/favorites_spec.rb → favorites_spec.rb} +1 -1
- data/spec/twitter/rest/{api/friends_and_followers_spec.rb → friends_and_followers_spec.rb} +1 -1
- data/spec/twitter/rest/{api/geo_spec.rb → geo_spec.rb} +1 -1
- data/spec/twitter/rest/{api/help_spec.rb → help_spec.rb} +1 -1
- data/spec/twitter/rest/{api/lists_spec.rb → lists_spec.rb} +1 -1
- data/spec/twitter/rest/{api/oauth_spec.rb → oauth_spec.rb} +4 -8
- data/spec/twitter/rest/{api/saved_searches_spec.rb → saved_searches_spec.rb} +1 -1
- data/spec/twitter/rest/{api/search_spec.rb → search_spec.rb} +1 -1
- data/spec/twitter/rest/{api/spam_reporting_spec.rb → spam_reporting_spec.rb} +1 -1
- data/spec/twitter/rest/{api/suggested_users_spec.rb → suggested_users_spec.rb} +1 -1
- data/spec/twitter/rest/{api/timelines_spec.rb → timelines_spec.rb} +1 -1
- data/spec/twitter/rest/{api/trends_spec.rb → trends_spec.rb} +1 -1
- data/spec/twitter/rest/{api/tweets_spec.rb → tweets_spec.rb} +74 -5
- data/spec/twitter/rest/{api/undocumented_spec.rb → undocumented_spec.rb} +1 -1
- data/spec/twitter/rest/{api/users_spec.rb → users_spec.rb} +5 -5
- data/spec/twitter/tweet_spec.rb +1 -1
- data/twitter.gemspec +0 -1
- metadata +247 -237
- metadata.gz.sig +0 -0
- checksums.yaml +0 -7
- checksums.yaml.gz.sig +0 -0
- data/lib/twitter/error/already_favorited.rb +0 -10
- data/lib/twitter/error/already_posted.rb +0 -10
- data/lib/twitter/error/already_retweeted.rb +0 -10
- data/lib/twitter/error/bad_gateway.rb +0 -10
- data/lib/twitter/error/bad_request.rb +0 -10
- data/lib/twitter/error/configuration_error.rb +0 -8
- data/lib/twitter/error/forbidden.rb +0 -10
- data/lib/twitter/error/gateway_timeout.rb +0 -10
- data/lib/twitter/error/internal_server_error.rb +0 -10
- data/lib/twitter/error/not_acceptable.rb +0 -10
- data/lib/twitter/error/not_found.rb +0 -10
- data/lib/twitter/error/request_timeout.rb +0 -10
- data/lib/twitter/error/service_unavailable.rb +0 -10
- data/lib/twitter/error/too_many_requests.rb +0 -12
- data/lib/twitter/error/unauthorized.rb +0 -10
- data/lib/twitter/error/unprocessable_entity.rb +0 -10
- data/lib/twitter/rest/api/direct_messages.rb +0 -140
- data/lib/twitter/rest/api/favorites.rb +0 -115
- data/lib/twitter/rest/api/friends_and_followers.rb +0 -284
- data/lib/twitter/rest/api/help.rb +0 -58
- data/lib/twitter/rest/api/lists.rb +0 -500
- data/lib/twitter/rest/api/oauth.rb +0 -67
- data/lib/twitter/rest/api/places_and_geo.rb +0 -86
- data/lib/twitter/rest/api/saved_searches.rb +0 -95
- data/lib/twitter/rest/api/search.rb +0 -39
- data/lib/twitter/rest/api/spam_reporting.rb +0 -29
- data/lib/twitter/rest/api/suggested_users.rb +0 -51
- data/lib/twitter/rest/api/timelines.rb +0 -202
- data/lib/twitter/rest/api/trends.rb +0 -58
- data/lib/twitter/rest/api/tweets.rb +0 -297
- data/lib/twitter/rest/api/undocumented.rb +0 -51
- data/lib/twitter/rest/api/users.rb +0 -383
- data/lib/twitter/rest/api/utils.rb +0 -212
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
require 'addressable/uri'
|
|
2
|
-
require 'twitter/arguments'
|
|
3
|
-
require 'twitter/request'
|
|
4
|
-
require 'twitter/user'
|
|
5
|
-
require 'twitter/utils'
|
|
6
|
-
|
|
7
|
-
module Twitter
|
|
8
|
-
module REST
|
|
9
|
-
module API
|
|
10
|
-
module Utils
|
|
11
|
-
include Twitter::Utils
|
|
12
|
-
URI_SUBSTRING = '://'
|
|
13
|
-
DEFAULT_CURSOR = -1
|
|
14
|
-
|
|
15
|
-
private
|
|
16
|
-
|
|
17
|
-
# Take a URI string or Twitter::Identity object and return its ID
|
|
18
|
-
#
|
|
19
|
-
# @param object [Integer, String, URI, Twitter::Identity] An ID, URI, or object.
|
|
20
|
-
# @return [Integer]
|
|
21
|
-
def extract_id(object)
|
|
22
|
-
case object
|
|
23
|
-
when ::Integer
|
|
24
|
-
object
|
|
25
|
-
when ::String
|
|
26
|
-
object.split('/').last.to_i
|
|
27
|
-
when URI
|
|
28
|
-
object.path.split('/').last.to_i
|
|
29
|
-
when Twitter::Identity
|
|
30
|
-
object.id
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# @param request_method [Symbol]
|
|
35
|
-
# @param path [String]
|
|
36
|
-
# @param options [Hash]
|
|
37
|
-
# @param klass [Class]
|
|
38
|
-
def perform_with_object(request_method, path, options, klass)
|
|
39
|
-
request = Twitter::Request.new(self, request_method, path, options)
|
|
40
|
-
request.perform_with_object(klass)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# @param request_method [Symbol]
|
|
44
|
-
# @param path [String]
|
|
45
|
-
# @param options [Hash]
|
|
46
|
-
# @param klass [Class]
|
|
47
|
-
def perform_with_objects(request_method, path, options, klass)
|
|
48
|
-
request = Twitter::Request.new(self, request_method, path, options)
|
|
49
|
-
request.perform_with_objects(klass)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
# @param request_method [Symbol]
|
|
53
|
-
# @param path [String]
|
|
54
|
-
# @param options [Hash]
|
|
55
|
-
# @param klass [Class]
|
|
56
|
-
def perform_with_cursor(request_method, path, options, collection_name, klass = nil) # rubocop:disable ParameterLists
|
|
57
|
-
merge_default_cursor!(options)
|
|
58
|
-
request = Twitter::Request.new(self, request_method, path, options)
|
|
59
|
-
request.perform_with_cursor(collection_name.to_sym, klass)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
# @param request_method [Symbol]
|
|
63
|
-
# @param path [String]
|
|
64
|
-
# @param args [Array]
|
|
65
|
-
# @return [Array<Twitter::User>]
|
|
66
|
-
def parallel_user_objects_from_response(request_method, path, args)
|
|
67
|
-
arguments = Twitter::Arguments.new(args)
|
|
68
|
-
parallel_map(arguments) do |user|
|
|
69
|
-
perform_with_object(request_method, path, merge_user(arguments.options, user), Twitter::User)
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
# @param request_method [Symbol]
|
|
74
|
-
# @param path [String]
|
|
75
|
-
# @param args [Array]
|
|
76
|
-
# @return [Array<Twitter::User>]
|
|
77
|
-
def user_objects_from_response(request_method, path, args)
|
|
78
|
-
arguments = Twitter::Arguments.new(args)
|
|
79
|
-
merge_user!(arguments.options, arguments.pop || screen_name) unless arguments.options[:user_id] || arguments.options[:screen_name]
|
|
80
|
-
perform_with_objects(request_method, path, arguments.options, Twitter::User)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
# @param klass [Class]
|
|
84
|
-
# @param request_method [Symbol]
|
|
85
|
-
# @param path [String]
|
|
86
|
-
# @param args [Array]
|
|
87
|
-
# @return [Array]
|
|
88
|
-
def objects_from_response_with_user(klass, request_method, path, args)
|
|
89
|
-
arguments = Twitter::Arguments.new(args)
|
|
90
|
-
merge_user!(arguments.options, arguments.pop)
|
|
91
|
-
perform_with_objects(request_method, path, arguments.options, klass)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
# @param klass [Class]
|
|
95
|
-
# @param request_method [Symbol]
|
|
96
|
-
# @param path [String]
|
|
97
|
-
# @param args [Array]
|
|
98
|
-
# @return [Array]
|
|
99
|
-
def parallel_objects_from_response(klass, request_method, path, args)
|
|
100
|
-
arguments = Twitter::Arguments.new(args)
|
|
101
|
-
parallel_map(arguments) do |object|
|
|
102
|
-
perform_with_object(request_method, path, arguments.options.merge(:id => extract_id(object)), klass)
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
# @param collection_name [Symbol]
|
|
107
|
-
# @param klass [Class]
|
|
108
|
-
# @param request_method [Symbol]
|
|
109
|
-
# @param path [String]
|
|
110
|
-
# @param args [Array]
|
|
111
|
-
# @return [Twitter::Cursor]
|
|
112
|
-
def cursor_from_response_with_user(collection_name, klass, request_method, path, args) # rubocop:disable ParameterLists
|
|
113
|
-
arguments = Twitter::Arguments.new(args)
|
|
114
|
-
merge_user!(arguments.options, arguments.pop || screen_name) unless arguments.options[:user_id] || arguments.options[:screen_name]
|
|
115
|
-
perform_with_cursor(request_method, path, arguments.options, collection_name, klass)
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
def handle_forbidden_error(klass, error)
|
|
119
|
-
error = klass.new(error) if error.message == klass::MESSAGE
|
|
120
|
-
fail(error)
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
def screen_name
|
|
124
|
-
@screen_name ||= verify_credentials.screen_name
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
def merge_default_cursor!(options)
|
|
128
|
-
options[:cursor] = DEFAULT_CURSOR unless options[:cursor]
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
# Take a user and merge it into the hash with the correct key
|
|
132
|
-
#
|
|
133
|
-
# @param hash [Hash]
|
|
134
|
-
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
|
135
|
-
# @return [Hash]
|
|
136
|
-
def merge_user(hash, user, prefix = nil)
|
|
137
|
-
merge_user!(hash.dup, user, prefix)
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
# Take a user and merge it into the hash with the correct key
|
|
141
|
-
#
|
|
142
|
-
# @param hash [Hash]
|
|
143
|
-
# @param user [Integer, String, URI, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
|
144
|
-
# @return [Hash]
|
|
145
|
-
def merge_user!(hash, user, prefix = nil)
|
|
146
|
-
case user
|
|
147
|
-
when Integer
|
|
148
|
-
set_compound_key('user_id', user, hash, prefix)
|
|
149
|
-
when String
|
|
150
|
-
if user[URI_SUBSTRING]
|
|
151
|
-
set_compound_key('screen_name', user.split('/').last, hash, prefix)
|
|
152
|
-
else
|
|
153
|
-
set_compound_key('screen_name', user, hash, prefix)
|
|
154
|
-
end
|
|
155
|
-
when URI, Addressable::URI
|
|
156
|
-
set_compound_key('screen_name', user.path.split('/').last, hash, prefix)
|
|
157
|
-
when Twitter::User
|
|
158
|
-
set_compound_key('user_id', user.id, hash, prefix)
|
|
159
|
-
end
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
def set_compound_key(key, value, hash, prefix = nil)
|
|
163
|
-
compound_key = [prefix, key].compact.join('_').to_sym
|
|
164
|
-
hash[compound_key] = value
|
|
165
|
-
hash
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
# Take a multiple users and merge them into the hash with the correct keys
|
|
169
|
-
#
|
|
170
|
-
# @param hash [Hash]
|
|
171
|
-
# @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen_names, or objects.
|
|
172
|
-
# @return [Hash]
|
|
173
|
-
def merge_users(hash, users)
|
|
174
|
-
merge_users!(hash.dup, users)
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
# Take a multiple users and merge them into the hash with the correct keys
|
|
178
|
-
#
|
|
179
|
-
# @param hash [Hash]
|
|
180
|
-
# @param users [Enumerable<Integer, String, URI, Twitter::User>] A collection of Twitter user IDs, screen_names, URIs, or objects.
|
|
181
|
-
# @return [Hash]
|
|
182
|
-
def merge_users!(hash, users)
|
|
183
|
-
user_ids, screen_names = collect_user_ids_and_screen_names(users)
|
|
184
|
-
hash[:user_id] = user_ids.join(',') unless user_ids.empty?
|
|
185
|
-
hash[:screen_name] = screen_names.join(',') unless screen_names.empty?
|
|
186
|
-
hash
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
def collect_user_ids_and_screen_names(users) # rubocop:disable MethodLength
|
|
190
|
-
user_ids, screen_names = [], []
|
|
191
|
-
users.flatten.each do |user|
|
|
192
|
-
case user
|
|
193
|
-
when Integer
|
|
194
|
-
user_ids << user
|
|
195
|
-
when String
|
|
196
|
-
if user[URI_SUBSTRING]
|
|
197
|
-
screen_names << user.split('/').last
|
|
198
|
-
else
|
|
199
|
-
screen_names << user
|
|
200
|
-
end
|
|
201
|
-
when URI
|
|
202
|
-
screen_names << user.path.split('/').last
|
|
203
|
-
when Twitter::User
|
|
204
|
-
user_ids << user.id
|
|
205
|
-
end
|
|
206
|
-
end
|
|
207
|
-
[user_ids, screen_names]
|
|
208
|
-
end
|
|
209
|
-
end
|
|
210
|
-
end
|
|
211
|
-
end
|
|
212
|
-
end
|