twitter_with_auto_pagination 0.8.12 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/twitter_with_auto_pagination/analysis/api.rb +9 -0
  3. data/lib/twitter_with_auto_pagination/{rest/uncategorized.rb → analysis/timelines.rb} +2 -2
  4. data/lib/twitter_with_auto_pagination/cache.rb +78 -0
  5. data/lib/twitter_with_auto_pagination/caching_and_logging.rb +80 -0
  6. data/lib/twitter_with_auto_pagination/client.rb +57 -0
  7. data/lib/twitter_with_auto_pagination/collector.rb +18 -0
  8. data/lib/twitter_with_auto_pagination/log_subscriber.rb +59 -26
  9. data/lib/twitter_with_auto_pagination/logger.rb +10 -0
  10. data/lib/twitter_with_auto_pagination/parallel.rb +25 -0
  11. data/lib/twitter_with_auto_pagination/rate_limit.rb +56 -0
  12. data/lib/twitter_with_auto_pagination/rest/api.rb +16 -14
  13. data/lib/twitter_with_auto_pagination/rest/extension/friends_and_followers.rb +0 -7
  14. data/lib/twitter_with_auto_pagination/rest/favorites.rb +13 -7
  15. data/lib/twitter_with_auto_pagination/rest/friends_and_followers.rb +33 -70
  16. data/lib/twitter_with_auto_pagination/rest/lists.rb +10 -9
  17. data/lib/twitter_with_auto_pagination/rest/search.rb +16 -6
  18. data/lib/twitter_with_auto_pagination/rest/timelines.rb +13 -26
  19. data/lib/twitter_with_auto_pagination/rest/users.rb +27 -40
  20. data/lib/twitter_with_auto_pagination/rest/utils.rb +29 -149
  21. data/lib/twitter_with_auto_pagination/serializer.rb +27 -0
  22. data/lib/twitter_with_auto_pagination.rb +2 -38
  23. data/spec/helper.rb +167 -36
  24. data/spec/twitter_with_auto_pagination/cache_spec.rb +71 -0
  25. data/spec/twitter_with_auto_pagination/client_spec.rb +7 -145
  26. data/spec/twitter_with_auto_pagination/parallel_spec.rb +23 -0
  27. data/spec/twitter_with_auto_pagination/rest/favorites_spec.rb +58 -0
  28. data/spec/twitter_with_auto_pagination/rest/friends_and_followers_spec.rb +161 -0
  29. data/spec/twitter_with_auto_pagination/rest/lists_spec.rb +39 -0
  30. data/spec/twitter_with_auto_pagination/rest/search_spec.rb +42 -0
  31. data/spec/twitter_with_auto_pagination/rest/timelines_spec.rb +82 -0
  32. data/spec/twitter_with_auto_pagination/rest/users_spec.rb +143 -0
  33. data/twitter_with_auto_pagination.gemspec +1 -1
  34. metadata +28 -3
@@ -0,0 +1,161 @@
1
+ require 'helper'
2
+
3
+ describe TwitterWithAutoPagination::REST::FriendsAndFollowers do
4
+ let(:config) do
5
+ {
6
+ consumer_key: ENV['CK'],
7
+ consumer_secret: ENV['CS'],
8
+ access_token: ENV['AT'],
9
+ access_token_secret: ENV['ATS']
10
+ }
11
+ end
12
+
13
+ let(:config2) do
14
+ {
15
+ consumer_key: ENV['CK2'],
16
+ consumer_secret: ENV['CS2'],
17
+ access_token: ENV['AT2'],
18
+ access_token_secret: ENV['ATS2']
19
+ }
20
+ end
21
+
22
+ let(:client) { TwitterWithAutoPagination::Client.new(config) }
23
+ let(:client2) { TwitterWithAutoPagination::Client.new(config2) }
24
+
25
+ let(:id) { 58135830 }
26
+ let(:id2) { 22356250 }
27
+
28
+ before do
29
+ client.cache.clear
30
+ client.twitter.send(:user_id) # Call verify_credentials
31
+ client2.twitter.send(:user_id) # Call verify_credentials
32
+ $fetch_called = $request_called = false
33
+ $fetch_count = $request_count = 0
34
+ end
35
+
36
+ describe '#friendship?' do
37
+ let(:name) { :friendship? }
38
+ let(:params) { [id, id2] }
39
+ let(:params2) { [id2, id] }
40
+
41
+ it_behaves_like 'continuous calls'
42
+ it_behaves_like 'cache: false is specified'
43
+ it_behaves_like 'when a value is changed'
44
+ it_behaves_like 'when options are changed'
45
+ it_behaves_like 'when a client is changed, it shares a cache'
46
+ it_behaves_like 'when any params is not specified, it raises an exception'
47
+
48
+ context '`from` is not changed and `to` is changed' do
49
+ let(:id3) { 165085148 }
50
+
51
+ it 'it does not share a cache' do
52
+ expect { client.friendship?(id, id2) }.to fetch & request
53
+ expect { client2.friendship?(id, id3) }.to fetch & request
54
+ end
55
+ end
56
+ end
57
+
58
+ describe '#friend_ids' do
59
+ let(:name) { :friend_ids }
60
+
61
+ context 'with one param' do
62
+ let(:params) { [id] }
63
+ let(:params2) { [id2] }
64
+
65
+ it_behaves_like 'continuous calls'
66
+ it_behaves_like 'cache: false is specified'
67
+ it_behaves_like 'when a value is changed'
68
+ it_behaves_like 'when options are changed'
69
+ it_behaves_like 'when a client is changed, it shares a cache'
70
+ end
71
+
72
+ context 'with no params' do
73
+ let(:params) { [] }
74
+
75
+ # Avoid too many requests
76
+ let(:client) { TwitterWithAutoPagination::Client.new(config2) }
77
+ let(:client2) { TwitterWithAutoPagination::Client.new(config) }
78
+
79
+ it_behaves_like 'continuous calls'
80
+ it_behaves_like 'cache: false is specified'
81
+ it_behaves_like 'when options are changed'
82
+ it_behaves_like 'when a client is changed, it does not share a cache'
83
+ end
84
+
85
+ it_behaves_like 'when any params is not specified, it returns a same result as a result with one param'
86
+ end
87
+
88
+ describe '#follower_ids' do
89
+ let(:name) { :follower_ids }
90
+
91
+ context 'with one param' do
92
+ let(:params) { [id] }
93
+ let(:params2) { [id2] }
94
+
95
+ it_behaves_like 'continuous calls'
96
+ it_behaves_like 'cache: false is specified'
97
+ it_behaves_like 'when a value is changed'
98
+ it_behaves_like 'when options are changed'
99
+ it_behaves_like 'when a client is changed, it shares a cache'
100
+ end
101
+
102
+ context 'with no params' do
103
+ let(:params) { [] }
104
+
105
+ # Avoid too many requests
106
+ let(:client) { TwitterWithAutoPagination::Client.new(config2) }
107
+ let(:client2) { TwitterWithAutoPagination::Client.new(config) }
108
+
109
+ it_behaves_like 'continuous calls'
110
+ it_behaves_like 'cache: false is specified'
111
+ it_behaves_like 'when options are changed'
112
+ it_behaves_like 'when a client is changed, it does not share a cache'
113
+ end
114
+
115
+ it_behaves_like 'when any params is not specified, it returns a same result as a result with one param'
116
+ end
117
+
118
+ describe '#friends' do
119
+ before do
120
+ allow(client).to receive(:friend_ids).and_return([id])
121
+ end
122
+
123
+ it 'calls #users_internal' do
124
+ expect(client).to receive(:users_internal).with([id], any_args)
125
+ client.friends
126
+ end
127
+ end
128
+
129
+ describe '#followers' do
130
+ before do
131
+ allow(client).to receive(:follower_ids).and_return([id])
132
+ end
133
+
134
+ it 'calls #users_internal' do
135
+ expect(client).to receive(:users_internal).with([id], any_args)
136
+ client.followers
137
+ end
138
+ end
139
+
140
+ describe '#friend_ids_and_follower_ids' do
141
+ it 'calls #friend_ids and #follower_ids' do
142
+ expect(client).to receive(:friend_ids).with(id, any_args)
143
+ expect(client).to receive(:follower_ids).with(id, any_args)
144
+ client.friend_ids_and_follower_ids(id)
145
+ end
146
+ end
147
+
148
+ describe '#friends_and_followers' do
149
+ it 'calls #friend_ids_and_follower_ids with unique ids' do
150
+ expect(client).to receive(:friend_ids_and_follower_ids).with(id, any_args).and_return([[id], [id]])
151
+ allow(client).to receive(:users_internal).with([id], any_args).and_return([{id: id}])
152
+ client.friends_and_followers(id)
153
+ end
154
+
155
+ it 'calls #users_internal with unique ids' do
156
+ allow(client).to receive(:friend_ids_and_follower_ids).with(id, any_args).and_return([[id], [id]])
157
+ expect(client).to receive(:users_internal).with([id], any_args).and_return([{id: id}])
158
+ client.friends_and_followers(id)
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,39 @@
1
+ require 'helper'
2
+
3
+ describe TwitterWithAutoPagination::REST::Lists do
4
+ let(:config) do
5
+ {
6
+ consumer_key: ENV['CK'],
7
+ consumer_secret: ENV['CS'],
8
+ access_token: ENV['AT'],
9
+ access_token_secret: ENV['ATS']
10
+ }
11
+ end
12
+
13
+ let(:config2) do
14
+ {
15
+ consumer_key: ENV['CK2'],
16
+ consumer_secret: ENV['CS2'],
17
+ access_token: ENV['AT2'],
18
+ access_token_secret: ENV['ATS2']
19
+ }
20
+ end
21
+
22
+ let(:client) { TwitterWithAutoPagination::Client.new(config) }
23
+ let(:client2) { TwitterWithAutoPagination::Client.new(config2) }
24
+
25
+ let(:id) { 58135830 }
26
+ let(:id2) { 22356250 }
27
+
28
+ before do
29
+ client.cache.clear
30
+ $fetch_called = $request_called = false
31
+ $fetch_count = $request_count = 0
32
+ end
33
+
34
+ describe '#memberships' do
35
+ end
36
+
37
+ describe '#list_members' do
38
+ end
39
+ end
@@ -0,0 +1,42 @@
1
+ require 'helper'
2
+
3
+ describe TwitterWithAutoPagination::REST::Search do
4
+ let(:client) do
5
+ TwitterWithAutoPagination::Client.new(
6
+ consumer_key: ENV['CK'],
7
+ consumer_secret: ENV['CS'],
8
+ access_token: ENV['AT'],
9
+ access_token_secret: ENV['ATS']
10
+ )
11
+ end
12
+
13
+ let(:client2) do
14
+ TwitterWithAutoPagination::Client.new(
15
+ consumer_key: ENV['CK2'],
16
+ consumer_secret: ENV['CS2'],
17
+ access_token: ENV['AT2'],
18
+ access_token_secret: ENV['ATS2']
19
+ )
20
+ end
21
+
22
+ let(:id) { 58135830 }
23
+ let(:id2) { 22356250 }
24
+
25
+ before do
26
+ client.cache.clear
27
+ $fetch_called = $request_called = false
28
+ $fetch_count = $request_count = 0
29
+ end
30
+
31
+ describe '#search' do
32
+ let(:name) { :search }
33
+ let(:params) { ['apple'] }
34
+
35
+ it_behaves_like 'continuous calls'
36
+ it_behaves_like 'cache: false is specified'
37
+ it_behaves_like 'when options are changed'
38
+ it_behaves_like 'when a client is changed, it shares a cache'
39
+ it_behaves_like 'when one param is specified, it raises an exception'
40
+ it_behaves_like 'when count is specified', 200
41
+ end
42
+ end
@@ -0,0 +1,82 @@
1
+ require 'helper'
2
+
3
+ describe TwitterWithAutoPagination::REST::Timelines do
4
+ let(:client) do
5
+ TwitterWithAutoPagination::Client.new(
6
+ consumer_key: ENV['CK'],
7
+ consumer_secret: ENV['CS'],
8
+ access_token: ENV['AT'],
9
+ access_token_secret: ENV['ATS']
10
+ )
11
+ end
12
+
13
+ let(:client2) do
14
+ TwitterWithAutoPagination::Client.new(
15
+ consumer_key: ENV['CK2'],
16
+ consumer_secret: ENV['CS2'],
17
+ access_token: ENV['AT2'],
18
+ access_token_secret: ENV['ATS2']
19
+ )
20
+ end
21
+
22
+ let(:id) { 58135830 }
23
+ let(:id2) { 22356250 }
24
+
25
+ before do
26
+ client.cache.clear
27
+ $fetch_called = $request_called = false
28
+ $fetch_count = $request_count = 0
29
+ end
30
+
31
+ describe '#home_timeline' do
32
+ let(:name) { :home_timeline }
33
+ let(:params) { [] }
34
+
35
+ it_behaves_like 'continuous calls'
36
+ it_behaves_like 'cache: false is specified'
37
+ it_behaves_like 'when options are changed'
38
+ it_behaves_like 'when a client is changed, it does not share a cache'
39
+ it_behaves_like 'when one param is specified, it raises an exception'
40
+ it_behaves_like 'when count is specified', 400
41
+ end
42
+
43
+ describe '#user_timeline' do
44
+ let(:name) { :user_timeline }
45
+
46
+ context 'with one param' do
47
+ let(:params) { [id] }
48
+ let(:params2) { [id2] }
49
+
50
+ it_behaves_like 'continuous calls'
51
+ it_behaves_like 'cache: false is specified'
52
+ it_behaves_like 'when a value is changed'
53
+ it_behaves_like 'when options are changed'
54
+ it_behaves_like 'when a client is changed, it shares a cache'
55
+ it_behaves_like 'when count is specified', 400
56
+ end
57
+
58
+ context 'with no params' do
59
+ let(:params) { [] }
60
+
61
+ it_behaves_like 'continuous calls'
62
+ it_behaves_like 'cache: false is specified'
63
+ it_behaves_like 'when options are changed'
64
+ it_behaves_like 'when a client is changed, it does not share a cache'
65
+ it_behaves_like 'when count is specified', 400
66
+ end
67
+
68
+ it_behaves_like 'when any params is not specified, it returns a same result as a result with one param'
69
+ end
70
+
71
+ describe '#mentions_timeline' do
72
+ let(:name) { :mentions_timeline }
73
+ let(:params) { [] }
74
+
75
+ it_behaves_like 'continuous calls'
76
+ it_behaves_like 'cache: false is specified'
77
+ it_behaves_like 'when options are changed'
78
+ it_behaves_like 'when a client is changed, it does not share a cache'
79
+ it_behaves_like 'when one param is specified, it raises an exception'
80
+ it_behaves_like 'when count is specified', 400
81
+ end
82
+ end
@@ -0,0 +1,143 @@
1
+ require 'helper'
2
+
3
+ describe TwitterWithAutoPagination::REST::Users do
4
+ let(:client) do
5
+ TwitterWithAutoPagination::Client.new(
6
+ consumer_key: ENV['CK'],
7
+ consumer_secret: ENV['CS'],
8
+ access_token: ENV['AT'],
9
+ access_token_secret: ENV['ATS']
10
+ )
11
+ end
12
+
13
+ let(:client2) do
14
+ TwitterWithAutoPagination::Client.new(
15
+ consumer_key: ENV['CK2'],
16
+ consumer_secret: ENV['CS2'],
17
+ access_token: ENV['AT2'],
18
+ access_token_secret: ENV['ATS2']
19
+ )
20
+ end
21
+
22
+ let(:id) { 58135830 }
23
+ let(:id2) { 22356250 }
24
+
25
+ before do
26
+ client.cache.clear
27
+ $fetch_called = $request_called = false
28
+ $fetch_count = $request_count = 0
29
+ end
30
+
31
+ describe '#verify_credential' do
32
+ let(:name) { :verify_credentials }
33
+ let(:params) { [] }
34
+
35
+ it_behaves_like 'continuous calls'
36
+ it_behaves_like 'cache: false is specified'
37
+ it_behaves_like 'when options are changed'
38
+ it_behaves_like 'when a client is changed, it does not share a cache'
39
+
40
+ context 'when one param is specified, it raises an exception' do
41
+ it 'raises an exception' do
42
+ expect { client.verify_credentials(id) }.to raise_error(TypeError)
43
+ end
44
+ end
45
+ end
46
+
47
+ describe '#user?' do
48
+ let(:name) { :user? }
49
+ let(:params) { [id] }
50
+ let(:params2) { [id2] }
51
+
52
+ it_behaves_like 'continuous calls'
53
+ it_behaves_like 'cache: false is specified'
54
+ it_behaves_like 'when a value is changed'
55
+ it_behaves_like 'when options are changed'
56
+ it_behaves_like 'when a client is changed, it shares a cache'
57
+ it_behaves_like 'when any params is not specified, it raises an exception'
58
+ end
59
+
60
+ describe '#user' do
61
+ let(:name) { :user }
62
+
63
+ context 'with one param' do
64
+ let(:params) { [id] }
65
+ let(:params2) { [id2] }
66
+
67
+ it_behaves_like 'continuous calls'
68
+ it_behaves_like 'cache: false is specified'
69
+ it_behaves_like 'when a value is changed'
70
+ it_behaves_like 'when options are changed'
71
+ it_behaves_like 'when a client is changed, it shares a cache'
72
+ end
73
+
74
+ context 'with no params' do
75
+ let(:params) { [] }
76
+
77
+ it_behaves_like 'continuous calls'
78
+ it_behaves_like 'cache: false is specified'
79
+ it_behaves_like 'when options are changed'
80
+ it_behaves_like 'when a client is changed, it does not share a cache'
81
+ end
82
+
83
+ it_behaves_like 'when any params is not specified, it returns a same result as a result with one param'
84
+ end
85
+
86
+ describe '#users' do
87
+ let(:name) { :users }
88
+ let(:params) { [[id]] }
89
+ let(:params2) { [[id2]] }
90
+
91
+ it_behaves_like 'continuous calls'
92
+ it_behaves_like 'cache: false is specified'
93
+ it_behaves_like 'when a value is changed'
94
+ it_behaves_like 'when options are changed'
95
+ it_behaves_like 'when a client is changed, it shares a cache'
96
+ it_behaves_like 'when any params is not specified, it raises an exception'
97
+
98
+ context 'with many values' do
99
+ it 'fetches 3 times' do
100
+ many_values = Array.new(150, id)
101
+ expect { client.users(many_values) }.to fetch.exactly(3).times & request.twice
102
+ expect { client.users(many_values) }.to fetch & not_request
103
+ end
104
+ end
105
+
106
+ end
107
+
108
+ describe '#blocked_ids' do
109
+ let(:name) { :blocked_ids }
110
+ let(:params) { [] }
111
+
112
+ it_behaves_like 'continuous calls'
113
+ it_behaves_like 'cache: false is specified'
114
+ it_behaves_like 'when options are changed'
115
+ it_behaves_like 'when a client is changed, it does not share a cache'
116
+ it_behaves_like 'when one param is specified, it raises an exception'
117
+
118
+ context 'when strange params are specified' do
119
+ let(:params) { [1, 2, 3] }
120
+
121
+ it 'does not raise an exception' do
122
+ expect { client.blocked_ids(*params) }.to_not raise_error
123
+ end
124
+
125
+ it 'does not share a cache' do
126
+ result1 = result2 = nil
127
+ expect { result1 = client.blocked_ids }.to fetch & request
128
+ expect { result2 = client.blocked_ids(*params) }.to fetch & request
129
+ expect(result1).to match_array(result2)
130
+ end
131
+ end
132
+ end
133
+
134
+ describe '#users_internal' do
135
+ context 'with many values' do
136
+ it 'fetches twice' do
137
+ many_values = Array.new(150, id)
138
+ expect { client.send(:users_internal, many_values) }.to fetch.twice & request.twice
139
+ expect { client.send(:users_internal, many_values) }.to fetch.twice & not_request
140
+ end
141
+ end
142
+ end
143
+ end
@@ -22,5 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.required_ruby_version = '>= 2.3'
23
23
  spec.summary = spec.description
24
24
  spec.test_files = Dir.glob('spec/**/*')
25
- spec.version = '0.8.12'
25
+ spec.version = '0.9.0'
26
26
  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.8.12
4
+ version: 0.9.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-10-25 00:00:00.000000000 Z
11
+ date: 2017-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: twitter
@@ -91,7 +91,16 @@ files:
91
91
  - README.md
92
92
  - Rakefile
93
93
  - lib/twitter_with_auto_pagination.rb
94
+ - lib/twitter_with_auto_pagination/analysis/api.rb
95
+ - lib/twitter_with_auto_pagination/analysis/timelines.rb
96
+ - lib/twitter_with_auto_pagination/cache.rb
97
+ - lib/twitter_with_auto_pagination/caching_and_logging.rb
98
+ - lib/twitter_with_auto_pagination/client.rb
99
+ - lib/twitter_with_auto_pagination/collector.rb
94
100
  - lib/twitter_with_auto_pagination/log_subscriber.rb
101
+ - lib/twitter_with_auto_pagination/logger.rb
102
+ - lib/twitter_with_auto_pagination/parallel.rb
103
+ - lib/twitter_with_auto_pagination/rate_limit.rb
95
104
  - lib/twitter_with_auto_pagination/rest/api.rb
96
105
  - lib/twitter_with_auto_pagination/rest/extension/clusters.rb
97
106
  - lib/twitter_with_auto_pagination/rest/extension/favoriting.rb
@@ -104,11 +113,19 @@ files:
104
113
  - lib/twitter_with_auto_pagination/rest/lists.rb
105
114
  - lib/twitter_with_auto_pagination/rest/search.rb
106
115
  - lib/twitter_with_auto_pagination/rest/timelines.rb
107
- - lib/twitter_with_auto_pagination/rest/uncategorized.rb
108
116
  - lib/twitter_with_auto_pagination/rest/users.rb
109
117
  - lib/twitter_with_auto_pagination/rest/utils.rb
118
+ - lib/twitter_with_auto_pagination/serializer.rb
110
119
  - spec/helper.rb
120
+ - spec/twitter_with_auto_pagination/cache_spec.rb
111
121
  - spec/twitter_with_auto_pagination/client_spec.rb
122
+ - spec/twitter_with_auto_pagination/parallel_spec.rb
123
+ - spec/twitter_with_auto_pagination/rest/favorites_spec.rb
124
+ - spec/twitter_with_auto_pagination/rest/friends_and_followers_spec.rb
125
+ - spec/twitter_with_auto_pagination/rest/lists_spec.rb
126
+ - spec/twitter_with_auto_pagination/rest/search_spec.rb
127
+ - spec/twitter_with_auto_pagination/rest/timelines_spec.rb
128
+ - spec/twitter_with_auto_pagination/rest/users_spec.rb
112
129
  - twitter_with_auto_pagination.gemspec
113
130
  homepage: http://github.com/ts-3156/twitter_with_auto_pagination/
114
131
  licenses:
@@ -136,4 +153,12 @@ specification_version: 4
136
153
  summary: Add auto paginate feature to Twitter gem.
137
154
  test_files:
138
155
  - spec/helper.rb
156
+ - spec/twitter_with_auto_pagination/cache_spec.rb
139
157
  - spec/twitter_with_auto_pagination/client_spec.rb
158
+ - spec/twitter_with_auto_pagination/parallel_spec.rb
159
+ - spec/twitter_with_auto_pagination/rest/favorites_spec.rb
160
+ - spec/twitter_with_auto_pagination/rest/friends_and_followers_spec.rb
161
+ - spec/twitter_with_auto_pagination/rest/lists_spec.rb
162
+ - spec/twitter_with_auto_pagination/rest/search_spec.rb
163
+ - spec/twitter_with_auto_pagination/rest/timelines_spec.rb
164
+ - spec/twitter_with_auto_pagination/rest/users_spec.rb