twitter_with_auto_pagination 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/twitter_with_auto_pagination/rest/favorites.rb +1 -1
- data/lib/twitter_with_auto_pagination/rest/friends_and_followers.rb +2 -4
- data/lib/twitter_with_auto_pagination/rest/search.rb +1 -2
- data/lib/twitter_with_auto_pagination/rest/timelines.rb +3 -3
- data/lib/twitter_with_auto_pagination/rest/users.rb +3 -3
- data/lib/twitter_with_auto_pagination/rest/utils.rb +18 -123
- data/twitter_with_auto_pagination.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 842345d2afa01f05557856bde019188e1ffe7183
|
4
|
+
data.tar.gz: ea0998abb411f7c0668ed9dbdff054fde3ef7c9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8cff32cee7e020cb481428a24acf78b325464b4064ede0e71066681bd7bec297b305f0c0b7c6ffa2bfb99aaf410db23fb299eed5841ccc2c9b4fea6c4b5bd58
|
7
|
+
data.tar.gz: beb7cc9f6678583ce5ba52b6c33f4d1a4d0ff0643a883d30dcee9db105a3caef0a7e8a994ccabd24c63525d5ea47a8fb51f69bc5f7c940a0d17469e71efbcc59
|
@@ -11,7 +11,7 @@ module TwitterWithAutoPagination
|
|
11
11
|
args[0] = verify_credentials.id if args.empty?
|
12
12
|
instrument(__method__, nil, options) do
|
13
13
|
fetch_cache_or_call_api(__method__, args[0], options) do
|
14
|
-
collect_with_max_id(method(__method__).super_method, *args, options)
|
14
|
+
collect_with_max_id(method(__method__).super_method, *args, options).map { |s| s.attrs }
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -46,11 +46,10 @@ module TwitterWithAutoPagination
|
|
46
46
|
|
47
47
|
def _friends_serially(*args)
|
48
48
|
options = {count: 200, include_user_entities: true, cursor: -1}.merge(args.extract_options!)
|
49
|
-
options[:reduce] = false unless options.has_key?(:reduce)
|
50
49
|
args[0] = verify_credentials.id if args.empty?
|
51
50
|
instrument(__method__, nil, options) do
|
52
51
|
fetch_cache_or_call_api(:friends, args[0], options) do
|
53
|
-
collect_with_cursor(method(:friends).super_method, *args, options)
|
52
|
+
collect_with_cursor(method(:friends).super_method, *args, options).map { |u| u.to_hash }
|
54
53
|
end
|
55
54
|
end
|
56
55
|
end
|
@@ -74,11 +73,10 @@ module TwitterWithAutoPagination
|
|
74
73
|
|
75
74
|
def _followers_serially(*args)
|
76
75
|
options = {count: 200, include_user_entities: true, cursor: -1}.merge(args.extract_options!)
|
77
|
-
options[:reduce] = false unless options.has_key?(:reduce)
|
78
76
|
args[0] = verify_credentials.id if args.empty?
|
79
77
|
instrument(__method__, nil, options) do
|
80
78
|
fetch_cache_or_call_api(:followers, args[0], options) do
|
81
|
-
collect_with_cursor(method(:followers).super_method, *args, options)
|
79
|
+
collect_with_cursor(method(:followers).super_method, *args, options).map { |u| u.to_hash }
|
82
80
|
end
|
83
81
|
end
|
84
82
|
end
|
@@ -7,10 +7,9 @@ module TwitterWithAutoPagination
|
|
7
7
|
|
8
8
|
def search(*args)
|
9
9
|
options = {count: 100, result_type: :recent, call_limit: 1}.merge(args.extract_options!)
|
10
|
-
options[:reduce] = false
|
11
10
|
instrument(__method__, nil, options) do
|
12
11
|
fetch_cache_or_call_api(__method__, args[0], options) do
|
13
|
-
collect_with_max_id(method(__method__).super_method, *args, options) { |response| response.attrs[:statuses] }
|
12
|
+
collect_with_max_id(method(__method__).super_method, *args, options) { |response| response.attrs[:statuses] }.map { |s| s.to_hash }
|
14
13
|
end
|
15
14
|
end
|
16
15
|
end
|
@@ -9,7 +9,7 @@ module TwitterWithAutoPagination
|
|
9
9
|
options = {count: 200, include_rts: true, call_limit: 3}.merge(args.extract_options!)
|
10
10
|
instrument(__method__, nil, options) do
|
11
11
|
fetch_cache_or_call_api(__method__, verify_credentials.id, options) do
|
12
|
-
collect_with_max_id(method(__method__).super_method, options)
|
12
|
+
collect_with_max_id(method(__method__).super_method, options).map { |s| s.attrs }
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -19,7 +19,7 @@ module TwitterWithAutoPagination
|
|
19
19
|
args[0] = verify_credentials.id if args.empty?
|
20
20
|
instrument(__method__, nil, options) do
|
21
21
|
fetch_cache_or_call_api(__method__, args[0], options) do
|
22
|
-
collect_with_max_id(method(__method__).super_method, *args, options)
|
22
|
+
collect_with_max_id(method(__method__).super_method, *args, options).map { |s| s.attrs }
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -28,7 +28,7 @@ module TwitterWithAutoPagination
|
|
28
28
|
options = {count: 200, include_rts: true, call_limit: 1}.merge(args.extract_options!)
|
29
29
|
instrument(__method__, nil, options) do
|
30
30
|
fetch_cache_or_call_api(__method__, verify_credentials.id, options) do
|
31
|
-
collect_with_max_id(method(__method__).super_method, options)
|
31
|
+
collect_with_max_id(method(__method__).super_method, options).map { |s| s.attrs }
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -10,7 +10,7 @@ module TwitterWithAutoPagination
|
|
10
10
|
options = {skip_status: true}.merge(args.extract_options!)
|
11
11
|
instrument(__method__, nil, options) do
|
12
12
|
fetch_cache_or_call_api(__method__, args) do
|
13
|
-
call_api(method(__method__).super_method, *args, options)
|
13
|
+
call_api(method(__method__).super_method, *args, options).to_hash
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -30,7 +30,7 @@ module TwitterWithAutoPagination
|
|
30
30
|
args[0] = verify_credentials.id if args.empty?
|
31
31
|
instrument(__method__, nil, options) do
|
32
32
|
fetch_cache_or_call_api(__method__, args[0], options) do
|
33
|
-
call_api(method(__method__).super_method, *args, options)
|
33
|
+
call_api(method(__method__).super_method, *args, options).to_hash
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -48,7 +48,7 @@ module TwitterWithAutoPagination
|
|
48
48
|
instrument(__method__, nil, options) do
|
49
49
|
Parallel.each_with_index(users_per_workers, in_threads: thread_size) do |users_per_worker, i|
|
50
50
|
_users = fetch_cache_or_call_api(__method__, users_per_worker, options) do
|
51
|
-
call_api(method(__method__).super_method, users_per_worker, options)
|
51
|
+
call_api(method(__method__).super_method, users_per_worker, options).map { |u| u.to_hash }
|
52
52
|
end
|
53
53
|
|
54
54
|
processed_users << {i: i, users: _users}
|
@@ -132,7 +132,8 @@ module TwitterWithAutoPagination
|
|
132
132
|
"#{options[:super_operation]}-ids#{delim}#{Digest::MD5.hexdigest(user.join(','))}"
|
133
133
|
when user.kind_of?(Array) && user.first.kind_of?(String)
|
134
134
|
"#{options[:super_operation]}-sns#{delim}#{Digest::MD5.hexdigest(user.join(','))}"
|
135
|
-
else
|
135
|
+
else
|
136
|
+
raise "#{method_name.inspect} #{user.inspect}"
|
136
137
|
end
|
137
138
|
when user.kind_of?(Integer)
|
138
139
|
"id#{delim}#{user.to_s}"
|
@@ -144,7 +145,8 @@ module TwitterWithAutoPagination
|
|
144
145
|
"sn#{delim}#{user}"
|
145
146
|
when user.kind_of?(Twitter::User)
|
146
147
|
"user#{delim}#{user.id.to_s}"
|
147
|
-
else
|
148
|
+
else
|
149
|
+
raise "#{method_name.inspect} #{user.inspect}"
|
148
150
|
end
|
149
151
|
|
150
152
|
"#{method_name}#{delim}#{identifier}"
|
@@ -154,132 +156,25 @@ module TwitterWithAutoPagination
|
|
154
156
|
file_cache_key(method_name, user, options)
|
155
157
|
end
|
156
158
|
|
157
|
-
|
158
|
-
id
|
159
|
-
name
|
160
|
-
screen_name
|
161
|
-
location
|
162
|
-
description
|
163
|
-
url
|
164
|
-
protected
|
165
|
-
followers_count
|
166
|
-
friends_count
|
167
|
-
listed_count
|
168
|
-
favourites_count
|
169
|
-
utc_offset
|
170
|
-
time_zone
|
171
|
-
geo_enabled
|
172
|
-
verified
|
173
|
-
statuses_count
|
174
|
-
lang
|
175
|
-
status
|
176
|
-
profile_image_url_https
|
177
|
-
profile_banner_url
|
178
|
-
profile_link_color
|
179
|
-
suspended
|
180
|
-
verified
|
181
|
-
entities
|
182
|
-
created_at
|
183
|
-
)
|
159
|
+
CODER = JSON
|
184
160
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
text
|
189
|
-
source
|
190
|
-
truncated
|
191
|
-
coordinates
|
192
|
-
place
|
193
|
-
entities
|
194
|
-
user
|
195
|
-
contributors
|
196
|
-
is_quote_status
|
197
|
-
retweet_count
|
198
|
-
favorite_count
|
199
|
-
favorited
|
200
|
-
retweeted
|
201
|
-
possibly_sensitive
|
202
|
-
lang
|
203
|
-
)
|
204
|
-
|
205
|
-
# encode
|
206
|
-
def encode_json(obj, caller_name, options = {})
|
207
|
-
options[:reduce] = true unless options.has_key?(:reduce)
|
208
|
-
case caller_name
|
209
|
-
when :user_timeline, :home_timeline, :mentions_timeline, :favorites # Twitter::Tweet
|
210
|
-
JSON.pretty_generate(obj.map { |o| o.attrs })
|
211
|
-
|
212
|
-
when :search # Hash
|
213
|
-
data =
|
214
|
-
if options[:reduce]
|
215
|
-
obj.map { |o| o.to_hash.slice(*STATUS_SAVE_KEYS) }
|
216
|
-
else
|
217
|
-
obj.map { |o| o.to_hash }
|
218
|
-
end
|
219
|
-
JSON.pretty_generate(data)
|
220
|
-
|
221
|
-
when :friends, :followers # Hash
|
222
|
-
data =
|
223
|
-
if options[:reduce]
|
224
|
-
obj.map { |o| o.to_hash.slice(*PROFILE_SAVE_KEYS) }
|
225
|
-
else
|
226
|
-
obj.map { |o| o.to_hash }
|
227
|
-
end
|
228
|
-
JSON.pretty_generate(data)
|
229
|
-
|
230
|
-
when :friend_ids, :follower_ids # Integer
|
231
|
-
JSON.pretty_generate(obj)
|
232
|
-
|
233
|
-
when :verify_credentials # Twitter::User
|
234
|
-
JSON.pretty_generate(obj.to_hash.slice(*PROFILE_SAVE_KEYS))
|
235
|
-
|
236
|
-
when :user # Twitter::User
|
237
|
-
JSON.pretty_generate(obj.to_hash.slice(*PROFILE_SAVE_KEYS))
|
238
|
-
|
239
|
-
when :users, :friends_parallelly, :followers_parallelly # Twitter::User
|
240
|
-
data =
|
241
|
-
if options[:reduce]
|
242
|
-
obj.map { |o| o.to_hash.slice(*PROFILE_SAVE_KEYS) }
|
243
|
-
else
|
244
|
-
obj.map { |o| o.to_hash }
|
245
|
-
end
|
246
|
-
JSON.pretty_generate(data)
|
247
|
-
|
248
|
-
when :user? # true or false
|
249
|
-
obj
|
250
|
-
|
251
|
-
when :friendship? # true or false
|
252
|
-
obj
|
161
|
+
def encode(obj)
|
162
|
+
obj.in?([true, false]) ? obj : CODER.dump(obj)
|
163
|
+
end
|
253
164
|
|
254
|
-
|
255
|
-
|
256
|
-
|
165
|
+
def decode(str)
|
166
|
+
obj = str.kind_of?(String) ? CODER.load(str) : str
|
167
|
+
_to_mash(obj)
|
257
168
|
end
|
258
169
|
|
259
|
-
|
260
|
-
def decode_json(json_str, caller_name, options = {})
|
261
|
-
obj = json_str.kind_of?(String) ? JSON.parse(json_str) : json_str
|
170
|
+
def _to_mash(obj)
|
262
171
|
case
|
263
|
-
when obj.
|
264
|
-
obj
|
265
|
-
|
266
|
-
when obj.kind_of?(Array) && obj.first.kind_of?(Hash)
|
267
|
-
obj.map { |o| Hashie::Mash.new(o) }
|
268
|
-
|
269
|
-
when obj.kind_of?(Array) && obj.first.kind_of?(Integer)
|
270
|
-
obj
|
271
|
-
|
172
|
+
when obj.kind_of?(Array)
|
173
|
+
obj.map { |o| _to_mash(o) }
|
272
174
|
when obj.kind_of?(Hash)
|
273
|
-
Hashie::Mash.new(obj)
|
274
|
-
|
275
|
-
when obj === true || obj === false
|
276
|
-
obj
|
277
|
-
|
278
|
-
when obj.kind_of?(Array) && obj.empty?
|
279
|
-
obj
|
280
|
-
|
175
|
+
Hashie::Mash.new(obj.map { |k, v| [k, _to_mash(v)] }.to_h)
|
281
176
|
else
|
282
|
-
|
177
|
+
obj
|
283
178
|
end
|
284
179
|
end
|
285
180
|
|
@@ -292,11 +187,11 @@ module TwitterWithAutoPagination
|
|
292
187
|
else
|
293
188
|
cache.fetch(key, expires_in: 1.hour, race_condition_ttl: 5.minutes) do
|
294
189
|
block_result = yield
|
295
|
-
instrument('serialize', key, caller: method_name) {
|
190
|
+
instrument('serialize', key, caller: method_name) { encode(block_result) }
|
296
191
|
end
|
297
192
|
end
|
298
193
|
|
299
|
-
instrument('deserialize', key, caller: method_name) {
|
194
|
+
instrument('deserialize', key, caller: method_name) { decode(fetch_result) }
|
300
195
|
end
|
301
196
|
end
|
302
197
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter_with_auto_pagination
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shinohara Teruki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: twitter
|