usps-imis-api 1.0.0.pre.rc.5 → 1.0.0.pre.rc.7
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/.rubocop.yml +1 -1
- data/Gemfile.lock +36 -30
- data/Readme.md +140 -32
- data/lib/usps/imis/api.rb +27 -39
- data/lib/usps/imis/business_object.rb +87 -47
- data/lib/usps/imis/config.rb +14 -3
- data/lib/usps/imis/data.rb +72 -0
- data/lib/usps/imis/error.rb +51 -0
- data/lib/usps/imis/errors/api_error.rb +11 -0
- data/lib/usps/imis/errors/config_error.rb +11 -0
- data/lib/usps/imis/errors/locked_id_error.rb +15 -0
- data/lib/usps/imis/errors/mapper_error.rb +29 -0
- data/lib/usps/imis/errors/not_found_error.rb +11 -0
- data/lib/usps/imis/errors/panel_unimplemented_error.rb +34 -0
- data/lib/usps/imis/{error → errors}/response_error.rb +5 -8
- data/lib/usps/imis/errors/unexpected_property_type_error.rb +31 -0
- data/lib/usps/imis/mapper.rb +28 -20
- data/lib/usps/imis/mocks/business_object.rb +47 -0
- data/lib/usps/imis/mocks.rb +11 -0
- data/lib/usps/imis/panels/base_panel.rb +144 -0
- data/lib/usps/imis/{panel → panels}/education.rb +2 -2
- data/lib/usps/imis/{panel → panels}/vsc.rb +2 -2
- data/lib/usps/imis/panels.rb +25 -0
- data/lib/usps/imis/properties.rb +50 -0
- data/lib/usps/imis/query.rb +94 -0
- data/lib/usps/imis/requests.rb +27 -3
- data/lib/usps/imis/version.rb +1 -1
- data/lib/usps/imis.rb +15 -15
- data/spec/lib/usps/imis/api_spec.rb +26 -13
- data/spec/lib/usps/imis/business_object_spec.rb +44 -20
- data/spec/lib/usps/imis/config_spec.rb +2 -2
- data/spec/lib/usps/imis/data_spec.rb +66 -0
- data/spec/lib/usps/imis/{error/api_error_spec.rb → error_spec.rb} +1 -1
- data/spec/lib/usps/imis/{error → errors}/response_error_spec.rb +4 -4
- data/spec/lib/usps/imis/mapper_spec.rb +27 -3
- data/spec/lib/usps/imis/mocks/business_object_spec.rb +65 -0
- data/spec/lib/usps/imis/panels/base_panel_spec.rb +33 -0
- data/spec/lib/usps/imis/panels/education_spec.rb +70 -0
- data/spec/lib/usps/imis/{panel → panels}/vsc_spec.rb +6 -7
- data/spec/lib/usps/imis/properties_spec.rb +19 -0
- data/spec/spec_helper.rb +2 -0
- data/usps-imis-api.gemspec +1 -1
- metadata +28 -16
- data/lib/ext/hash.rb +0 -10
- data/lib/usps/imis/error/api_error.rb +0 -44
- data/lib/usps/imis/error/mapper_error.rb +0 -11
- data/lib/usps/imis/panel/base_panel.rb +0 -101
- data/lib/usps/imis/panel/panel_properties.rb +0 -52
- data/spec/lib/usps/imis/panel/base_panel_spec.rb +0 -32
- data/spec/lib/usps/imis/panel/education_spec.rb +0 -55
- data/spec/lib/usps/imis/panel/panel_properties_spec.rb +0 -19
|
@@ -6,28 +6,34 @@ describe Usps::Imis::BusinessObject do
|
|
|
6
6
|
let(:business_object) { described_class.new(api, 'Stub') }
|
|
7
7
|
let(:api) { Usps::Imis::Api.new }
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
'
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
before do
|
|
10
|
+
allow(business_object).to receive(:raw_object).and_return(
|
|
11
|
+
Usps::Imis::Data[
|
|
12
|
+
'Properties' => {
|
|
13
|
+
'$values' => [
|
|
14
|
+
{ 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
|
|
15
|
+
{ 'Name' => 'Stub Integer', 'Value' => { '$value' => 42 } },
|
|
16
|
+
{ 'Name' => 'Stub String', 'Value' => 'something' }
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
)
|
|
19
21
|
end
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
'
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
describe '#get' do
|
|
24
|
+
it 'returns multiple values' do
|
|
25
|
+
expect(business_object.get('Stub String', 'Stub Integer')).to eq(['something', 42])
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe 'delegation to get_fields' do
|
|
29
|
+
before { allow(business_object).to receive(:get_fields).with('Stub String', 'Stub Integer') }
|
|
30
|
+
|
|
31
|
+
it 'delegates to get_fields' do
|
|
32
|
+
business_object.get('Stub String', 'Stub Integer')
|
|
33
|
+
|
|
34
|
+
expect(business_object).to have_received(:get_fields).with('Stub String', 'Stub Integer')
|
|
35
|
+
end
|
|
36
|
+
end
|
|
31
37
|
end
|
|
32
38
|
|
|
33
39
|
describe '#get_field' do
|
|
@@ -40,7 +46,25 @@ describe Usps::Imis::BusinessObject do
|
|
|
40
46
|
end
|
|
41
47
|
end
|
|
42
48
|
|
|
49
|
+
describe '#get_fields' do
|
|
50
|
+
it 'returns multiple values' do
|
|
51
|
+
expect(business_object.get_fields('Stub String', 'Stub Integer')).to eq(['something', 42])
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
43
55
|
describe '#filter_fields' do
|
|
56
|
+
let(:expected) do
|
|
57
|
+
{
|
|
58
|
+
'Properties' => {
|
|
59
|
+
'$values' => [
|
|
60
|
+
{ 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
|
|
61
|
+
{ 'Name' => 'Stub Integer', 'Value' => { '$value' => 43 } },
|
|
62
|
+
{ 'Name' => 'Stub String', 'Value' => 'other' }
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
end
|
|
67
|
+
|
|
44
68
|
it 'formats fields correctly' do
|
|
45
69
|
updated = business_object.send(:filter_fields, 'Stub Integer' => 43, 'Stub String' => 'other')
|
|
46
70
|
|
|
@@ -24,7 +24,7 @@ describe Usps::Imis::Config do
|
|
|
24
24
|
subject { config.environment }
|
|
25
25
|
|
|
26
26
|
let(:config) do
|
|
27
|
-
described_class.new {
|
|
27
|
+
described_class.new { it.environment = 'test' }
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
it { is_expected.to be_test }
|
|
@@ -51,7 +51,7 @@ describe Usps::Imis::Config do
|
|
|
51
51
|
|
|
52
52
|
it 'raises an error' do
|
|
53
53
|
expect { config.hostname }.to raise_error(
|
|
54
|
-
Usps::Imis::
|
|
54
|
+
Usps::Imis::Errors::ConfigError, 'Unexpected API environment: nothing'
|
|
55
55
|
)
|
|
56
56
|
end
|
|
57
57
|
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Usps::Imis::Data do
|
|
6
|
+
let(:data) do
|
|
7
|
+
described_class[
|
|
8
|
+
'EntityTypeName' => 'ABC_ASC_Individual_Demog',
|
|
9
|
+
'Properties' => {
|
|
10
|
+
'$values' => [
|
|
11
|
+
{ 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
|
|
12
|
+
{ 'Name' => 'Stub Integer', 'Value' => { '$value' => 42 } },
|
|
13
|
+
{ 'Name' => 'Stub String', 'Value' => 'something' }
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe 'missing property' do
|
|
20
|
+
it 'returns nil for missing properties' do
|
|
21
|
+
expect(data['Not Found']).to be_nil
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe '#properties' do
|
|
26
|
+
it 'iterates over the properties, excluding IDs' do
|
|
27
|
+
expect(data.properties.map { |field, value| "#{field}: #{value}" }).to eq(
|
|
28
|
+
['Stub Integer: 42', 'Stub String: something']
|
|
29
|
+
)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'iterates over the properties, including IDs' do
|
|
33
|
+
expect(data.properties(include_ids: true).map { |field, value| "#{field}: #{value}" }).to eq(
|
|
34
|
+
['ID: 31092', 'Stub Integer: 42', 'Stub String: something']
|
|
35
|
+
)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe '#inspect' do
|
|
40
|
+
it 'generates the correct inspect string' do
|
|
41
|
+
expect(data.inspect).to eq('#<Usps::Imis::Data entity="ABC_ASC_Individual_Demog" imis_id=31092>')
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context 'with data from a Panel' do
|
|
45
|
+
let(:data) do
|
|
46
|
+
described_class[
|
|
47
|
+
'EntityTypeName' => 'ABC_ASC_Individual_Demog',
|
|
48
|
+
'Properties' => {
|
|
49
|
+
'$values' => [
|
|
50
|
+
{ 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
|
|
51
|
+
{ 'Name' => 'Ordinal', 'Value' => { '$value' => '99' } },
|
|
52
|
+
{ 'Name' => 'Stub Integer', 'Value' => { '$value' => 42 } },
|
|
53
|
+
{ 'Name' => 'Stub String', 'Value' => 'something' }
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'generates the correct inspect string with an ordinal' do
|
|
60
|
+
expect(data.inspect).to eq(
|
|
61
|
+
'#<Usps::Imis::Data entity="ABC_ASC_Individual_Demog" imis_id=31092 ordinal=99>'
|
|
62
|
+
)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
|
4
4
|
|
|
5
5
|
ApiResponseStub = Struct.new(:code, :body)
|
|
6
6
|
|
|
7
|
-
describe Usps::Imis::
|
|
7
|
+
describe Usps::Imis::Errors::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::ResponseError 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::
|
|
64
|
+
Usps::Imis::Errors::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::ResponseError do
|
|
|
78
78
|
let(:response) { ApiResponseStub.new('500', response_body) }
|
|
79
79
|
let(:warning_text) do
|
|
80
80
|
<<~WARNING.chomp
|
|
81
|
-
Usps::Imis::
|
|
81
|
+
Usps::Imis::Errors::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::ResponseError do
|
|
|
95
95
|
let(:response) { ApiResponseStub.new('500', response_body) }
|
|
96
96
|
let(:warning_text) do
|
|
97
97
|
<<~WARNING.chomp
|
|
98
|
-
Usps::Imis::
|
|
98
|
+
Usps::Imis::Errors::ResponseError: [INTERNAL_SERVER_ERROR] The iMIS API returned an error.
|
|
99
99
|
#{response_body}
|
|
100
100
|
WARNING
|
|
101
101
|
end
|
|
@@ -9,7 +9,31 @@ describe Usps::Imis::Mapper do
|
|
|
9
9
|
it 'stores the initial imis_id' do
|
|
10
10
|
mapper = described_class.new(imis_id: 42)
|
|
11
11
|
|
|
12
|
-
expect(mapper.api.imis_id).to eq(
|
|
12
|
+
expect(mapper.api.imis_id).to eq(42)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe '#fetch' do
|
|
17
|
+
before { api.imis_id = 31092 }
|
|
18
|
+
|
|
19
|
+
it 'fetches a mapped field' do
|
|
20
|
+
expect(api.mapper.fetch(:mm)).to be_a(Integer)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'supports Hash access syntax' do
|
|
24
|
+
expect(api.mapper[:mm]).to be_a(Integer)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'supports Hash access syntax on the Api directly' do
|
|
28
|
+
expect(api[:mm]).to be_a(Integer)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'raises for unmapped updates' do
|
|
32
|
+
expect { api.mapper.fetch(:another) }.to raise_error(
|
|
33
|
+
Usps::Imis::Errors::MapperError,
|
|
34
|
+
%(Mapper does not recognize field: "another".\n) \
|
|
35
|
+
'Please report what data you are attempting to work with to ITCom leadership.'
|
|
36
|
+
)
|
|
13
37
|
end
|
|
14
38
|
end
|
|
15
39
|
|
|
@@ -22,8 +46,8 @@ describe Usps::Imis::Mapper do
|
|
|
22
46
|
|
|
23
47
|
it 'raises for unmapped updates' do
|
|
24
48
|
expect { api.mapper.update(something: 'anything') }.to raise_error(
|
|
25
|
-
Usps::Imis::
|
|
26
|
-
|
|
49
|
+
Usps::Imis::Errors::MapperError,
|
|
50
|
+
%(Mapper does not recognize field: "something".\n) \
|
|
27
51
|
'Please report what data you are attempting to work with to ITCom leadership.'
|
|
28
52
|
)
|
|
29
53
|
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Usps::Imis::Mocks::BusinessObject do
|
|
6
|
+
let(:mock) { described_class.new(**fields) }
|
|
7
|
+
let(:fields) { { TotMMS: 2, Something: 'Another' } }
|
|
8
|
+
|
|
9
|
+
let(:data) do
|
|
10
|
+
Usps::Imis::Properties.build do |props|
|
|
11
|
+
props.add 'TotMMS', 2
|
|
12
|
+
props.add 'Something', 'Another'
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe 'get' do
|
|
17
|
+
it 'returns the correct data' do
|
|
18
|
+
expect(mock.get).to eq(data)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe 'get_field' do
|
|
23
|
+
it 'returns the correct field value' do
|
|
24
|
+
expect(mock.get_field('TotMMS')).to eq(2)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe 'get_fields' do
|
|
29
|
+
it 'returns the correct field values' do
|
|
30
|
+
expect(mock.get_fields('TotMMS', 'Something')).to eq([2, 'Another'])
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe 'put_fields' do
|
|
35
|
+
let(:combined_data) do
|
|
36
|
+
Usps::Imis::Properties.build do |props|
|
|
37
|
+
props.add 'TotMMS', 2
|
|
38
|
+
props.add 'Something', 'Another'
|
|
39
|
+
props.add 'SomethingElse', 'interesting'
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'returns the correct data' do
|
|
44
|
+
expect(mock.put_fields(SomethingElse: 'interesting')).to eq(combined_data)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
describe 'put' do
|
|
49
|
+
it 'returns the correct data' do
|
|
50
|
+
expect(mock.put(data)).to eq(data)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
describe 'post' do
|
|
55
|
+
it 'returns the correct data' do
|
|
56
|
+
expect(mock.post(data)).to eq(data)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
describe 'delete' do
|
|
61
|
+
it 'returns the correct data' do
|
|
62
|
+
expect(mock.delete).to eq('')
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
module Usps
|
|
6
|
+
module Imis
|
|
7
|
+
module Panels
|
|
8
|
+
class InvalidPanel < BasePanel; end
|
|
9
|
+
|
|
10
|
+
class InvalidPanelWithBusinessObject < BasePanel
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
def business_object = 'Something'
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe Usps::Imis::Panels::BasePanel do
|
|
20
|
+
it 'requires #business_object to be defined' do
|
|
21
|
+
expect { Usps::Imis::Panels::InvalidPanel.new.get(1) }.to raise_error(
|
|
22
|
+
Usps::Imis::Errors::PanelUnimplementedError,
|
|
23
|
+
'Usps::Imis::Panels::InvalidPanel must implement #business_object'
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'requires #payload(data) to be defined' do
|
|
28
|
+
expect { Usps::Imis::Panels::InvalidPanelWithBusinessObject.new.create({}) }.to raise_error(
|
|
29
|
+
Usps::Imis::Errors::PanelUnimplementedError,
|
|
30
|
+
'Usps::Imis::Panels::InvalidPanelWithBusinessObject must implement #payload(data)'
|
|
31
|
+
)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Usps::Imis::Panels::Education do
|
|
6
|
+
describe 'api example' do
|
|
7
|
+
let(:education) { described_class.new }
|
|
8
|
+
|
|
9
|
+
let(:details) do
|
|
10
|
+
{
|
|
11
|
+
certificate: 'E136924',
|
|
12
|
+
description: 'Marine Navigation',
|
|
13
|
+
effective_date: Time.now.strftime('%Y-%m-%dT00:00:00'),
|
|
14
|
+
source: 'Online Exams System',
|
|
15
|
+
code: 'MN',
|
|
16
|
+
type_code: 'CRS'
|
|
17
|
+
}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
before { education.api.imis_id = 6374 }
|
|
21
|
+
|
|
22
|
+
describe '#get' do
|
|
23
|
+
it 'loads a specific object' do
|
|
24
|
+
expect(education.get(90737)).to be_a(Usps::Imis::Data)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'returns specific fields' do
|
|
28
|
+
expect(education.get(90737, 'ABC_Product_Code', 'ABC_Other_Code')).to eq(%w[CRS AP])
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe '#get_field' do
|
|
33
|
+
it 'returns a specific field' do
|
|
34
|
+
expect(education.get_field(90737, 'ABC_Product_Code')).to eq('CRS')
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe '#get_fields' do
|
|
39
|
+
it 'returns specific fields' do
|
|
40
|
+
expect(education.get_fields(90737, 'ABC_Product_Code', 'ABC_Other_Code')).to eq(%w[CRS AP])
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# rubocop:disable RSpec/ExampleLength
|
|
45
|
+
it 'interacts with records correctly', :aggregate_failures do
|
|
46
|
+
new_record = education.create(details)
|
|
47
|
+
expect(new_record).to be_a(Usps::Imis::Data)
|
|
48
|
+
|
|
49
|
+
ordinal = new_record.ordinal
|
|
50
|
+
|
|
51
|
+
update_result =
|
|
52
|
+
education.update(details.merge(source: 'Online Exams System - Modified', ordinal:))
|
|
53
|
+
expect(update_result['ABC_Educ_Source_System']).to eq('Online Exams System - Modified')
|
|
54
|
+
|
|
55
|
+
put_fields_result = education.put_fields(ordinal, 'ABC_Educ_Source_System' => 'Online Exams System - Mod2')
|
|
56
|
+
expect(put_fields_result['ABC_Educ_Source_System']).to eq('Online Exams System - Mod2')
|
|
57
|
+
|
|
58
|
+
expect(education.destroy(ordinal)).to be(true)
|
|
59
|
+
end
|
|
60
|
+
# rubocop:enable RSpec/ExampleLength
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
describe 'initialization with ID' do
|
|
64
|
+
it 'can initialize with an iMIS ID' do
|
|
65
|
+
panel = described_class.new(imis_id: 6374)
|
|
66
|
+
|
|
67
|
+
expect(panel.api.imis_id).to eq(6374)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'spec_helper'
|
|
4
4
|
|
|
5
|
-
describe Usps::Imis::
|
|
5
|
+
describe Usps::Imis::Panels::Vsc do
|
|
6
6
|
let(:vsc) { described_class.new }
|
|
7
7
|
|
|
8
8
|
let(:details) do
|
|
@@ -17,22 +17,21 @@ describe Usps::Imis::Panel::Vsc do
|
|
|
17
17
|
|
|
18
18
|
describe '#get' do
|
|
19
19
|
it 'loads a specific object' do
|
|
20
|
-
expect(vsc.get(1433)).to be_a(
|
|
20
|
+
expect(vsc.get(1433)).to be_a(Usps::Imis::Data)
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
# rubocop:disable RSpec/ExampleLength
|
|
25
25
|
it 'handles new records correctly', :aggregate_failures do
|
|
26
26
|
new_record = vsc.create(details)
|
|
27
|
-
expect(new_record).to be_a(
|
|
27
|
+
expect(new_record).to be_a(Usps::Imis::Data)
|
|
28
28
|
|
|
29
|
-
ordinal = new_record
|
|
29
|
+
ordinal = new_record.ordinal
|
|
30
30
|
|
|
31
31
|
update_result = vsc.update(details.merge(count: 43, ordinal:))
|
|
32
|
-
|
|
33
|
-
expect(updated['Value']['$value']).to eq(43)
|
|
32
|
+
expect(update_result['Quantity']).to eq(43)
|
|
34
33
|
|
|
35
|
-
expect(vsc.destroy(ordinal)).to
|
|
34
|
+
expect(vsc.destroy(ordinal)).to be(true)
|
|
36
35
|
end
|
|
37
36
|
# rubocop:enable RSpec/ExampleLength
|
|
38
37
|
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Usps::Imis::Properties do
|
|
6
|
+
let(:builder) { described_class.new }
|
|
7
|
+
|
|
8
|
+
it 'wraps boolean property values' do
|
|
9
|
+
expect(builder.send(:wrap, true)).to eq(
|
|
10
|
+
'$type' => 'System.Boolean', '$value' => true
|
|
11
|
+
)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'raises an error for unexpected property types' do
|
|
15
|
+
expect { builder.send(:wrap, {}) }.to raise_error(
|
|
16
|
+
Usps::Imis::Errors::UnexpectedPropertyTypeError, 'Unexpected property type: {}'
|
|
17
|
+
)
|
|
18
|
+
end
|
|
19
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/usps-imis-api.gemspec
CHANGED
|
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
|
7
7
|
s.version = Usps::Imis::VERSION
|
|
8
8
|
s.summary = 'iMIS API Wrapper'
|
|
9
9
|
s.description = 'A wrapper for the iMIS API.'
|
|
10
|
-
s.homepage = '
|
|
10
|
+
s.homepage = 'https://github.com/unitedstatespowersquadrons/imis-api-ruby'
|
|
11
11
|
s.authors = ['Julian Fiander']
|
|
12
12
|
s.email = 'jsfiander@gmail.com'
|
|
13
13
|
s.require_paths = %w[lib]
|
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.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Julian Fiander
|
|
@@ -41,35 +41,47 @@ files:
|
|
|
41
41
|
- Readme.md
|
|
42
42
|
- bin/console
|
|
43
43
|
- bin/setup
|
|
44
|
-
- lib/ext/hash.rb
|
|
45
44
|
- lib/usps/imis.rb
|
|
46
45
|
- lib/usps/imis/api.rb
|
|
47
46
|
- lib/usps/imis/business_object.rb
|
|
48
47
|
- lib/usps/imis/config.rb
|
|
49
|
-
- lib/usps/imis/
|
|
50
|
-
- lib/usps/imis/error
|
|
51
|
-
- lib/usps/imis/
|
|
48
|
+
- lib/usps/imis/data.rb
|
|
49
|
+
- lib/usps/imis/error.rb
|
|
50
|
+
- lib/usps/imis/errors/api_error.rb
|
|
51
|
+
- lib/usps/imis/errors/config_error.rb
|
|
52
|
+
- lib/usps/imis/errors/locked_id_error.rb
|
|
53
|
+
- lib/usps/imis/errors/mapper_error.rb
|
|
54
|
+
- lib/usps/imis/errors/not_found_error.rb
|
|
55
|
+
- lib/usps/imis/errors/panel_unimplemented_error.rb
|
|
56
|
+
- lib/usps/imis/errors/response_error.rb
|
|
57
|
+
- lib/usps/imis/errors/unexpected_property_type_error.rb
|
|
52
58
|
- lib/usps/imis/mapper.rb
|
|
53
|
-
- lib/usps/imis/
|
|
54
|
-
- lib/usps/imis/
|
|
55
|
-
- lib/usps/imis/
|
|
56
|
-
- lib/usps/imis/
|
|
59
|
+
- lib/usps/imis/mocks.rb
|
|
60
|
+
- lib/usps/imis/mocks/business_object.rb
|
|
61
|
+
- lib/usps/imis/panels.rb
|
|
62
|
+
- lib/usps/imis/panels/base_panel.rb
|
|
63
|
+
- lib/usps/imis/panels/education.rb
|
|
64
|
+
- lib/usps/imis/panels/vsc.rb
|
|
65
|
+
- lib/usps/imis/properties.rb
|
|
66
|
+
- lib/usps/imis/query.rb
|
|
57
67
|
- lib/usps/imis/requests.rb
|
|
58
68
|
- lib/usps/imis/version.rb
|
|
59
69
|
- spec/lib/usps/imis/api_spec.rb
|
|
60
70
|
- spec/lib/usps/imis/business_object_spec.rb
|
|
61
71
|
- spec/lib/usps/imis/config_spec.rb
|
|
62
|
-
- spec/lib/usps/imis/
|
|
63
|
-
- spec/lib/usps/imis/
|
|
72
|
+
- spec/lib/usps/imis/data_spec.rb
|
|
73
|
+
- spec/lib/usps/imis/error_spec.rb
|
|
74
|
+
- spec/lib/usps/imis/errors/response_error_spec.rb
|
|
64
75
|
- spec/lib/usps/imis/mapper_spec.rb
|
|
65
|
-
- spec/lib/usps/imis/
|
|
66
|
-
- spec/lib/usps/imis/
|
|
67
|
-
- spec/lib/usps/imis/
|
|
68
|
-
- spec/lib/usps/imis/
|
|
76
|
+
- spec/lib/usps/imis/mocks/business_object_spec.rb
|
|
77
|
+
- spec/lib/usps/imis/panels/base_panel_spec.rb
|
|
78
|
+
- spec/lib/usps/imis/panels/education_spec.rb
|
|
79
|
+
- spec/lib/usps/imis/panels/vsc_spec.rb
|
|
80
|
+
- spec/lib/usps/imis/properties_spec.rb
|
|
69
81
|
- spec/lib/usps/imis_spec.rb
|
|
70
82
|
- spec/spec_helper.rb
|
|
71
83
|
- usps-imis-api.gemspec
|
|
72
|
-
homepage:
|
|
84
|
+
homepage: https://github.com/unitedstatespowersquadrons/imis-api-ruby
|
|
73
85
|
licenses: []
|
|
74
86
|
metadata:
|
|
75
87
|
rubygems_mfa_required: 'true'
|
data/lib/ext/hash.rb
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Usps
|
|
4
|
-
module Imis
|
|
5
|
-
module Error
|
|
6
|
-
# Base error class for all internal exceptions
|
|
7
|
-
#
|
|
8
|
-
class ApiError < StandardError
|
|
9
|
-
# Additional call-specific metadata to pass through to Bugsnag
|
|
10
|
-
#
|
|
11
|
-
attr_accessor :metadata
|
|
12
|
-
|
|
13
|
-
# A new instance of +ApiError+
|
|
14
|
-
#
|
|
15
|
-
# @param message [String] The base exception message
|
|
16
|
-
# @param metadata [Hash] Additional call-specific metadata to pass through to Bugsnag
|
|
17
|
-
#
|
|
18
|
-
def initialize(message, metadata = {})
|
|
19
|
-
super(message)
|
|
20
|
-
@metadata = metadata
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# Additional metadata to include in Bugsnag reports
|
|
24
|
-
#
|
|
25
|
-
# Can include fields at the top level, which will be shows on the custom tab
|
|
26
|
-
#
|
|
27
|
-
# Can include fields nested under a top-level key, which will be shown on a tab with the
|
|
28
|
-
# top-level key as its name
|
|
29
|
-
#
|
|
30
|
-
# @return [Hash]
|
|
31
|
-
#
|
|
32
|
-
def bugsnag_meta_data
|
|
33
|
-
metadata == {} ? {} : base_metadata
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
private
|
|
37
|
-
|
|
38
|
-
def base_metadata
|
|
39
|
-
{ api: metadata }
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|