usps-imis-api 0.5.0 → 0.5.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/Gemfile.lock +1 -1
- data/lib/usps/imis/api.rb +18 -5
- data/lib/usps/imis/version.rb +1 -1
- data/spec/lib/usps/imis/api_spec.rb +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 93af4ce91eacb92695d10144b3885da6bd1e8ff31e26f8b22c8ae9404595f951
|
|
4
|
+
data.tar.gz: 6c2df89c1531953ef37d8fd867699fc8917d2aca3db3e204cf3937bf679cf7ed
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 299a9220c4232cd0a1d45681a4f5c32800c0188e3e86f2740b7106f5ccc256f22dfe15bbafe6bd8c06152b4af9f3434c2cba5e49c632eed5a3a1540a4305ca59
|
|
7
|
+
data.tar.gz: 2d0310cea22d9160330cb4d1438679dc17565ab9e43d32dc0db7fd2dea7315a070cbd949bc30e0cde9ecbca09302a5c1e4033c034667fffb52d44462177766a9
|
data/Gemfile.lock
CHANGED
data/lib/usps/imis/api.rb
CHANGED
|
@@ -31,6 +31,10 @@ module Usps
|
|
|
31
31
|
#
|
|
32
32
|
attr_reader :imis_id
|
|
33
33
|
|
|
34
|
+
# Whether to lock changes to the selected iMIS ID
|
|
35
|
+
#
|
|
36
|
+
attr_reader :lock_imis_id
|
|
37
|
+
|
|
34
38
|
# A new instance of +Api+
|
|
35
39
|
#
|
|
36
40
|
# @param skip_authentication [bool] Skip authentication on initialization (used for tests)
|
|
@@ -46,6 +50,8 @@ module Usps
|
|
|
46
50
|
# @param id [Integer, String] iMIS ID to select for future requests
|
|
47
51
|
#
|
|
48
52
|
def imis_id=(id)
|
|
53
|
+
raise Error::ApiError, 'Cannot change iMIS ID while locked' if lock_imis_id
|
|
54
|
+
|
|
49
55
|
@imis_id = id.to_i.to_s
|
|
50
56
|
end
|
|
51
57
|
|
|
@@ -56,15 +62,19 @@ module Usps
|
|
|
56
62
|
# @return [String] Corresponding iMIS ID
|
|
57
63
|
#
|
|
58
64
|
def imis_id_for(certificate)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
raise Error::ApiError, 'Cannot change iMIS ID while locked' if lock_imis_id
|
|
66
|
+
|
|
67
|
+
begin
|
|
68
|
+
result = query(Imis.configuration.imis_id_query_name, { certificate: })
|
|
69
|
+
@imis_id = result['Items']['$values'][0]['ID']
|
|
70
|
+
rescue StandardError
|
|
71
|
+
raise Error::ApiError, 'Member not found'
|
|
72
|
+
end
|
|
63
73
|
end
|
|
64
74
|
|
|
65
75
|
# Run requests as DSL, with specific iMIS ID only maintained for this scope
|
|
66
76
|
#
|
|
67
|
-
#
|
|
77
|
+
# While in this block, changes to the value of +imis_id+ are not allowed
|
|
68
78
|
#
|
|
69
79
|
# @param id [Integer, String] iMIS ID to select for requests within the block
|
|
70
80
|
#
|
|
@@ -76,8 +86,11 @@ module Usps
|
|
|
76
86
|
def with(id, &)
|
|
77
87
|
old_id = imis_id
|
|
78
88
|
self.imis_id = id
|
|
89
|
+
|
|
90
|
+
@lock_imis_id = true
|
|
79
91
|
instance_eval(&)
|
|
80
92
|
ensure
|
|
93
|
+
@lock_imis_id = false
|
|
81
94
|
self.imis_id = old_id
|
|
82
95
|
end
|
|
83
96
|
|
data/lib/usps/imis/version.rb
CHANGED
|
@@ -82,6 +82,18 @@ describe Usps::Imis::Api do
|
|
|
82
82
|
it 'uses a panel correctly' do
|
|
83
83
|
expect(api.with(6374) { panels.vsc.get(1433) }).to be_a(Hash)
|
|
84
84
|
end
|
|
85
|
+
|
|
86
|
+
it 'blocks calling imis_id=' do
|
|
87
|
+
expect do
|
|
88
|
+
api.with(31092) { self.imis_id = 31092 }
|
|
89
|
+
end.to raise_error(Usps::Imis::Error::ApiError, 'Cannot change iMIS ID while locked')
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'blocks calling imis_id_for' do
|
|
93
|
+
expect do
|
|
94
|
+
api.with(31092) { imis_id_for('E231625') }
|
|
95
|
+
end.to raise_error(Usps::Imis::Error::ApiError, 'Cannot change iMIS ID while locked')
|
|
96
|
+
end
|
|
85
97
|
end
|
|
86
98
|
|
|
87
99
|
describe '#inspect' do
|