twitter_friendly 1.2.3 → 2.0.0.pre.alpha
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 317720f96610724f2d1aaf2009fc7aab40edf8fd207a82601066dfd83541eab5
|
4
|
+
data.tar.gz: 0e055652b985fbf44344683e6b6dbdf2e823f9303e9a581faad23020a303f826
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b4ca53a272e37c0184b838660b8800ef31353757627d392a97c823bb477b58b7564dfa022af0a425dfb55dfe266c642680f604d6b5875a797362ecf4ac86ded
|
7
|
+
data.tar.gz: 2d54d1bd9019648b03ff517a65d43b1bae25c71c55ebf5694184eb890fb879ca717588cfe7de35fc107c83e9d88cba8dfe570205ad3fed1af344b21964a13230
|
data/Gemfile.lock
CHANGED
data/bin/console
CHANGED
@@ -7,8 +7,8 @@ require "twitter_friendly"
|
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
9
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
|
11
|
-
|
10
|
+
require "pry"
|
11
|
+
Pry.start
|
12
12
|
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|
13
|
+
# require "irb"
|
14
|
+
# IRB.start(__FILE__)
|
@@ -15,10 +15,15 @@ module TwitterFriendly
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def fetch_resources_with_cursor(method_name, *args)
|
18
|
+
def fetch_resources_with_cursor(method_name, max_count, *args)
|
19
19
|
options = args.dup.extract_options!
|
20
20
|
|
21
|
-
|
21
|
+
total_count = options.delete(:count) || max_count
|
22
|
+
call_count = total_count / max_count + (total_count % max_count == 0 ? 0 : 1)
|
23
|
+
options[:count] = [max_count, total_count].min
|
24
|
+
collect_options = {call_count: call_count, total_count: total_count}
|
25
|
+
|
26
|
+
collect_with_cursor([], -1, collect_options) do |next_cursor|
|
22
27
|
options[:cursor] = next_cursor unless next_cursor.nil?
|
23
28
|
send(method_name, *args)
|
24
29
|
end
|
@@ -37,20 +42,27 @@ module TwitterFriendly
|
|
37
42
|
end
|
38
43
|
end
|
39
44
|
|
40
|
-
def collect_with_cursor(collection, cursor, &block)
|
45
|
+
def collect_with_cursor(collection, cursor, collect_options, &block)
|
41
46
|
response = yield(cursor)
|
42
|
-
|
47
|
+
if response.nil?
|
48
|
+
logger.warn "#{__method__}: response is nil." if respond_to?(:logger)
|
49
|
+
return collection
|
50
|
+
end
|
43
51
|
|
44
52
|
# Notice: If you call response.to_a, it automatically fetch all results and the results are not cached.
|
45
53
|
|
46
54
|
# cursor でリクエストするメソッドは cursor ごとキャッシュに保存するので、このメソッドで
|
47
55
|
# ids, users または lists でリソースを取得する必要がある。
|
48
|
-
|
56
|
+
fetched_resources = response[:ids] || response[:users] || response[:lists]
|
57
|
+
if fetched_resources.nil? || fetched_resources.empty?
|
58
|
+
logger.warn "#{__method__}: fetched_resources is nil or empty." if respond_to?(:logger)
|
59
|
+
end
|
60
|
+
collection.concat(fetched_resources)
|
49
61
|
|
50
|
-
if response[:next_cursor].zero?
|
62
|
+
if response[:next_cursor].zero? || (collect_options[:call_count] -= 1) < 1
|
51
63
|
collection.flatten
|
52
64
|
else
|
53
|
-
collect_with_cursor(collection, response[:next_cursor], &block)
|
65
|
+
collect_with_cursor(collection, response[:next_cursor], collect_options, &block)
|
54
66
|
end
|
55
67
|
end
|
56
68
|
end
|
@@ -24,7 +24,7 @@ module TwitterFriendly
|
|
24
24
|
if options.has_key?(:cursor)
|
25
25
|
@twitter.friend_ids(*args)&.attrs
|
26
26
|
else
|
27
|
-
fetch_resources_with_cursor(__method__, *args)
|
27
|
+
fetch_resources_with_cursor(__method__, MAX_IDS_PER_REQUEST, *args)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -35,7 +35,7 @@ module TwitterFriendly
|
|
35
35
|
if options.has_key?(:cursor)
|
36
36
|
@twitter.follower_ids(*args)&.attrs
|
37
37
|
else
|
38
|
-
fetch_resources_with_cursor(__method__, *args)
|
38
|
+
fetch_resources_with_cursor(__method__, MAX_IDS_PER_REQUEST, *args)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -23,7 +23,7 @@ module TwitterFriendly
|
|
23
23
|
if options.has_key?(:cursor)
|
24
24
|
@twitter.memberships(*args)&.attrs
|
25
25
|
else
|
26
|
-
fetch_resources_with_cursor(__method__, *args)
|
26
|
+
fetch_resources_with_cursor(__method__, MAX_LISTS_PER_REQUEST, *args)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -44,7 +44,7 @@ module TwitterFriendly
|
|
44
44
|
if options.has_key?(:cursor)
|
45
45
|
@twitter.list_members(*args)&.attrs
|
46
46
|
else
|
47
|
-
fetch_resources_with_cursor(__method__, *args)
|
47
|
+
fetch_resources_with_cursor(__method__, MAX_MEMBERS_PER_REQUEST, *args)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter_friendly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.pre.alpha
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ts-3156
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|