usps-imis-api 1.0.0.pre.rc.2 → 1.0.0.pre.rc.3
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 +19 -6
- data/lib/usps/imis/config.rb +1 -1
- data/lib/usps/imis/error/{api.rb → api_error.rb} +2 -2
- data/lib/usps/imis/error/{mapper.rb → mapper_error.rb} +1 -1
- data/lib/usps/imis/error/{response.rb → response_error.rb} +3 -3
- data/lib/usps/imis/mapper.rb +1 -1
- data/lib/usps/imis/panel/base_panel.rb +2 -2
- data/lib/usps/imis/version.rb +1 -1
- data/lib/usps/imis.rb +3 -3
- data/spec/lib/usps/imis/api_spec.rb +15 -3
- data/spec/lib/usps/imis/config_spec.rb +1 -1
- data/spec/lib/usps/imis/error/{api_spec.rb → api_error_spec.rb} +1 -1
- data/spec/lib/usps/imis/error/{response_spec.rb → response_error_spec.rb} +4 -4
- data/spec/lib/usps/imis/mapper_spec.rb +1 -1
- data/spec/lib/usps/imis/panel/base_panel_spec.rb +2 -2
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 927a6d408196ed631d013daac7854beb5b0c27b7b138a454c0078af710cad204
|
|
4
|
+
data.tar.gz: 8d747f8023487b5fa1d2e4fc50a3aa5d26676cc99c818849b6fa9af205a8e50b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b87668b7e37cfa951b729ef0c01b580055b0d48076f6ffab10bff81e0d47ad255df3718e3c63daece6c0a2fc256506eb9ceefec0bed564ce09b1c5bc4e8ba116
|
|
7
|
+
data.tar.gz: e0c08859e7e890887267d13166023ef903355ed70416bd83e856d143de0eab6753d78c0b976acdcc3356144bd3ae92a95ebef43233c6b40a89b17315bb29de0e
|
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
|
|
|
@@ -228,7 +241,7 @@ module Usps
|
|
|
228
241
|
|
|
229
242
|
def submit(uri, request)
|
|
230
243
|
client(uri).request(request).tap do |result|
|
|
231
|
-
raise Error::
|
|
244
|
+
raise Error::ResponseError.from(result) unless result.is_a?(Net::HTTPSuccess)
|
|
232
245
|
end
|
|
233
246
|
end
|
|
234
247
|
|
data/lib/usps/imis/config.rb
CHANGED
|
@@ -5,12 +5,12 @@ module Usps
|
|
|
5
5
|
module Error
|
|
6
6
|
# Base error class for all internal exceptions
|
|
7
7
|
#
|
|
8
|
-
class
|
|
8
|
+
class ApiError < StandardError
|
|
9
9
|
# Additional call-specific metadata to pass through to Bugsnag
|
|
10
10
|
#
|
|
11
11
|
attr_accessor :metadata
|
|
12
12
|
|
|
13
|
-
# A new instance of +
|
|
13
|
+
# A new instance of +ApiError+
|
|
14
14
|
#
|
|
15
15
|
# @param message [String] The base exception message
|
|
16
16
|
# @param metadata [Hash] Additional call-specific metadata to pass through to Bugsnag
|
|
@@ -5,7 +5,7 @@ module Usps
|
|
|
5
5
|
module Error
|
|
6
6
|
# Exception raised due to receiving an error response from the API
|
|
7
7
|
#
|
|
8
|
-
class
|
|
8
|
+
class ResponseError < ApiError
|
|
9
9
|
# [Net::HTTPResponse] The response received from the API
|
|
10
10
|
#
|
|
11
11
|
attr_reader :response
|
|
@@ -14,7 +14,7 @@ module Usps
|
|
|
14
14
|
#
|
|
15
15
|
attr_accessor :metadata
|
|
16
16
|
|
|
17
|
-
# Create a new instance of +
|
|
17
|
+
# Create a new instance of +ResponseError+ from an API response
|
|
18
18
|
#
|
|
19
19
|
# @param response [Net::HTTPResponse] The response received from the API
|
|
20
20
|
#
|
|
@@ -22,7 +22,7 @@ module Usps
|
|
|
22
22
|
new(nil, response)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
# Create a new instance of +
|
|
25
|
+
# Create a new instance of +ResponseError+
|
|
26
26
|
#
|
|
27
27
|
# @param _message Ignored
|
|
28
28
|
# @param response [Net::HTTPResponse] The response received from the API
|
data/lib/usps/imis/mapper.rb
CHANGED
|
@@ -51,11 +51,11 @@ module Usps
|
|
|
51
51
|
private
|
|
52
52
|
|
|
53
53
|
def business_object
|
|
54
|
-
raise Error::
|
|
54
|
+
raise Error::ApiError, "#{self.class.name} must implement #business_object"
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
def payload(_data)
|
|
58
|
-
raise Error::
|
|
58
|
+
raise Error::ApiError, "#{self.class.name} must implement #payload(data)"
|
|
59
59
|
end
|
|
60
60
|
end
|
|
61
61
|
end
|
data/lib/usps/imis/version.rb
CHANGED
data/lib/usps/imis.rb
CHANGED
|
@@ -13,9 +13,9 @@ require 'ext/hash' unless defined?(Rails)
|
|
|
13
13
|
|
|
14
14
|
# Internal requires
|
|
15
15
|
require_relative 'imis/config'
|
|
16
|
-
require_relative 'imis/error/
|
|
17
|
-
require_relative 'imis/error/
|
|
18
|
-
require_relative 'imis/error/
|
|
16
|
+
require_relative 'imis/error/api_error'
|
|
17
|
+
require_relative 'imis/error/mapper_error'
|
|
18
|
+
require_relative 'imis/error/response_error'
|
|
19
19
|
require_relative 'imis/api'
|
|
20
20
|
require_relative 'imis/mapper'
|
|
21
21
|
require_relative 'imis/panel/base_panel'
|
|
@@ -31,7 +31,7 @@ describe Usps::Imis::Api do
|
|
|
31
31
|
|
|
32
32
|
it 'wraps errors' do
|
|
33
33
|
expect { api.imis_id_for('E231625') }.to raise_error(
|
|
34
|
-
Usps::Imis::Error::
|
|
34
|
+
Usps::Imis::Error::ApiError, 'Member not found'
|
|
35
35
|
)
|
|
36
36
|
end
|
|
37
37
|
end
|
|
@@ -47,7 +47,7 @@ describe Usps::Imis::Api do
|
|
|
47
47
|
context 'when receiving a response error' do
|
|
48
48
|
let(:warning_text) do
|
|
49
49
|
<<~WARNING.chomp
|
|
50
|
-
Usps::Imis::Error::
|
|
50
|
+
Usps::Imis::Error::ResponseError: [INTERNAL_SERVER_ERROR] The iMIS API returned an error.
|
|
51
51
|
Something went wrong
|
|
52
52
|
WARNING
|
|
53
53
|
end
|
|
@@ -62,7 +62,7 @@ describe Usps::Imis::Api do
|
|
|
62
62
|
|
|
63
63
|
it 'wraps the error' do
|
|
64
64
|
expect { api.put_fields('ABC_ASC_Individual_Demog', { 'TotMMS' => 15 }) }.to raise_error(
|
|
65
|
-
Usps::Imis::Error::
|
|
65
|
+
Usps::Imis::Error::ApiError, warning_text
|
|
66
66
|
)
|
|
67
67
|
end
|
|
68
68
|
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
|
|
@@ -25,7 +25,7 @@ describe Usps::Imis::Config do
|
|
|
25
25
|
|
|
26
26
|
it 'raises an error' do
|
|
27
27
|
expect { config.hostname }.to raise_error(
|
|
28
|
-
Usps::Imis::Error::
|
|
28
|
+
Usps::Imis::Error::ApiError, 'Unexpected API environment: nothing'
|
|
29
29
|
)
|
|
30
30
|
end
|
|
31
31
|
end
|
|
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
|
4
4
|
|
|
5
5
|
ApiResponseStub = Struct.new(:code, :body)
|
|
6
6
|
|
|
7
|
-
describe Usps::Imis::Error::
|
|
7
|
+
describe Usps::Imis::Error::ResponseError do
|
|
8
8
|
let(:error) { described_class.from(response) }
|
|
9
9
|
|
|
10
10
|
describe 'error codes' do
|
|
@@ -61,7 +61,7 @@ describe Usps::Imis::Error::Response do
|
|
|
61
61
|
let(:response) { ApiResponseStub.new('500', 'Body of the API response error') }
|
|
62
62
|
let(:warning_text) do
|
|
63
63
|
<<~WARNING.chomp
|
|
64
|
-
Usps::Imis::Error::
|
|
64
|
+
Usps::Imis::Error::ResponseError: [INTERNAL_SERVER_ERROR] The iMIS API returned an error.
|
|
65
65
|
Body of the API response error
|
|
66
66
|
WARNING
|
|
67
67
|
end
|
|
@@ -78,7 +78,7 @@ describe Usps::Imis::Error::Response do
|
|
|
78
78
|
let(:response) { ApiResponseStub.new('500', response_body) }
|
|
79
79
|
let(:warning_text) do
|
|
80
80
|
<<~WARNING.chomp
|
|
81
|
-
Usps::Imis::Error::
|
|
81
|
+
Usps::Imis::Error::ResponseError: [INTERNAL_SERVER_ERROR] The iMIS API returned an error.
|
|
82
82
|
description
|
|
83
83
|
WARNING
|
|
84
84
|
end
|
|
@@ -95,7 +95,7 @@ describe Usps::Imis::Error::Response do
|
|
|
95
95
|
let(:response) { ApiResponseStub.new('500', response_body) }
|
|
96
96
|
let(:warning_text) do
|
|
97
97
|
<<~WARNING.chomp
|
|
98
|
-
Usps::Imis::Error::
|
|
98
|
+
Usps::Imis::Error::ResponseError: [INTERNAL_SERVER_ERROR] The iMIS API returned an error.
|
|
99
99
|
#{response_body}
|
|
100
100
|
WARNING
|
|
101
101
|
end
|
|
@@ -22,7 +22,7 @@ describe Usps::Imis::Mapper do
|
|
|
22
22
|
|
|
23
23
|
it 'raises for unmapped updates' do
|
|
24
24
|
expect { api.mapper.update(something: 'anything') }.to raise_error(
|
|
25
|
-
Usps::Imis::Error::
|
|
25
|
+
Usps::Imis::Error::MapperError,
|
|
26
26
|
'Unrecognized field: "something". ' \
|
|
27
27
|
'Please report what data you are attempting to work with to ITCom leadership.'
|
|
28
28
|
)
|
|
@@ -19,13 +19,13 @@ end
|
|
|
19
19
|
describe Usps::Imis::Panel::BasePanel do
|
|
20
20
|
it 'requires #business_object to be defined' do
|
|
21
21
|
expect { Usps::Imis::Panel::InvalidPanel.new.get(1) }.to raise_error(
|
|
22
|
-
Usps::Imis::Error::
|
|
22
|
+
Usps::Imis::Error::ApiError, 'Usps::Imis::Panel::InvalidPanel must implement #business_object'
|
|
23
23
|
)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
it 'requires #payload(data) to be defined' do
|
|
27
27
|
expect { Usps::Imis::Panel::InvalidPanelWithBusinessObject.new.create({}) }.to raise_error(
|
|
28
|
-
Usps::Imis::Error::
|
|
28
|
+
Usps::Imis::Error::ApiError,
|
|
29
29
|
'Usps::Imis::Panel::InvalidPanelWithBusinessObject must implement #payload(data)'
|
|
30
30
|
)
|
|
31
31
|
end
|
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: 1.0.0.pre.rc.
|
|
4
|
+
version: 1.0.0.pre.rc.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Julian Fiander
|
|
@@ -31,9 +31,9 @@ files:
|
|
|
31
31
|
- lib/usps/imis.rb
|
|
32
32
|
- lib/usps/imis/api.rb
|
|
33
33
|
- lib/usps/imis/config.rb
|
|
34
|
-
- lib/usps/imis/error/
|
|
35
|
-
- lib/usps/imis/error/
|
|
36
|
-
- lib/usps/imis/error/
|
|
34
|
+
- lib/usps/imis/error/api_error.rb
|
|
35
|
+
- lib/usps/imis/error/mapper_error.rb
|
|
36
|
+
- lib/usps/imis/error/response_error.rb
|
|
37
37
|
- lib/usps/imis/mapper.rb
|
|
38
38
|
- lib/usps/imis/panel/base_panel.rb
|
|
39
39
|
- lib/usps/imis/panel/education.rb
|
|
@@ -41,8 +41,8 @@ files:
|
|
|
41
41
|
- lib/usps/imis/version.rb
|
|
42
42
|
- spec/lib/usps/imis/api_spec.rb
|
|
43
43
|
- spec/lib/usps/imis/config_spec.rb
|
|
44
|
-
- spec/lib/usps/imis/error/
|
|
45
|
-
- spec/lib/usps/imis/error/
|
|
44
|
+
- spec/lib/usps/imis/error/api_error_spec.rb
|
|
45
|
+
- spec/lib/usps/imis/error/response_error_spec.rb
|
|
46
46
|
- spec/lib/usps/imis/mapper_spec.rb
|
|
47
47
|
- spec/lib/usps/imis/panel/base_panel_spec.rb
|
|
48
48
|
- spec/lib/usps/imis/panel/education_spec.rb
|