twitter_with_auto_pagination 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85b2134eb58d567fcbf7d1d5b73d47f7211a9609
4
- data.tar.gz: 5aede29a942eeabbfe4c810782ef008ea66bf2b5
3
+ metadata.gz: adeef994e42b9c1f9918c03e3bbb9fc01bc9589b
4
+ data.tar.gz: 8632de6d1cb4862d10993a393e29a929ff4512ca
5
5
  SHA512:
6
- metadata.gz: 71d2303c9bd1f795dcc9d5fc284345494a97a9024c9d39ee513adb8fc40b30cf163a078435ef03a2899a85f2f7a0899ab03970617431b418642162344bb59293
7
- data.tar.gz: 588abe185579116532ada869ed9e04730091994d55ce74abafb96edce4d50dd4847301632851d85c5f8c84262b4486b979a3d860cd269e0fadbf607de22c0096
6
+ metadata.gz: e13248d55c2f853622545a24e49b8803f08d21cb8fb0dee51e82d84ba8c775519fd1e32b3f9b309b6ce453eee70bfa0d7dfdd7ba338e8cb7759be5b028aab11a
7
+ data.tar.gz: a894177e7ae82b9c4f808f5643a931553b0be253dcc33848f28ba4a906deece0aa388e4c741e04515ce226fb7bf1078578ea5e8a81f78918b4f499936a99f0ff
@@ -11,7 +11,9 @@ module TwitterWithAutoPagination
11
11
  def collect_with_cursor(collection = [], cursor = nil, &block)
12
12
  response = yield(cursor)
13
13
  return collection if response.nil?
14
- collection += (response.attrs[:ids] || response.attrs[:users] || response.attrs[:lists]) # TODO to_a
14
+
15
+ # Notice: If you call response.to_a, it automatically fetch all results and the results are not cached.
16
+ collection += (response.attrs[:ids] || response.attrs[:users] || response.attrs[:lists])
15
17
  response.attrs[:next_cursor].zero? ? collection.flatten : collect_with_cursor(collection, response.attrs[:next_cursor], &block)
16
18
  end
17
19
  end
@@ -16,7 +16,7 @@ module TwitterWithAutoPagination
16
16
  options = {count: MAX_IDS_PER_REQUEST, cursor: -1}.merge(args.extract_options!)
17
17
 
18
18
  collect_with_cursor do |next_cursor|
19
- options[:next_cursor] = next_cursor unless next_cursor.nil?
19
+ options[:cursor] = next_cursor unless next_cursor.nil?
20
20
  twitter.send(name, *args, options)
21
21
  end
22
22
  end
@@ -10,7 +10,7 @@ module TwitterWithAutoPagination
10
10
  options = {count: 1000, cursor: -1}.merge(args.extract_options!)
11
11
 
12
12
  collect_with_cursor do |next_cursor|
13
- options[:next_cursor] = next_cursor unless next_cursor.nil?
13
+ options[:cursor] = next_cursor unless next_cursor.nil?
14
14
  twitter.send(:memberships, *args, options)
15
15
  end
16
16
  end
@@ -20,7 +20,7 @@ module TwitterWithAutoPagination
20
20
  options = {count: 5000, skip_status: 1, cursor: -1}.merge(args.extract_options!)
21
21
 
22
22
  collect_with_cursor do |next_cursor|
23
- options[:next_cursor] = next_cursor unless next_cursor.nil?
23
+ options[:cursor] = next_cursor unless next_cursor.nil?
24
24
  twitter.send(:list_members, *args, options)
25
25
  end
26
26
  end
@@ -19,6 +19,15 @@ describe TwitterWithAutoPagination::REST::FriendsAndFollowers do
19
19
  }
20
20
  end
21
21
 
22
+ let(:config3) do
23
+ {
24
+ consumer_key: ENV['CK3'],
25
+ consumer_secret: ENV['CS3'],
26
+ access_token: ENV['AT3'],
27
+ access_token_secret: ENV['ATS3']
28
+ }
29
+ end
30
+
22
31
  let(:client) { TwitterWithAutoPagination::Client.new(config) }
23
32
  let(:client2) { TwitterWithAutoPagination::Client.new(config2) }
24
33
 
@@ -28,7 +37,7 @@ describe TwitterWithAutoPagination::REST::FriendsAndFollowers do
28
37
  before do
29
38
  client.cache.clear
30
39
  client.twitter.send(:user_id) # Call verify_credentials
31
- client2.twitter.send(:user_id) # Call verify_credentials
40
+ client2.twitter.send(:user_id)
32
41
  $fetch_called = $request_called = false
33
42
  $fetch_count = $request_count = 0
34
43
  end
@@ -58,6 +67,10 @@ describe TwitterWithAutoPagination::REST::FriendsAndFollowers do
58
67
  describe '#friend_ids' do
59
68
  let(:name) { :friend_ids }
60
69
 
70
+ it 'matches original one' do
71
+ expect(client.friend_ids).to match_twitter(client.twitter.friend_ids.attrs[:ids])
72
+ end
73
+
61
74
  context 'with one param' do
62
75
  let(:params) { [id] }
63
76
  let(:params2) { [id2] }
@@ -88,6 +101,27 @@ describe TwitterWithAutoPagination::REST::FriendsAndFollowers do
88
101
  describe '#follower_ids' do
89
102
  let(:name) { :follower_ids }
90
103
 
104
+ it 'matches original one' do
105
+ expect(client.follower_ids).to match_twitter(client.twitter.follower_ids.attrs[:ids])
106
+ end
107
+
108
+ context 'a user who has too many followers is specified' do
109
+ let(:client) { TwitterWithAutoPagination::Client.new(config3) }
110
+ let(:id) { 187385226 }
111
+ let!(:followers_count) { client.user(id)[:followers_count] }
112
+
113
+ before do
114
+ client.twitter.send(:user_id)
115
+ $fetch_called = $request_called = false
116
+ $fetch_count = $request_count = 0
117
+ end
118
+
119
+ it 'automatically fetches all followers' do
120
+ request_count = followers_count / 5000 + (followers_count % 5000 == 0 ? 0 : 1)
121
+ expect { client.follower_ids(id) }.to fetch & request.exactly(request_count).times
122
+ end
123
+ end
124
+
91
125
  context 'with one param' do
92
126
  let(:params) { [id] }
93
127
  let(:params2) { [id2] }
@@ -149,13 +183,21 @@ describe TwitterWithAutoPagination::REST::FriendsAndFollowers do
149
183
  it 'calls #friend_ids_and_follower_ids with unique ids' do
150
184
  expect(client).to receive(:friend_ids_and_follower_ids).with(id, any_args).and_return([[id], [id]])
151
185
  allow(client).to receive(:users_internal).with([id], any_args).and_return([{id: id}])
152
- client.friends_and_followers(id)
186
+
187
+ friends, followers = client.friends_and_followers(id)
188
+
189
+ expect(friends).to match_twitter([{id: id}])
190
+ expect(followers).to match_twitter([{id: id}])
153
191
  end
154
192
 
155
193
  it 'calls #users_internal with unique ids' do
156
194
  allow(client).to receive(:friend_ids_and_follower_ids).with(id, any_args).and_return([[id], [id]])
157
195
  expect(client).to receive(:users_internal).with([id], any_args).and_return([{id: id}])
158
- client.friends_and_followers(id)
196
+
197
+ friends, followers = client.friends_and_followers(id)
198
+
199
+ expect(friends).to match_twitter([{id: id}])
200
+ expect(followers).to match_twitter([{id: id}])
159
201
  end
160
202
  end
161
203
  end
@@ -21,5 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.required_ruby_version = '>= 2.3'
22
22
  spec.summary = spec.description
23
23
  spec.test_files = Dir.glob('spec/**/*')
24
- spec.version = '0.9.4'
24
+ spec.version = '0.9.5'
25
25
  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.9.4
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shinohara Teruki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-27 00:00:00.000000000 Z
11
+ date: 2017-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: twitter