twitter_friendly 1.2.1 → 1.2.2

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: 810019b532f5f365b544ca6e0a0066717794b8975b59ae0a840b74f44377bff6
4
- data.tar.gz: 75f3b7052fa926da7457b53f71d0f2f6e08496efd02042750681678b53d351dd
3
+ metadata.gz: 6d4ae87e3b1ed7b257a212dae005fdf20a22809e067fda985c34799067afcf3a
4
+ data.tar.gz: 75a2a81a104a3a69dc6cb2a0fd46cf005501cca76955ff31b8c7681aea8c103f
5
5
  SHA512:
6
- metadata.gz: '08a9a4ef337d993f1cb3bb6689df73d67b5adc74576214206774c5dc2b720e0ef66c30a376c2d122c4a70d7dc85661f6114508ad0e030819f52a0c65370a3033'
7
- data.tar.gz: f26d6b48033db9dc96752a55c12a5e7ffe1c3610773f0014af8d1a69b4c84384de5eec858c204634212c1e205b2579ec6cf689a8dd0cdf634031a65510520ca4
6
+ metadata.gz: 3c1772f3b904c93a14871d4e59692c9f4465965f0007d08ebdde28fc368ca692af20d100046a7ae9f50f419f505a6836d03833930b1c94739255454b61bf57d9
7
+ data.tar.gz: 9153c013954336b682e82429049389e0f1c09f68fb6927cb40949ebcec5c80e816a48990c177cd7c94c61fa051d198eee5fe5ae87a29de864806ef169363d9e7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- twitter_friendly (1.2.1)
4
+ twitter_friendly (1.2.2)
5
5
  activesupport (>= 4.2, < 6.0)
6
6
  oj (~> 3.7.6)
7
7
  parallel (~> 1.12.1)
data/Rakefile CHANGED
@@ -1,2 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
+
2
3
  task :default => :spec
4
+
5
+ begin
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ rescue LoadError
9
+ end
@@ -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
- result = send(method_name, *args)
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
- collection.concat tweets
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
- collection.concat (response[:ids] || response[:users] || response[:lists])
64
- response[:next_cursor].zero? ? collection.flatten : collect_with_cursor(collection, response[:next_cursor], &block)
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)
@@ -1,3 +1,3 @@
1
1
  module TwitterFriendly
2
- VERSION = "1.2.1"
2
+ VERSION = "1.2.2"
3
3
  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: 1.2.1
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-15 00:00:00.000000000 Z
11
+ date: 2019-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport