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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad19ed5d60abf0531fdc10f01113fada6a5bc9413574bda31783d41507000c87
4
- data.tar.gz: 8d0fcf7a1881cfb262a248683346489be5e28f2d57ce8a18923210780fc9e847
3
+ metadata.gz: 4a27bda1b2938e0cfedde1da424a7694a001c539deb705032c4e7aefe126361a
4
+ data.tar.gz: f2fccb24b0f76b452a6b7b3719e225f6659f53d8e6251be130d920bff1f299dd
5
5
  SHA512:
6
- metadata.gz: 8abd5d2a143699aa7f184def0c97358bbc475c2248a1f56c5f5104ff9b9e08f917dd1f285637109ed3e0026c91e049661bf77a73f40bc56082a1d286d180951b
7
- data.tar.gz: 823f16f923c71f7f0822a0d48fbe84152ea0221a96ded092570ee5554242acf9b619688625708bd9af89117f3d081c26125c02b5b879378e971072c4770cac08
6
+ metadata.gz: 6a86560e9f859589317faf46dc524105d2b77b2e25d869c6eec604fa1f98592ed4bdf59a6675078e89345782ab45017fdf34f5895d99cf3944473fccf05e9faf
7
+ data.tar.gz: aea9d7c488dec4f017a3252d5294cc9f9fa03eed3e374bbd4d9cc0926c9e76b6c725df5a65ea6eca3314e483153e80be05002917fa49aab8993884fe4cfbd3fd
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps-imis-api (0.1.2)
4
+ usps-imis-api (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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(:mm, 15)
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(:mm, 15)
149
+ mapper.update(mm: 15)
150
150
  end
151
151
  ```
152
152
 
data/lib/imis/api.rb CHANGED
@@ -77,6 +77,10 @@ module Imis
77
77
  @mapper ||= Mapper.new(self)
78
78
  end
79
79
 
80
+ def update(data)
81
+ mapper.update(data)
82
+ end
83
+
80
84
  private
81
85
 
82
86
  def client(uri)
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 a single field name
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
- def update(field_name, value)
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
- api.put(business_object_name, { field => value })
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(
@@ -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(:mm, 15)).to be_a(Hash)
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(:something, 'anything') }.to raise_error(
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.'
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'usps-imis-api'
5
- s.version = '0.1.2'
5
+ s.version = '0.1.3'
6
6
  s.summary = 'iMIS API Wrapper'
7
7
  s.description = 'A wrapper for the iMIS API.'
8
8
  s.homepage = 'http://rubygems.org/gems/usps-imis-api'
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.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander