usps-imis-api 0.9.4 → 0.9.6
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/Readme.md +14 -3
- data/lib/usps/imis/api.rb +6 -3
- data/lib/usps/imis/errors/mapper_error.rb +1 -1
- data/lib/usps/imis/mapper.rb +18 -10
- data/lib/usps/imis/mocks/business_object.rb +12 -2
- data/lib/usps/imis/version.rb +1 -1
- data/spec/lib/usps/imis/mapper_spec.rb +24 -0
- data/spec/lib/usps/imis/mocks/business_object_spec.rb +9 -1
- 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: d2b1b801709e2ccfbbb85b2a3f2393cc9132b016264e573d01a91bb3696a211e
|
|
4
|
+
data.tar.gz: 76abe88f06a0f2246d2845815d57cd35fcf63536feb467865cf609ffd4591b47
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4a16a5b54c2547ce1fd5db54589a3a741320be6b62e4ad7bd057d3d074b205abbd35e10460870c1e69bdf97a93a81b7f350cf1a76d512039c37fc7944c75721d
|
|
7
|
+
data.tar.gz: 0ffc668c62f27783fd0a01c3a6bca8bc2fdc2e8c350c0b043e592105bcffa4fceb7f43b6eb6cd44bb91f7538a4e0d05a14c0554b1a566a97c2a081f625cd2486
|
data/Gemfile.lock
CHANGED
data/Readme.md
CHANGED
|
@@ -34,7 +34,7 @@ Usps::Imis.configure do |config|
|
|
|
34
34
|
config.password = ENV['IMIS_PASSWORD']
|
|
35
35
|
|
|
36
36
|
# These options will use these defaults
|
|
37
|
-
config.logger = Logger.new($stdout)
|
|
37
|
+
config.logger = ActiveSupport::TaggedLogging.new(Logger.new($stdout))
|
|
38
38
|
config.logger.level = :info
|
|
39
39
|
end
|
|
40
40
|
```
|
|
@@ -213,13 +213,24 @@ end
|
|
|
213
213
|
### Field Mapper
|
|
214
214
|
|
|
215
215
|
For fields that have already been mapped between the ITCom database and iMIS, you can use the
|
|
216
|
-
Mapper class to further simplify the update
|
|
216
|
+
Mapper class to further simplify the fetch / update interfaces:
|
|
217
|
+
|
|
218
|
+
```ruby
|
|
219
|
+
mm = api.mapper.fetch(:mm)
|
|
220
|
+
mm = api.mapper[:mm]
|
|
221
|
+
```
|
|
217
222
|
|
|
218
223
|
```ruby
|
|
219
224
|
api.mapper.update(mm: 15)
|
|
220
225
|
```
|
|
221
226
|
|
|
222
|
-
For simplicity, you can also call `
|
|
227
|
+
For simplicity, you can also call `fetch` (or simply use Hash access syntax) and `update` on the
|
|
228
|
+
`Api` class directly:
|
|
229
|
+
|
|
230
|
+
```ruby
|
|
231
|
+
api.fetch(:mm)
|
|
232
|
+
api[:mm]
|
|
233
|
+
```
|
|
223
234
|
|
|
224
235
|
```ruby
|
|
225
236
|
api.update(mm: 15)
|
data/lib/usps/imis/api.rb
CHANGED
|
@@ -128,11 +128,14 @@ module Usps
|
|
|
128
128
|
@mapper ||= Mapper.new(self)
|
|
129
129
|
end
|
|
130
130
|
|
|
131
|
+
# Convenience alias for reading mapped fields
|
|
132
|
+
#
|
|
133
|
+
def fetch(field_key) = mapper.fetch(field_key)
|
|
134
|
+
alias [] fetch
|
|
135
|
+
|
|
131
136
|
# Convenience alias for updating mapped fields
|
|
132
137
|
#
|
|
133
|
-
def update(data)
|
|
134
|
-
mapper.update(data)
|
|
135
|
-
end
|
|
138
|
+
def update(data) = mapper.update(data)
|
|
136
139
|
|
|
137
140
|
# Convenience accessor for available Panel objects, each using this instance as its parent
|
|
138
141
|
# +Api+
|
|
@@ -19,7 +19,7 @@ module Usps
|
|
|
19
19
|
#
|
|
20
20
|
def message
|
|
21
21
|
<<~MESSAGE.chomp
|
|
22
|
-
Mapper does not recognize field: "#{metadata[:
|
|
22
|
+
Mapper does not recognize field: "#{metadata[:field_key]}".
|
|
23
23
|
Please report what data you are attempting to work with to ITCom leadership.
|
|
24
24
|
MESSAGE
|
|
25
25
|
end
|
data/lib/usps/imis/mapper.rb
CHANGED
|
@@ -28,6 +28,14 @@ module Usps
|
|
|
28
28
|
@api.imis_id = imis_id if imis_id
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
+
def fetch(field_key)
|
|
32
|
+
missing_mapping!(field_key) unless FIELD_MAPPING.key?(field_key.to_sym)
|
|
33
|
+
|
|
34
|
+
business_object_name, field = FIELD_MAPPING[field_key]
|
|
35
|
+
api.on(business_object_name)[field]
|
|
36
|
+
end
|
|
37
|
+
alias [] fetch
|
|
38
|
+
|
|
31
39
|
# Update a member's data on multiple affected business objects by arbitrary field names
|
|
32
40
|
#
|
|
33
41
|
# Does not require knowing which business object / iMIS-specific field name to use
|
|
@@ -59,25 +67,25 @@ module Usps
|
|
|
59
67
|
|
|
60
68
|
def logger = Imis.logger('Mapper')
|
|
61
69
|
|
|
62
|
-
def map_update(
|
|
63
|
-
missing_mapping!(
|
|
70
|
+
def map_update(field_key)
|
|
71
|
+
missing_mapping!(field_key) unless FIELD_MAPPING.key?(field_key.to_sym)
|
|
64
72
|
|
|
65
|
-
business_object_name, field = FIELD_MAPPING[
|
|
73
|
+
business_object_name, field = FIELD_MAPPING[field_key.to_sym]
|
|
66
74
|
yield(business_object_name, field)
|
|
67
75
|
end
|
|
68
76
|
|
|
69
|
-
def missing_mapping!(
|
|
77
|
+
def missing_mapping!(field_key)
|
|
70
78
|
unless ENV['TESTING']
|
|
71
79
|
# :nocov:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
"
|
|
76
|
-
|
|
80
|
+
"Mapper does not know how to handle field \"#{field_key}\".\n\n" \
|
|
81
|
+
'You can use api.put_fields(business_object_name, { field_name => value }) ' \
|
|
82
|
+
"if you know the business object and iMIS-specific field name.\n\n"
|
|
83
|
+
.split("\n")
|
|
84
|
+
.each { logger.warn(it) }
|
|
77
85
|
# :nocov:
|
|
78
86
|
end
|
|
79
87
|
|
|
80
|
-
raise Errors::MapperError.new({
|
|
88
|
+
raise Errors::MapperError.new({ field_key: })
|
|
81
89
|
end
|
|
82
90
|
end
|
|
83
91
|
end
|
|
@@ -12,25 +12,35 @@ module Usps
|
|
|
12
12
|
@fields = fields.transform_keys(&:to_s)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
def get_field(name) = fields[name]
|
|
16
|
-
|
|
17
15
|
def get
|
|
18
16
|
Usps::Imis::Properties.build do |props|
|
|
19
17
|
fields.each { |name, value| props.add(name, value) }
|
|
20
18
|
end
|
|
21
19
|
end
|
|
20
|
+
alias read get
|
|
21
|
+
|
|
22
|
+
def get_field(name) = fields[name]
|
|
23
|
+
alias fetch get_field
|
|
24
|
+
alias [] get_field
|
|
25
|
+
|
|
26
|
+
def get_fields(*field_names) = field_names.map { fields[it] }
|
|
27
|
+
alias fetch_all get_fields
|
|
22
28
|
|
|
23
29
|
def put_fields(data)
|
|
24
30
|
Usps::Imis::Properties.build do |props|
|
|
25
31
|
fields.merge(data.transform_keys(&:to_s)).each { |name, value| props.add(name, value) }
|
|
26
32
|
end
|
|
27
33
|
end
|
|
34
|
+
alias patch put_fields
|
|
28
35
|
|
|
29
36
|
def put(data) = data
|
|
37
|
+
alias update put
|
|
30
38
|
|
|
31
39
|
def post(data) = data
|
|
40
|
+
alias create post
|
|
32
41
|
|
|
33
42
|
def delete = ''
|
|
43
|
+
alias destroy delete
|
|
34
44
|
end
|
|
35
45
|
end
|
|
36
46
|
end
|
data/lib/usps/imis/version.rb
CHANGED
|
@@ -13,6 +13,30 @@ describe Usps::Imis::Mapper do
|
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
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
|
+
)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
16
40
|
describe '#update' do
|
|
17
41
|
before { api.imis_id = 31092 }
|
|
18
42
|
|
|
@@ -4,11 +4,12 @@ require 'spec_helper'
|
|
|
4
4
|
|
|
5
5
|
describe Usps::Imis::Mocks::BusinessObject do
|
|
6
6
|
let(:mock) { described_class.new(**fields) }
|
|
7
|
-
let(:fields) { { TotMMS: 2 } }
|
|
7
|
+
let(:fields) { { TotMMS: 2, Something: 'Another' } }
|
|
8
8
|
|
|
9
9
|
let(:data) do
|
|
10
10
|
Usps::Imis::Properties.build do |props|
|
|
11
11
|
props.add 'TotMMS', 2
|
|
12
|
+
props.add 'Something', 'Another'
|
|
12
13
|
end
|
|
13
14
|
end
|
|
14
15
|
|
|
@@ -24,10 +25,17 @@ describe Usps::Imis::Mocks::BusinessObject do
|
|
|
24
25
|
end
|
|
25
26
|
end
|
|
26
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
|
+
|
|
27
34
|
describe 'put_fields' do
|
|
28
35
|
let(:combined_data) do
|
|
29
36
|
Usps::Imis::Properties.build do |props|
|
|
30
37
|
props.add 'TotMMS', 2
|
|
38
|
+
props.add 'Something', 'Another'
|
|
31
39
|
props.add 'SomethingElse', 'interesting'
|
|
32
40
|
end
|
|
33
41
|
end
|