usps-imis-api 0.1.2 → 0.1.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/Readme.md +2 -2
- data/lib/imis/api.rb +4 -0
- data/lib/imis/mapper.rb +20 -5
- data/spec/lib/imis/api_spec.rb +5 -1
- data/spec/lib/imis/mapper_spec.rb +2 -2
- data/usps-imis-api.gemspec +1 -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: 4a27bda1b2938e0cfedde1da424a7694a001c539deb705032c4e7aefe126361a
|
4
|
+
data.tar.gz: f2fccb24b0f76b452a6b7b3719e225f6659f53d8e6251be130d920bff1f299dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a86560e9f859589317faf46dc524105d2b77b2e25d869c6eec604fa1f98592ed4bdf59a6675078e89345782ab45017fdf34f5895d99cf3944473fccf05e9faf
|
7
|
+
data.tar.gz: aea9d7c488dec4f017a3252d5294cc9f9fa03eed3e374bbd4d9cc0926c9e76b6c725df5a65ea6eca3314e483153e80be05002917fa49aab8993884fe4cfbd3fd
|
data/Gemfile.lock
CHANGED
data/Readme.md
CHANGED
@@ -129,7 +129,7 @@ For fields that have already been mapped between the ITCom database and iMIS, yo
|
|
129
129
|
Mapper class to further simplify the update interface:
|
130
130
|
|
131
131
|
```ruby
|
132
|
-
api.mapper.update(:
|
132
|
+
api.mapper.update(mm: 15)
|
133
133
|
```
|
134
134
|
|
135
135
|
If there is no known mapping for the requested field, the Mapper will give up, but will provide
|
@@ -146,7 +146,7 @@ previous value.
|
|
146
146
|
api.with(31092) do
|
147
147
|
# These two requests are identical:
|
148
148
|
put('ABC_ASC_Individual_Demog', { 'TotMMS' => 15 })
|
149
|
-
mapper.update(:
|
149
|
+
mapper.update(mm: 15)
|
150
150
|
end
|
151
151
|
```
|
152
152
|
|
data/lib/imis/api.rb
CHANGED
data/lib/imis/mapper.rb
CHANGED
@@ -14,22 +14,37 @@ module Imis
|
|
14
14
|
@api = api
|
15
15
|
end
|
16
16
|
|
17
|
-
# Update a member's data by
|
17
|
+
# Update a member's data on multiple affected business objects by arbitrary field names
|
18
18
|
# Does not require knowing which business object / iMIS-specific field name to use
|
19
19
|
#
|
20
20
|
# Only available for previously-mapped fields
|
21
21
|
#
|
22
|
-
|
22
|
+
# `data` is a hash of shape { field_key => value }
|
23
|
+
#
|
24
|
+
def update(data)
|
25
|
+
updates = data.each_with_object({}) do |(field_key, value), hash|
|
26
|
+
map_update(field_key) do |business_object_name, field|
|
27
|
+
hash[business_object_name] ||= {}
|
28
|
+
hash[business_object_name][field] = value
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
updates.map do |business_object_name, field_updates|
|
33
|
+
api.put(business_object_name, field_updates)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def map_update(field_name)
|
23
40
|
if FIELD_MAPPING.key?(field_name.to_sym)
|
24
41
|
business_object_name, field = FIELD_MAPPING[field_name.to_sym]
|
25
|
-
|
42
|
+
yield(business_object_name, field)
|
26
43
|
else
|
27
44
|
missing_mapping(field_name)
|
28
45
|
end
|
29
46
|
end
|
30
47
|
|
31
|
-
private
|
32
|
-
|
33
48
|
def missing_mapping(field_name)
|
34
49
|
unless ENV['TESTING']
|
35
50
|
warn(
|
data/spec/lib/imis/api_spec.rb
CHANGED
@@ -20,8 +20,12 @@ describe Imis::Api do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
describe '#with' do
|
23
|
-
it 'sends an update' do
|
23
|
+
it 'sends an update from put' do
|
24
24
|
expect(api.with(31092) { put('ABC_ASC_Individual_Demog', { 'TotMMS' => 15 }) }).to be_a(Hash)
|
25
25
|
end
|
26
|
+
|
27
|
+
it 'sends an update from update' do
|
28
|
+
expect(api.with(31092) { update(mm: 15) }.first).to be_a(Hash)
|
29
|
+
end
|
26
30
|
end
|
27
31
|
end
|
@@ -9,11 +9,11 @@ describe Imis::Mapper do
|
|
9
9
|
before { api.imis_id = 31092 }
|
10
10
|
|
11
11
|
it 'sends a mapped update' do
|
12
|
-
expect(api.mapper.update(:
|
12
|
+
expect(api.mapper.update(mm: 15).first).to be_a(Hash)
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'raises for unmapped updates' do
|
16
|
-
expect { api.mapper.update(:
|
16
|
+
expect { api.mapper.update(something: 'anything') }.to raise_error(
|
17
17
|
Imis::Error::Mapper,
|
18
18
|
'Unrecognized field: "something". ' \
|
19
19
|
'Please report what data you are attempting to work with to ITCom leadership.'
|
data/usps-imis-api.gemspec
CHANGED