twitter_with_auto_pagination 0.9.0 → 0.9.1

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
  SHA1:
3
- metadata.gz: ed91eaf1cf67bef358dda37cdd3886003fa80c0c
4
- data.tar.gz: e91e410326935bb838a8c9c7d29f678d129b2417
3
+ metadata.gz: 85eecd1e9b697a9d479e8397e86180fdffe7f4c4
4
+ data.tar.gz: 37fe4226e75aa04c5e0618254143263a337bb18b
5
5
  SHA512:
6
- metadata.gz: 97ad05cdd642560bb57e5ef28f2d1b7fdbb492e9112dfdd0af8688fd7a3735f799a0d99957d97a28e7699d158724a14dccd57c3424b9b5964e68ead8990af020
7
- data.tar.gz: f342f1131df4b7fe0410e5ad9b61879bb88a07077d08a4414e07828dea0fcb1a3ba6cec6ee9c638de382fb36b72dce4d36344e99d7a94562dfdf9d7c1eba3197
6
+ metadata.gz: 89ab8908cc586738a97d59c021b24127e200e8b3bc6c93504f8374dd1e86829fc98a0326a272b945ddd7f9bec84a69bcf04b14119c3a6be1cb736eeae10e24c0
7
+ data.tar.gz: f059e8a50b88b808fa8575be9053640b60353982b774ce23355cfbd0643002532b4dfbaf4a546f31ba2a5e37ac22334b6a84646a38009eb554bfb7623c84fbe6
@@ -7,13 +7,11 @@ module TwitterWithAutoPagination
7
7
  class Cache
8
8
  extend Forwardable
9
9
 
10
- attr_reader :serializer, :client
10
+ attr_reader :client
11
11
 
12
12
  def_delegators :@client, :clear, :cleanup
13
13
 
14
14
  def initialize
15
- @serializer = Serializer
16
-
17
15
  path = File.join('tmp', 'twitter_cache')
18
16
  Dir.mkdir(path) unless File.exists?(path)
19
17
  @client = ActiveSupport::Cache::FileStore.new(path, expires_in: 1.hour, race_condition_ttl: 5.minutes)
@@ -26,10 +24,10 @@ module TwitterWithAutoPagination
26
24
  fetch_result =
27
25
  @client.fetch(key) do
28
26
  block_result = yield
29
- serializer.encode(block_result, args: options[:args])
27
+ Serializer.encode(block_result, args: options[:args])
30
28
  end
31
29
 
32
- block_result ? block_result : serializer.decode(fetch_result, args: options[:args])
30
+ block_result ? block_result : Serializer.decode(fetch_result, args: options[:args])
33
31
  end
34
32
 
35
33
  private
@@ -1,20 +1,26 @@
1
1
  module TwitterWithAutoPagination
2
2
  class Serializer
3
- CODER = JSON
4
-
5
3
  class << self
6
4
  def encode(obj, options = {})
7
5
  instrument(options) do
8
- (!!obj == obj) ? obj : CODER.dump(obj)
6
+ (!!obj == obj) ? obj : coder.dump(obj)
9
7
  end
10
8
  end
11
9
 
12
10
  def decode(str, options = {})
13
11
  instrument(options) do
14
- str.kind_of?(String) ? CODER.parse(str, symbolize_names: true) : str
12
+ str.kind_of?(String) ? coder.decode(str) : str
15
13
  end
16
14
  end
17
15
 
16
+ def coder
17
+ @@coder ||= JsonCoder.new(JSON)
18
+ end
19
+
20
+ def coder=(coder)
21
+ @@coder = Coder.instance(coder)
22
+ end
23
+
18
24
  private
19
25
 
20
26
  def instrument(options, &block)
@@ -23,5 +29,37 @@ module TwitterWithAutoPagination
23
29
  ActiveSupport::Notifications.instrument("#{payload[:operation]}.twitter", payload) { yield(payload) }
24
30
  end
25
31
  end
32
+
33
+ class Coder
34
+ def initialize(coder)
35
+ @coder = coder
36
+ end
37
+
38
+ def encode(obj)
39
+ @coder.dump(obj)
40
+ end
41
+
42
+ def self.instance(coder)
43
+ if coder == JSON
44
+ JsonCoder.new(coder)
45
+ elsif defined?(Oj) && coder == Oj
46
+ OjCoder.new(coder)
47
+ else
48
+ raise "Invalid coder #{coder}"
49
+ end
50
+ end
51
+ end
52
+
53
+ class JsonCoder < Coder
54
+ def decode(str)
55
+ @coder.parse(str, symbolize_names: true)
56
+ end
57
+ end
58
+
59
+ class OjCoder < Coder
60
+ def decode(str)
61
+ @coder.load(str, symbol_keys: true)
62
+ end
63
+ end
26
64
  end
27
65
  end
@@ -113,7 +113,6 @@ describe TwitterWithAutoPagination::REST::Users do
113
113
  it_behaves_like 'cache: false is specified'
114
114
  it_behaves_like 'when options are changed'
115
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
116
 
118
117
  context 'when strange params are specified' do
119
118
  let(:params) { [1, 2, 3] }
@@ -2,7 +2,7 @@ lib = File.expand_path('../lib', __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
- spec.add_dependency 'twitter'
5
+ spec.add_dependency 'twitter', '~> 6.0'
6
6
  spec.add_dependency 'activesupport'
7
7
  spec.add_dependency 'hashie'
8
8
  spec.add_dependency 'parallel'
@@ -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.9.0'
25
+ spec.version = '0.9.1'
26
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter_with_auto_pagination
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shinohara Teruki
@@ -14,16 +14,16 @@ dependencies:
14
14
  name: twitter
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '6.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '6.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement