usps-imis-api 0.4.5 → 0.5.0
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 +2 -2
- 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 +3 -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: 1febbdb28781a5589ce97b66eb071728aef8b8e81991970854620c9fc128cf54
|
|
4
|
+
data.tar.gz: cc5aeb7ddab766c885d4bb009b1fa9afcdaa8f71d68b56f2e86861c12f8eda72
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '09fdb03097ef67813356bf1a4378f53827bcacc3c8115fb9128ce0f2a8dcdceb26aafc3296b8132468860906ac3884965c53b4e47729aa8dc0a964a13346717e'
|
|
7
|
+
data.tar.gz: 3703f4325f53afde2c9350c4382d0cbfeb4d53489275c866a1041749ba5324d7833c4a3fe14f11e70bcd3a1729981f2b3b3befcd3a603a5ab5703a03ae6a9cc5
|
data/Gemfile.lock
CHANGED
data/lib/usps/imis/api.rb
CHANGED
|
@@ -59,7 +59,7 @@ module Usps
|
|
|
59
59
|
result = query(Imis.configuration.imis_id_query_name, { certificate: })
|
|
60
60
|
@imis_id = result['Items']['$values'][0]['ID']
|
|
61
61
|
rescue StandardError
|
|
62
|
-
raise Error::
|
|
62
|
+
raise Error::ApiError, 'Member not found'
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
# Run requests as DSL, with specific iMIS ID only maintained for this scope
|
|
@@ -228,7 +228,7 @@ module Usps
|
|
|
228
228
|
|
|
229
229
|
def submit(uri, request)
|
|
230
230
|
client(uri).request(request).tap do |result|
|
|
231
|
-
raise Error::
|
|
231
|
+
raise Error::ResponseError.from(result) unless result.is_a?(Net::HTTPSuccess)
|
|
232
232
|
end
|
|
233
233
|
end
|
|
234
234
|
|
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
|
|
@@ -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: 0.
|
|
4
|
+
version: 0.5.0
|
|
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
|