usps-imis-api 0.6.1 → 0.6.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 +29 -2
- data/lib/usps/imis/business_object.rb +13 -0
- data/lib/usps/imis/version.rb +1 -1
- data/lib/usps/imis.rb +2 -0
- data/spec/lib/usps/imis/business_object_spec.rb +30 -20
- 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: eeff742b04ebe9046cb57d7cf8501b3a175a9e50729cba6f812f44ed12d90c43
|
|
4
|
+
data.tar.gz: 5960918afa1fd57e141cdd52408380ce135e53fa81eb7da4f9c48849436974ac
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: eb267af35e92cfa0c7511b1ed78eae72b6811569324486ea0f411dcf988c0f5d0515f079b0356cac0776555dd93b62f677fccc0fcf78ae43e424cb8f856469a6
|
|
7
|
+
data.tar.gz: 83c81ac9c0ef3ef658ae32c6de1026ec9aa5bea89f6f4e7bd2e0b5e7bcd6052562d93ab4d7f01db7b5bb4ab57e1eb1b00fe26a8121efeadf013cd2007a7e32e9
|
data/Gemfile.lock
CHANGED
data/Readme.md
CHANGED
|
@@ -13,7 +13,7 @@ gem install usps-imis-api
|
|
|
13
13
|
or add this line to your Gemfile:
|
|
14
14
|
|
|
15
15
|
```ruby
|
|
16
|
-
gem 'usps-imis-api', '~> 0.6.
|
|
16
|
+
gem 'usps-imis-api', '~> 0.6.3'
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
## Setup
|
|
@@ -87,6 +87,16 @@ api.imis_id = 31092
|
|
|
87
87
|
data = api.on('ABC_ASC_Individual_Demog').get
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
+
### GET Field
|
|
91
|
+
|
|
92
|
+
To fetch a specific field from member data, run e.g.:
|
|
93
|
+
|
|
94
|
+
```ruby
|
|
95
|
+
api.imis_id = 31092
|
|
96
|
+
|
|
97
|
+
tot_mms = api.on('ABC_ASC_Individual_Demog').get_field('TotMMS')
|
|
98
|
+
```
|
|
99
|
+
|
|
90
100
|
### PUT Fields
|
|
91
101
|
|
|
92
102
|
To update member data, run e.g.:
|
|
@@ -204,7 +214,7 @@ previous value.
|
|
|
204
214
|
|
|
205
215
|
```ruby
|
|
206
216
|
api.with(31092) do
|
|
207
|
-
# These
|
|
217
|
+
# These requests are identical:
|
|
208
218
|
|
|
209
219
|
on('ABC_ASC_Individual_Demog') { put('TotMMS' => 15) }
|
|
210
220
|
|
|
@@ -222,6 +232,23 @@ api.with(6374) do
|
|
|
222
232
|
end
|
|
223
233
|
```
|
|
224
234
|
|
|
235
|
+
```ruby
|
|
236
|
+
api.with(31092) do
|
|
237
|
+
# These requests are identical:
|
|
238
|
+
|
|
239
|
+
api.on('ABC_ASC_Individual_Demog') do
|
|
240
|
+
get['Properties']['$values'].find { |hash| hash['Name'] == 'TotMMS' }['Value']['$value']
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
api.on('ABC_ASC_Individual_Demog') { get_field('TotMMS') }
|
|
244
|
+
|
|
245
|
+
api.on('ABC_ASC_Individual_Demog').get_field('TotMMS')
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
# This request fetches the same data, but leaves the iMIS ID selected
|
|
249
|
+
api.with(31092).on('ABC_ASC_Individual_Demog').get_field('TotMMS')
|
|
250
|
+
```
|
|
251
|
+
|
|
225
252
|
## Exception Handling
|
|
226
253
|
|
|
227
254
|
All internal exceptions inherit from `Usps::Imis::ApiError`.
|
|
@@ -40,6 +40,19 @@ module Usps
|
|
|
40
40
|
JSON.parse(result.body)
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
+
# Get a single named field from a business object for the current member
|
|
44
|
+
#
|
|
45
|
+
# @param name [String] Field name to return
|
|
46
|
+
#
|
|
47
|
+
# @return [Hash] Response data from the API
|
|
48
|
+
#
|
|
49
|
+
def get_field(name)
|
|
50
|
+
values = get['Properties']['$values']
|
|
51
|
+
value = values.find { |hash| hash['Name'] == name }['Value']
|
|
52
|
+
|
|
53
|
+
value.is_a?(String) ? value : value['$value']
|
|
54
|
+
end
|
|
55
|
+
|
|
43
56
|
# Update only specific fields on a business object for the current member
|
|
44
57
|
#
|
|
45
58
|
# @param fields [Hash] Conforms to pattern +{ field_key => value }+
|
data/lib/usps/imis/version.rb
CHANGED
data/lib/usps/imis.rb
CHANGED
|
@@ -6,31 +6,41 @@ 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
|
+
let(:expected) do
|
|
10
|
+
{
|
|
11
|
+
'Properties' => {
|
|
12
|
+
'$values' => [
|
|
13
|
+
{ 'Name' => 'Stub iMIS ID', 'Value' => { '$value' => '31092' } },
|
|
14
|
+
{ 'Name' => 'Stub Integer', 'Value' => { '$value' => 43 } },
|
|
15
|
+
{ 'Name' => 'Stub String', 'Value' => 'other' }
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
before do
|
|
22
|
+
allow(business_object).to receive(:get).and_return({
|
|
23
|
+
'Properties' => {
|
|
24
|
+
'$values' => [
|
|
25
|
+
{ 'Name' => 'Stub iMIS ID', 'Value' => { '$value' => '31092' } },
|
|
26
|
+
{ 'Name' => 'Stub Integer', 'Value' => { '$value' => 42 } },
|
|
27
|
+
{ 'Name' => 'Stub String', 'Value' => 'something' }
|
|
28
|
+
]
|
|
19
29
|
}
|
|
30
|
+
})
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe '#get_field' do
|
|
34
|
+
it 'returns a string value' do
|
|
35
|
+
expect(business_object.get_field('Stub String')).to eq('something')
|
|
20
36
|
end
|
|
21
37
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
'Properties' => {
|
|
25
|
-
'$values' => [
|
|
26
|
-
{ 'Name' => 'Stub iMIS ID', 'Value' => { '$value' => '31092' } },
|
|
27
|
-
{ 'Name' => 'Stub Integer', 'Value' => { '$value' => 42 } },
|
|
28
|
-
{ 'Name' => 'Stub String', 'Value' => 'something' }
|
|
29
|
-
]
|
|
30
|
-
}
|
|
31
|
-
})
|
|
38
|
+
it 'returns an integer value' do
|
|
39
|
+
expect(business_object.get_field('Stub Integer')).to eq(42)
|
|
32
40
|
end
|
|
41
|
+
end
|
|
33
42
|
|
|
43
|
+
describe '#filter_fields' do
|
|
34
44
|
it 'formats fields correctly' do
|
|
35
45
|
updated = business_object.send(:filter_fields, 'Stub Integer' => 43, 'Stub String' => 'other')
|
|
36
46
|
|