px-service-client 2.0.0 → 2.0.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 +4 -4
- data/lib/px/service/client/base.rb +9 -11
- data/lib/px/service/client/caching.rb +3 -3
- data/lib/px/service/client/hmac_signing.rb +2 -2
- data/lib/px/service/client/version.rb +1 -1
- data/spec/px/service/client/base_spec.rb +38 -2
- data/spec/px/service/client/caching/caching_spec.rb +5 -5
- data/spec/px/service/client/hmac_signing_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19e7ec8a32fa4b49f0fac0e10eab3b1a38e373f2
|
4
|
+
data.tar.gz: b583bc1b97b2ad936e30242238184ce2d4241034
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afe66390c4020a0896b7d882e9bcf78463ab3a932b4373f428f16b96f5c84d0250d8eabd57df4e12f6ca27c0c4ceb05a33281b721f4cad51973de50f321f024e
|
7
|
+
data.tar.gz: cc9b24b80f6945371bfc339cb73e75a48473860e18a3a60bbfdac6554aa643ee5152c6421de579fb23f166e8db73aebaf2c5188bcda5a563027766e272ac3f55
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Px::Service::Client
|
2
2
|
class Base
|
3
|
-
|
3
|
+
class_attribute :logger, :config
|
4
4
|
|
5
5
|
class DefaultConfig < OpenStruct
|
6
6
|
def initialize
|
@@ -9,21 +9,19 @@ module Px::Service::Client
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
self.config = DefaultConfig.new
|
13
|
+
|
12
14
|
##
|
13
15
|
# Configure the client
|
14
|
-
def self.
|
15
|
-
|
16
|
-
yield(
|
17
|
-
|
16
|
+
def self.configure
|
17
|
+
c = self.config.dup
|
18
|
+
yield(c) if block_given?
|
19
|
+
self.config = c
|
18
20
|
end
|
19
21
|
|
20
22
|
# Make class config available to instances
|
21
|
-
def
|
22
|
-
|
23
|
-
self.class.config { |c| yield(c) }
|
24
|
-
else
|
25
|
-
self.class.config
|
26
|
-
end
|
23
|
+
def configure
|
24
|
+
self.class.configure { |c| yield(c) }
|
27
25
|
end
|
28
26
|
|
29
27
|
private
|
@@ -19,15 +19,15 @@ module Px::Service::Client
|
|
19
19
|
included do
|
20
20
|
cattr_accessor :cache_client, :cache_logger
|
21
21
|
|
22
|
-
|
22
|
+
configure do |config|
|
23
23
|
config.cache_expiry = 30.seconds
|
24
24
|
config.cache_default_policy_group = 'general'
|
25
25
|
config.cache_logger = nil
|
26
26
|
config.cache_client = nil
|
27
27
|
end
|
28
28
|
|
29
|
-
# DEPRECATED: Use .
|
30
|
-
alias_method :caching, :
|
29
|
+
# DEPRECATED: Use .configure (base class method) instead
|
30
|
+
alias_method :caching, :configure
|
31
31
|
end
|
32
32
|
|
33
33
|
def cache_request(url, strategy: nil, policy_group: config.cache_default_policy_group, expires_in: config.cache_expiry, refresh_probability: 1)
|
@@ -13,14 +13,14 @@ module Px::Service::Client
|
|
13
13
|
end
|
14
14
|
|
15
15
|
# Default config for signing
|
16
|
-
|
16
|
+
configure do |config|
|
17
17
|
config.hmac_secret = DEFAULT_SECRET
|
18
18
|
config.hmac_keyspan = DEFAULT_KEYSPAN
|
19
19
|
end
|
20
20
|
|
21
21
|
##
|
22
22
|
# DEPRECATED: Use .config (base class method) instead
|
23
|
-
alias_method :hmac_signing, :
|
23
|
+
alias_method :hmac_signing, :configure
|
24
24
|
end
|
25
25
|
|
26
26
|
module ClassMethods
|
@@ -8,7 +8,7 @@ describe Px::Service::Client::Base do
|
|
8
8
|
subject {
|
9
9
|
Class.new(Px::Service::Client::Base).tap do |c|
|
10
10
|
c.include(Px::Service::Client::Caching)
|
11
|
-
c.
|
11
|
+
c.configure do |config|
|
12
12
|
config.cache_client = dalli
|
13
13
|
end
|
14
14
|
end.new
|
@@ -30,7 +30,7 @@ describe Px::Service::Client::Base do
|
|
30
30
|
|
31
31
|
context "when there are separate subclasses" do
|
32
32
|
before :each do
|
33
|
-
subject.
|
33
|
+
subject.configure do |c|
|
34
34
|
c.subject_field = "value"
|
35
35
|
end
|
36
36
|
end
|
@@ -43,6 +43,42 @@ describe Px::Service::Client::Base do
|
|
43
43
|
expect(other_subclass.config.subject_field).not_to eq("value")
|
44
44
|
end
|
45
45
|
end
|
46
|
+
|
47
|
+
context "when the subclass is itself inherited" do
|
48
|
+
let(:subsubclass) {
|
49
|
+
Class.new(subject.class).new
|
50
|
+
}
|
51
|
+
|
52
|
+
before :each do
|
53
|
+
subject.configure do |c|
|
54
|
+
c.subject_field = "value"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it "sets the config value on the subject" do
|
59
|
+
expect(subject.config.subject_field).to eq("value")
|
60
|
+
end
|
61
|
+
|
62
|
+
it "inherits the config value on the sub-subclass" do
|
63
|
+
expect(subsubclass.config.subject_field).to eq("value")
|
64
|
+
end
|
65
|
+
|
66
|
+
context "when the config value is changed on the sub-subclass" do
|
67
|
+
before :each do
|
68
|
+
subsubclass.configure do |c|
|
69
|
+
c.subject_field = "other"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "does not change the config value on the subject" do
|
74
|
+
expect(subject.config.subject_field).to eq("value")
|
75
|
+
end
|
76
|
+
|
77
|
+
it "changes the config value on the sub-subclass" do
|
78
|
+
expect(subsubclass.config.subject_field).to eq("other")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
46
82
|
end
|
47
83
|
|
48
84
|
describe '#make_request' do
|
@@ -9,11 +9,11 @@ describe Px::Service::Client::Caching do
|
|
9
9
|
subject {
|
10
10
|
Class.new(Px::Service::Client::Base).tap do |c|
|
11
11
|
c.include(Px::Service::Client::Caching)
|
12
|
-
|
12
|
+
|
13
13
|
# Anonymous classes don't have a name. Stub out :name so that things work
|
14
14
|
allow(c).to receive(:name).and_return("Caching")
|
15
15
|
|
16
|
-
c.
|
16
|
+
c.configure do |config|
|
17
17
|
config.cache_client = dalli
|
18
18
|
end
|
19
19
|
end.new
|
@@ -87,7 +87,7 @@ describe Px::Service::Client::Caching do
|
|
87
87
|
|
88
88
|
context 'when cache client is not set' do
|
89
89
|
before :each do
|
90
|
-
subject.
|
90
|
+
subject.configure do |config|
|
91
91
|
config.cache_client = nil
|
92
92
|
end
|
93
93
|
end
|
@@ -111,7 +111,7 @@ describe Px::Service::Client::Caching do
|
|
111
111
|
context "when there is a cached response" do
|
112
112
|
context 'when cache client is not set' do
|
113
113
|
before :each do
|
114
|
-
subject.
|
114
|
+
subject.configure do |config|
|
115
115
|
config.cache_client = nil
|
116
116
|
end
|
117
117
|
end
|
@@ -166,7 +166,7 @@ describe Px::Service::Client::Caching do
|
|
166
166
|
context "when there is a cached response" do
|
167
167
|
context 'when cache client is not set' do
|
168
168
|
before :each do
|
169
|
-
subject.
|
169
|
+
subject.configure do |config|
|
170
170
|
config.cache_client = nil
|
171
171
|
end
|
172
172
|
end
|