usps-imis-api 0.9.7 → 0.9.8
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 +3 -0
- data/Gemfile.lock +1 -1
- data/Readme.md +10 -2
- data/lib/usps/imis/api.rb +5 -0
- data/lib/usps/imis/business_object.rb +10 -0
- data/lib/usps/imis/error.rb +2 -0
- data/lib/usps/imis/mapper.rb +23 -0
- data/lib/usps/imis/panels/base_panel.rb +10 -0
- data/lib/usps/imis/version.rb +1 -1
- data/spec/lib/usps/imis/business_object_spec.rb +62 -49
- 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: 80cb6198e125d3dc201641a6a70c639c8890094582fe6c293c807fb212a59738
|
|
4
|
+
data.tar.gz: e5382f2b08c9bffd26204cd06c3d55bc8604e7fa62ebc612a5b88a42a4029ab1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ba2f8613ca13a61eda5d8a0c5a229e09d8226e74ca8611f83e80d6d3259e2f120f6fddab9ee2eb7740c0de150de8462537219147fe7d3c2aceafc5e0c8652dfc
|
|
7
|
+
data.tar.gz: 472196fce4e1a5e05287889b6d70e56bc72f5326944dafd114527865688d82f3208d7e4ae38b4161a176ea43663a7981eee196e145bbeac3d62f9c2f9b941713
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/Readme.md
CHANGED
|
@@ -213,7 +213,7 @@ 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 fetch / update interfaces:
|
|
216
|
+
Mapper class to further simplify the `fetch` / `update` interfaces:
|
|
217
217
|
|
|
218
218
|
```ruby
|
|
219
219
|
mm = api.mapper.fetch(:mm)
|
|
@@ -234,6 +234,7 @@ api[:mm]
|
|
|
234
234
|
|
|
235
235
|
```ruby
|
|
236
236
|
api.update(mm: 15)
|
|
237
|
+
api[:mm] = 15
|
|
237
238
|
```
|
|
238
239
|
|
|
239
240
|
If there is no known mapping for the requested field, the Mapper will give up, but will provide
|
|
@@ -272,6 +273,7 @@ ordinal = created.raw['Identity']['IdentityElements']['$values'][1].to_i # Value
|
|
|
272
273
|
vsc.update(certificate: 'E136924', year: 2024, count: 43, ordinal: ordinal)
|
|
273
274
|
|
|
274
275
|
vsc.put_fields(ordinal, 'Quantity' => 44)
|
|
276
|
+
vsc['Quantity'] = 44
|
|
275
277
|
|
|
276
278
|
vsc.destroy(ordinal)
|
|
277
279
|
```
|
|
@@ -305,7 +307,12 @@ api.with(31092) do
|
|
|
305
307
|
mapper.update(mm: 15)
|
|
306
308
|
|
|
307
309
|
update(mm: 15)
|
|
310
|
+
|
|
311
|
+
mapper[:mm] = 15
|
|
308
312
|
end
|
|
313
|
+
|
|
314
|
+
# This request fetches the same data, but leaves the iMIS ID selected
|
|
315
|
+
api.with(31092)[:mm] = 15
|
|
309
316
|
```
|
|
310
317
|
|
|
311
318
|
```ruby
|
|
@@ -333,8 +340,9 @@ api.with(31092) do
|
|
|
333
340
|
on('ABC_ASC_Individual_Demog')['TotMMS']
|
|
334
341
|
end
|
|
335
342
|
|
|
336
|
-
#
|
|
343
|
+
# These requests fetch the same data, but leave the iMIS ID selected
|
|
337
344
|
api.with(31092).on('ABC_ASC_Individual_Demog').get_field('TotMMS')
|
|
345
|
+
api.with(31092).on('ABC_ASC_Individual_Demog')['TotMMS']
|
|
338
346
|
```
|
|
339
347
|
|
|
340
348
|
### Data Methods
|
data/lib/usps/imis/api.rb
CHANGED
|
@@ -133,6 +133,11 @@ module Usps
|
|
|
133
133
|
def fetch(field_key) = mapper.fetch(field_key)
|
|
134
134
|
alias [] fetch
|
|
135
135
|
|
|
136
|
+
# Convenience alias for updating mapped fields
|
|
137
|
+
#
|
|
138
|
+
def put_field(field_key, value) = update(field_key => value)
|
|
139
|
+
alias []= put_field
|
|
140
|
+
|
|
136
141
|
# Convenience alias for updating mapped fields
|
|
137
142
|
#
|
|
138
143
|
def update(data) = mapper.update(data)
|
|
@@ -66,6 +66,16 @@ module Usps
|
|
|
66
66
|
end
|
|
67
67
|
alias fetch_all get_fields
|
|
68
68
|
|
|
69
|
+
# Update a single named field on a business object for the current member
|
|
70
|
+
#
|
|
71
|
+
# @param field [String] Name of the field
|
|
72
|
+
# @param value Value of the field
|
|
73
|
+
#
|
|
74
|
+
# @return [Usps::Imis::Data] Response data from the API
|
|
75
|
+
#
|
|
76
|
+
def put_field(field, value) = put(filter_fields(field => value))
|
|
77
|
+
alias []= put_field
|
|
78
|
+
|
|
69
79
|
# Update only specific fields on a business object for the current member
|
|
70
80
|
#
|
|
71
81
|
# @param fields [Hash] Conforms to pattern +{ field_key => value }+
|
data/lib/usps/imis/error.rb
CHANGED
data/lib/usps/imis/mapper.rb
CHANGED
|
@@ -28,6 +28,16 @@ module Usps
|
|
|
28
28
|
@api.imis_id = imis_id if imis_id
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
+
# Get a member's data for a specific field by arbitrary field name
|
|
32
|
+
#
|
|
33
|
+
# Does not require knowing which business object / iMIS-specific field name to use
|
|
34
|
+
#
|
|
35
|
+
# Only available for fields defined in +FIELD_MAPPING+
|
|
36
|
+
#
|
|
37
|
+
# @param field_key [Symbol] Internal name of the field
|
|
38
|
+
#
|
|
39
|
+
# @return Value of the field
|
|
40
|
+
#
|
|
31
41
|
def fetch(field_key)
|
|
32
42
|
missing_mapping!(field_key) unless FIELD_MAPPING.key?(field_key.to_sym)
|
|
33
43
|
|
|
@@ -36,6 +46,19 @@ module Usps
|
|
|
36
46
|
end
|
|
37
47
|
alias [] fetch
|
|
38
48
|
|
|
49
|
+
# Update a member's data for a specific field by arbitrary field name
|
|
50
|
+
#
|
|
51
|
+
# Does not require knowing which business object / iMIS-specific field name to use
|
|
52
|
+
#
|
|
53
|
+
# Only available for fields defined in +FIELD_MAPPING+
|
|
54
|
+
#
|
|
55
|
+
# @param field_key [Symbol] Internal name of the field
|
|
56
|
+
#
|
|
57
|
+
# @return Value of the field
|
|
58
|
+
#
|
|
59
|
+
def put_field(field_key, value) = update(field_key => value)
|
|
60
|
+
alias []= put_field
|
|
61
|
+
|
|
39
62
|
# Update a member's data on multiple affected business objects by arbitrary field names
|
|
40
63
|
#
|
|
41
64
|
# Does not require knowing which business object / iMIS-specific field name to use
|
|
@@ -49,6 +49,16 @@ module Usps
|
|
|
49
49
|
def get_fields(ordinal, *fields) = api.on(business_object, ordinal:).get_fields(*fields)
|
|
50
50
|
alias fetch_all get_fields
|
|
51
51
|
|
|
52
|
+
# Update a single named field on a business object for the current member
|
|
53
|
+
#
|
|
54
|
+
# @param field [String] Name of the field
|
|
55
|
+
# @param value Value of the field
|
|
56
|
+
#
|
|
57
|
+
# @return [Usps::Imis::Data] Response data from the API
|
|
58
|
+
#
|
|
59
|
+
def put_field(field, value) = api.on(business_object, ordinal:).put_field(field, value)
|
|
60
|
+
alias []= put_field
|
|
61
|
+
|
|
52
62
|
# Update only specific fields on a Panel for the current member
|
|
53
63
|
#
|
|
54
64
|
# @param ordinal [Integer] The ordinal identifier for the desired object
|
data/lib/usps/imis/version.rb
CHANGED
|
@@ -3,72 +3,85 @@
|
|
|
3
3
|
require 'spec_helper'
|
|
4
4
|
|
|
5
5
|
describe Usps::Imis::BusinessObject do
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
{ 'Name' => 'Stub Integer', 'Value' => { '$value' => 42 } },
|
|
16
|
-
{ 'Name' => 'Stub String', 'Value' => 'something' }
|
|
17
|
-
]
|
|
18
|
-
}
|
|
19
|
-
]
|
|
20
|
-
)
|
|
6
|
+
describe '#put_field' do
|
|
7
|
+
let(:business_object) { api.on('ABC_ASC_Individual_Demog') }
|
|
8
|
+
let(:api) { Usps::Imis::Api.new.with(31092) }
|
|
9
|
+
|
|
10
|
+
before { business_object.put_field('TotMMS', 15) }
|
|
11
|
+
|
|
12
|
+
it 'submits the correct update request' do
|
|
13
|
+
expect { business_object['TotMMS'] = 16 }.to change { business_object['TotMMS'] }.from(15).to(16)
|
|
14
|
+
end
|
|
21
15
|
end
|
|
22
16
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
context 'with stubbed data' do
|
|
18
|
+
let(:business_object) { described_class.new(api, 'Stub') }
|
|
19
|
+
let(:api) { Usps::Imis::Api.new }
|
|
20
|
+
|
|
21
|
+
before do
|
|
22
|
+
allow(business_object).to receive(:raw_object).and_return(
|
|
23
|
+
Usps::Imis::Data[
|
|
24
|
+
'Properties' => {
|
|
25
|
+
'$values' => [
|
|
26
|
+
{ 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
|
|
27
|
+
{ 'Name' => 'Stub Integer', 'Value' => { '$value' => 42 } },
|
|
28
|
+
{ 'Name' => 'Stub String', 'Value' => 'something' }
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
)
|
|
26
33
|
end
|
|
27
34
|
|
|
28
|
-
describe '
|
|
29
|
-
|
|
35
|
+
describe '#get' do
|
|
36
|
+
it 'returns multiple values' do
|
|
37
|
+
expect(business_object.get('Stub String', 'Stub Integer')).to eq(['something', 42])
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe 'delegation to get_fields' do
|
|
41
|
+
before { allow(business_object).to receive(:get_fields).with('Stub String', 'Stub Integer') }
|
|
30
42
|
|
|
31
|
-
|
|
32
|
-
|
|
43
|
+
it 'delegates to get_fields' do
|
|
44
|
+
business_object.get('Stub String', 'Stub Integer')
|
|
33
45
|
|
|
34
|
-
|
|
46
|
+
expect(business_object).to have_received(:get_fields).with('Stub String', 'Stub Integer')
|
|
47
|
+
end
|
|
35
48
|
end
|
|
36
49
|
end
|
|
37
|
-
end
|
|
38
50
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
describe '#get_field' do
|
|
52
|
+
it 'returns a string value' do
|
|
53
|
+
expect(business_object.get_field('Stub String')).to eq('something')
|
|
54
|
+
end
|
|
43
55
|
|
|
44
|
-
|
|
45
|
-
|
|
56
|
+
it 'returns an integer value' do
|
|
57
|
+
expect(business_object.get_field('Stub Integer')).to eq(42)
|
|
58
|
+
end
|
|
46
59
|
end
|
|
47
|
-
end
|
|
48
60
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
61
|
+
describe '#get_fields' do
|
|
62
|
+
it 'returns multiple values' do
|
|
63
|
+
expect(business_object.get_fields('Stub String', 'Stub Integer')).to eq(['something', 42])
|
|
64
|
+
end
|
|
52
65
|
end
|
|
53
|
-
end
|
|
54
66
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
describe '#filter_fields' do
|
|
68
|
+
let(:expected) do
|
|
69
|
+
{
|
|
70
|
+
'Properties' => {
|
|
71
|
+
'$values' => [
|
|
72
|
+
{ 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
|
|
73
|
+
{ 'Name' => 'Stub Integer', 'Value' => { '$value' => 43 } },
|
|
74
|
+
{ 'Name' => 'Stub String', 'Value' => 'other' }
|
|
75
|
+
]
|
|
76
|
+
}
|
|
64
77
|
}
|
|
65
|
-
|
|
66
|
-
end
|
|
78
|
+
end
|
|
67
79
|
|
|
68
|
-
|
|
69
|
-
|
|
80
|
+
it 'formats fields correctly' do
|
|
81
|
+
updated = business_object.send(:filter_fields, 'Stub Integer' => 43, 'Stub String' => 'other')
|
|
70
82
|
|
|
71
|
-
|
|
83
|
+
expect(updated).to eq(expected)
|
|
84
|
+
end
|
|
72
85
|
end
|
|
73
86
|
end
|
|
74
87
|
end
|