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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1febbdb28781a5589ce97b66eb071728aef8b8e81991970854620c9fc128cf54
4
- data.tar.gz: cc5aeb7ddab766c885d4bb009b1fa9afcdaa8f71d68b56f2e86861c12f8eda72
3
+ metadata.gz: 93af4ce91eacb92695d10144b3885da6bd1e8ff31e26f8b22c8ae9404595f951
4
+ data.tar.gz: 6c2df89c1531953ef37d8fd867699fc8917d2aca3db3e204cf3937bf679cf7ed
5
5
  SHA512:
6
- metadata.gz: '09fdb03097ef67813356bf1a4378f53827bcacc3c8115fb9128ce0f2a8dcdceb26aafc3296b8132468860906ac3884965c53b4e47729aa8dc0a964a13346717e'
7
- data.tar.gz: 3703f4325f53afde2c9350c4382d0cbfeb4d53489275c866a1041749ba5324d7833c4a3fe14f11e70bcd3a1729981f2b3b3befcd3a603a5ab5703a03ae6a9cc5
6
+ metadata.gz: 299a9220c4232cd0a1d45681a4f5c32800c0188e3e86f2740b7106f5ccc256f22dfe15bbafe6bd8c06152b4af9f3434c2cba5e49c632eed5a3a1540a4305ca59
7
+ data.tar.gz: 2d0310cea22d9160330cb4d1438679dc17565ab9e43d32dc0db7fd2dea7315a070cbd949bc30e0cde9ecbca09302a5c1e4033c034667fffb52d44462177766a9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps-imis-api (0.5.0)
4
+ usps-imis-api (0.5.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
- result = query(Imis.configuration.imis_id_query_name, { certificate: })
60
- @imis_id = result['Items']['$values'][0]['ID']
61
- rescue StandardError
62
- raise Error::ApiError, 'Member not found'
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
- # This should be used with methods that do not change the value of `imis_id`
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
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Imis
5
- VERSION = '0.5.0'
5
+ VERSION = '0.5.1'
6
6
  end
7
7
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usps-imis-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander