usps-imis-api 0.6.14 → 0.6.16
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 +2 -0
- data/Gemfile.lock +1 -1
- data/Readme.md +30 -9
- data/lib/usps/imis/api.rb +1 -10
- data/lib/usps/imis/business_object.rb +16 -15
- data/lib/usps/imis/error/response_error.rb +1 -1
- data/lib/usps/imis/mapper.rb +1 -1
- data/lib/usps/imis/requests.rb +1 -1
- data/lib/usps/imis/version.rb +1 -1
- data/spec/lib/usps/imis/api_spec.rb +3 -3
- data/spec/lib/usps/imis/business_object_spec.rb +2 -2
- data/spec/lib/usps/imis/config_spec.rb +1 -1
- data/spec/lib/usps/imis/panel/education_spec.rb +0 -1
- data/spec/lib/usps/imis/panel/vsc_spec.rb +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: 9d68eb23f00014bc9cb6173f716084f8eff9cedfc48e70507c07a35fe8e7b207
|
|
4
|
+
data.tar.gz: fda5c7882bc758d9cfdd2889e734ff8c0d319f456e39bf1965f030765ec82a0e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bb42f257b1e4e6c6383dd9b1f37d68e9c89f358f98bfccb09c53190573da28b0259fabe27e12f50c5420daa8f009661e928463c19a48e854abd86b8dd34021f1
|
|
7
|
+
data.tar.gz: a4fb539ef056e6936e1546b303ef8b20bf52a822185063d8b6eabc042eb5b3f2b2fceb5d0cff5959c40ce524175a137dd1821783af7eea495803342c1d065cff
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/Readme.md
CHANGED
|
@@ -77,7 +77,13 @@ You can also manually set the current ID, if you already have it for a given mem
|
|
|
77
77
|
api.imis_id = imis_id
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
###
|
|
80
|
+
### Business Object and Panel Actions
|
|
81
|
+
|
|
82
|
+
Business Objects and Panels support the following actions.
|
|
83
|
+
|
|
84
|
+
Panels require passing in the ordinal identifier as an argument, except for `POST`.
|
|
85
|
+
|
|
86
|
+
#### GET
|
|
81
87
|
|
|
82
88
|
To fetch member data, run e.g.:
|
|
83
89
|
|
|
@@ -87,7 +93,9 @@ api.imis_id = 31092
|
|
|
87
93
|
data = api.on('ABC_ASC_Individual_Demog').get
|
|
88
94
|
```
|
|
89
95
|
|
|
90
|
-
|
|
96
|
+
Alias: `read`
|
|
97
|
+
|
|
98
|
+
#### GET Field
|
|
91
99
|
|
|
92
100
|
To fetch a specific field from member data, run e.g.:
|
|
93
101
|
|
|
@@ -97,7 +105,9 @@ api.imis_id = 31092
|
|
|
97
105
|
tot_mms = api.on('ABC_ASC_Individual_Demog').get_field('TotMMS')
|
|
98
106
|
```
|
|
99
107
|
|
|
100
|
-
|
|
108
|
+
Alias: `fetch`
|
|
109
|
+
|
|
110
|
+
#### PUT Fields
|
|
101
111
|
|
|
102
112
|
To update member data, run e.g.:
|
|
103
113
|
|
|
@@ -111,7 +121,9 @@ update = api.on('ABC_ASC_Individual_Demog').put_fields(data)
|
|
|
111
121
|
This method fetches the current data structure, and filters it down to just what you want to
|
|
112
122
|
update, to reduce the likelihood of update collisions or type validation failures.
|
|
113
123
|
|
|
114
|
-
|
|
124
|
+
Alias: `patch`
|
|
125
|
+
|
|
126
|
+
#### PUT
|
|
115
127
|
|
|
116
128
|
To update member data, run e.g.:
|
|
117
129
|
|
|
@@ -121,9 +133,13 @@ api.imis_id = 31092
|
|
|
121
133
|
update = api.on('ABC_ASC_Individual_Demog').put(complete_imis_object)
|
|
122
134
|
```
|
|
123
135
|
|
|
124
|
-
This method requires a complete iMIS data structure.
|
|
136
|
+
This method requires a complete iMIS data structure. However, any properties not included will be
|
|
137
|
+
left unmodified (meaning this also effectively handles `PATCH`, though iMIS does not accept that
|
|
138
|
+
HTTP verb).
|
|
139
|
+
|
|
140
|
+
Alias: `update`
|
|
125
141
|
|
|
126
|
-
|
|
142
|
+
#### POST
|
|
127
143
|
|
|
128
144
|
To create new member data, run e.g.:
|
|
129
145
|
|
|
@@ -133,7 +149,9 @@ created = api.on('ABC_ASC_Individual_Demog').post(complete_imis_object)
|
|
|
133
149
|
|
|
134
150
|
This method requires a complete iMIS data structure.
|
|
135
151
|
|
|
136
|
-
|
|
152
|
+
Alias: `create`
|
|
153
|
+
|
|
154
|
+
#### DELETE
|
|
137
155
|
|
|
138
156
|
To remove member data, run e.g.:
|
|
139
157
|
|
|
@@ -145,6 +163,8 @@ api.on('ABC_ASC_Individual_Demog').delete
|
|
|
145
163
|
|
|
146
164
|
This returns a blank string on success.
|
|
147
165
|
|
|
166
|
+
Alias: `destroy`
|
|
167
|
+
|
|
148
168
|
### QUERY
|
|
149
169
|
|
|
150
170
|
Run an IQA Query
|
|
@@ -187,7 +207,8 @@ vsc.api.imis_id = 6374
|
|
|
187
207
|
vsc.get(1417)
|
|
188
208
|
|
|
189
209
|
created = vsc.create(certificate: 'E136924', year: 2024, count: 42)
|
|
190
|
-
ordinal = created['Properties']['$values'][
|
|
210
|
+
ordinal = created['Properties']['$values'].find { it['Name'] == 'Ordinal' }['Value']['$value']
|
|
211
|
+
# ordinal = created['Identity']['IdentityElements']['$values'][1] # Alternative
|
|
191
212
|
|
|
192
213
|
vsc.update(certificate: 'E136924', year: 2024, count: 43, ordinal: ordinal)
|
|
193
214
|
|
|
@@ -237,7 +258,7 @@ api.with(31092) do
|
|
|
237
258
|
# These requests are identical:
|
|
238
259
|
|
|
239
260
|
on('ABC_ASC_Individual_Demog') do
|
|
240
|
-
get['Properties']['$values'].find {
|
|
261
|
+
get['Properties']['$values'].find { it['Name'] == 'TotMMS' }['Value']['$value']
|
|
241
262
|
end
|
|
242
263
|
|
|
243
264
|
on('ABC_ASC_Individual_Demog') { get_field('TotMMS') }
|
data/lib/usps/imis/api.rb
CHANGED
|
@@ -132,15 +132,6 @@ module Usps
|
|
|
132
132
|
results
|
|
133
133
|
end
|
|
134
134
|
|
|
135
|
-
# An instance of +BusinessObject+, using this instance as its parent +Api+
|
|
136
|
-
#
|
|
137
|
-
# @param business_object_name [String] Name of the business object
|
|
138
|
-
# @param ordinal [Integer] Ordinal to build override ID param of the URL (e.g. used for Panels)
|
|
139
|
-
#
|
|
140
|
-
def business_object(business_object_name, ordinal: nil)
|
|
141
|
-
BusinessObject.new(self, business_object_name, ordinal:)
|
|
142
|
-
end
|
|
143
|
-
|
|
144
135
|
# Run requests as DSL, with specific +BusinessObject+ only maintained for this scope
|
|
145
136
|
#
|
|
146
137
|
# If no block is given, this returns the specified +BusinessObject+.
|
|
@@ -149,7 +140,7 @@ module Usps
|
|
|
149
140
|
# @param ordinal [Integer] Ordinal to build override ID param of the URL (e.g. used for Panels)
|
|
150
141
|
#
|
|
151
142
|
def on(business_object_name, ordinal: nil, &)
|
|
152
|
-
object =
|
|
143
|
+
object = BusinessObject.new(self, business_object_name, ordinal:)
|
|
153
144
|
return object unless block_given?
|
|
154
145
|
|
|
155
146
|
object.instance_eval(&)
|
|
@@ -49,7 +49,7 @@ module Usps
|
|
|
49
49
|
#
|
|
50
50
|
def get_field(name)
|
|
51
51
|
values = get['Properties']['$values']
|
|
52
|
-
value = values.find {
|
|
52
|
+
value = values.find { it['Name'] == name }['Value']
|
|
53
53
|
|
|
54
54
|
value.is_a?(String) ? value : value['$value']
|
|
55
55
|
end
|
|
@@ -69,6 +69,8 @@ module Usps
|
|
|
69
69
|
|
|
70
70
|
# Update a business object for the current member
|
|
71
71
|
#
|
|
72
|
+
# Any properties not included will be left unmodified
|
|
73
|
+
#
|
|
72
74
|
# @param body [Hash] Full raw API object data
|
|
73
75
|
#
|
|
74
76
|
# @return [Hash] Response data from the API
|
|
@@ -133,22 +135,21 @@ module Usps
|
|
|
133
135
|
existing = get
|
|
134
136
|
|
|
135
137
|
JSON.parse(JSON.dump(existing)).tap do |updated|
|
|
136
|
-
#
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
#
|
|
140
|
-
updated['Properties']['$values'] = []
|
|
138
|
+
# Preserve the iMIS ID, as well as the Ordinal (if present)
|
|
139
|
+
updated['Properties']['$values'], properties =
|
|
140
|
+
existing['Properties']['$values'].partition { %w[ID Ordinal].include?(it['Name']) }
|
|
141
141
|
|
|
142
142
|
# Iterate through all existing fields
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
143
|
+
properties.each do |value|
|
|
144
|
+
# Skip unmodified fields
|
|
145
|
+
next unless fields.keys.include?(value['Name'])
|
|
146
|
+
|
|
147
|
+
# Strings are not wrapped in the type definition structure
|
|
148
|
+
new_value = fields[value['Name']]
|
|
149
|
+
if new_value.is_a?(String)
|
|
150
|
+
value['Value'] = new_value
|
|
151
|
+
else
|
|
152
|
+
value['Value']['$value'] = new_value
|
|
152
153
|
end
|
|
153
154
|
|
|
154
155
|
# Add the completed field with the updated value
|
data/lib/usps/imis/mapper.rb
CHANGED
data/lib/usps/imis/requests.rb
CHANGED
|
@@ -20,7 +20,7 @@ module Usps
|
|
|
20
20
|
#
|
|
21
21
|
def authorize(request)
|
|
22
22
|
authenticate if token_expiration < Time.now
|
|
23
|
-
request.tap {
|
|
23
|
+
request.tap { it.add_field('Authorization', "Bearer #{token}") }
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def submit(uri, request)
|
data/lib/usps/imis/version.rb
CHANGED
|
@@ -56,7 +56,7 @@ describe Usps::Imis::Api do
|
|
|
56
56
|
before { api.imis_id = 31092 }
|
|
57
57
|
|
|
58
58
|
it 'sends an update' do
|
|
59
|
-
expect(api.
|
|
59
|
+
expect(api.on('ABC_ASC_Individual_Demog').put_fields('TotMMS' => 15)).to(
|
|
60
60
|
be_a(Hash)
|
|
61
61
|
)
|
|
62
62
|
end
|
|
@@ -78,7 +78,7 @@ describe Usps::Imis::Api do
|
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
it 'wraps the error' do
|
|
81
|
-
expect { api.
|
|
81
|
+
expect { api.on('ABC_ASC_Individual_Demog').put_fields('TotMMS' => 15) }.to(
|
|
82
82
|
raise_error(Usps::Imis::Error::ApiError, warning_text)
|
|
83
83
|
)
|
|
84
84
|
end
|
|
@@ -88,7 +88,7 @@ describe Usps::Imis::Api do
|
|
|
88
88
|
describe '#with' do
|
|
89
89
|
it 'sends an update from put' do
|
|
90
90
|
expect(
|
|
91
|
-
api.with(31092) {
|
|
91
|
+
api.with(31092) { on('ABC_ASC_Individual_Demog').put_fields('TotMMS' => 15) }
|
|
92
92
|
).to be_a(Hash)
|
|
93
93
|
end
|
|
94
94
|
|
|
@@ -10,7 +10,7 @@ describe Usps::Imis::BusinessObject do
|
|
|
10
10
|
{
|
|
11
11
|
'Properties' => {
|
|
12
12
|
'$values' => [
|
|
13
|
-
{ 'Name' => '
|
|
13
|
+
{ 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
|
|
14
14
|
{ 'Name' => 'Stub Integer', 'Value' => { '$value' => 43 } },
|
|
15
15
|
{ 'Name' => 'Stub String', 'Value' => 'other' }
|
|
16
16
|
]
|
|
@@ -22,7 +22,7 @@ describe Usps::Imis::BusinessObject do
|
|
|
22
22
|
allow(business_object).to receive(:get).and_return({
|
|
23
23
|
'Properties' => {
|
|
24
24
|
'$values' => [
|
|
25
|
-
{ 'Name' => '
|
|
25
|
+
{ 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
|
|
26
26
|
{ 'Name' => 'Stub Integer', 'Value' => { '$value' => 42 } },
|
|
27
27
|
{ 'Name' => 'Stub String', 'Value' => 'something' }
|
|
28
28
|
]
|
|
@@ -29,7 +29,7 @@ describe Usps::Imis::Panel::Vsc do
|
|
|
29
29
|
ordinal = new_record['Identity']['IdentityElements']['$values'][1]
|
|
30
30
|
|
|
31
31
|
update_result = vsc.update(details.merge(count: 43, ordinal:))
|
|
32
|
-
updated = update_result['Properties']['$values'].find {
|
|
32
|
+
updated = update_result['Properties']['$values'].find { it['Name'] == 'Quantity' }
|
|
33
33
|
expect(updated['Value']['$value']).to eq(43)
|
|
34
34
|
|
|
35
35
|
expect(vsc.destroy(ordinal)).to eq('')
|