twitter_friendly 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/Rakefile +7 -0
- data/lib/twitter_friendly/rest/collector.rb +15 -25
- data/lib/twitter_friendly/rest/search.rb +2 -0
- data/lib/twitter_friendly/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d4ae87e3b1ed7b257a212dae005fdf20a22809e067fda985c34799067afcf3a
|
4
|
+
data.tar.gz: 75a2a81a104a3a69dc6cb2a0fd46cf005501cca76955ff31b8c7681aea8c103f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c1772f3b904c93a14871d4e59692c9f4465965f0007d08ebdde28fc368ca692af20d100046a7ae9f50f419f505a6836d03833930b1c94739255454b61bf57d9
|
7
|
+
data.tar.gz: 9153c013954336b682e82429049389e0f1c09f68fb6927cb40949ebcec5c80e816a48990c177cd7c94c61fa051d198eee5fe5ae87a29de864806ef169363d9e7
|
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -11,24 +11,10 @@ module TwitterFriendly
|
|
11
11
|
|
12
12
|
collect_with_max_id([], nil, collect_options) do |max_id|
|
13
13
|
options[:max_id] = max_id unless max_id.nil?
|
14
|
-
|
15
|
-
|
16
|
-
if method_name == :search
|
17
|
-
result.attrs[:statuses]
|
18
|
-
else
|
19
|
-
if result.is_a?(Array) && result[0].respond_to?(:attrs)
|
20
|
-
result.map(&:attrs)
|
21
|
-
else
|
22
|
-
result
|
23
|
-
end
|
24
|
-
end
|
14
|
+
send(method_name, *args)
|
25
15
|
end
|
26
16
|
end
|
27
17
|
|
28
|
-
# @param method_name [Symbol]
|
29
|
-
# @param user [Integer, String, nil]
|
30
|
-
#
|
31
|
-
# @option options [Integer] :count
|
32
18
|
def fetch_resources_with_cursor(method_name, *args)
|
33
19
|
options = args.dup.extract_options!
|
34
20
|
|
@@ -38,30 +24,34 @@ module TwitterFriendly
|
|
38
24
|
end
|
39
25
|
end
|
40
26
|
|
27
|
+
private
|
28
|
+
|
41
29
|
def collect_with_max_id(collection, max_id, collect_options, &block)
|
42
30
|
tweets = yield(max_id)
|
43
|
-
return collection if tweets.nil?
|
44
31
|
|
45
|
-
|
46
|
-
if tweets.empty? || (collect_options[:call_count] -= 1) < 1
|
32
|
+
if tweets.nil? || tweets.empty? || (collect_options[:call_count] -= 1) < 1
|
47
33
|
collection.flatten
|
48
34
|
else
|
35
|
+
collection.concat(tweets)
|
49
36
|
collect_with_max_id(collection, tweets.last[:id] - 1, collect_options, &block)
|
50
37
|
end
|
51
38
|
end
|
52
39
|
|
53
|
-
# @param user [Integer, String, nil]
|
54
|
-
# @param collection [Array]
|
55
|
-
# @param cursor [Integer]
|
56
|
-
#
|
57
|
-
# @option options [Integer] :count
|
58
40
|
def collect_with_cursor(collection, cursor, &block)
|
59
41
|
response = yield(cursor)
|
60
42
|
return collection if response.nil?
|
61
43
|
|
62
44
|
# Notice: If you call response.to_a, it automatically fetch all results and the results are not cached.
|
63
|
-
|
64
|
-
|
45
|
+
|
46
|
+
# cursor でリクエストするメソッドは cursor ごとキャッシュに保存するので、このメソッドで
|
47
|
+
# ids, users または lists でリソースを取得する必要がある。
|
48
|
+
collection.concat(response[:ids] || response[:users] || response[:lists])
|
49
|
+
|
50
|
+
if response[:next_cursor].zero?
|
51
|
+
collection.flatten
|
52
|
+
else
|
53
|
+
collect_with_cursor(collection, response[:next_cursor], &block)
|
54
|
+
end
|
65
55
|
end
|
66
56
|
end
|
67
57
|
end
|
@@ -9,6 +9,8 @@ module TwitterFriendly
|
|
9
9
|
options = {result_type: 'recent'}.merge(options)
|
10
10
|
|
11
11
|
if options[:count] <= MAX_TWEETS_PER_REQUEST
|
12
|
+
# max_id で次のツイートを取得するので、このメソッドでは statuses を返してよい。
|
13
|
+
# 逆に、cursor で次のツイートを取得するメソッドでは、レスポンス全体を返す必要がある。
|
12
14
|
@twitter.search(query, options)&.attrs&.fetch(:statuses)
|
13
15
|
else
|
14
16
|
fetch_tweets_with_max_id(__method__, MAX_TWEETS_PER_REQUEST, query, options)
|
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: 1.2.
|
4
|
+
version: 1.2.2
|
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-04-
|
11
|
+
date: 2019-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|