usps-imis-api 0.7.0 → 0.7.1
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 +20 -0
- data/lib/usps/imis/business_object.rb +53 -34
- data/lib/usps/imis/panels/base_panel.rb +23 -19
- data/lib/usps/imis/version.rb +1 -1
- data/spec/lib/usps/imis/business_object_spec.rb +35 -13
- data/spec/lib/usps/imis/panels/education_spec.rb +11 -1
- data/spec/lib/usps/imis/panels/vsc_spec.rb +1 -1
- data/usps-imis-api.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ca358fc80eed74b0335f6137f71e503fffbc84d6c396c8e1c23c90501eab5b36
|
|
4
|
+
data.tar.gz: 239111a5dfd7cb186fe358fc0227e3063744225cf619e12a91e994f639142e56
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2f31860395762aeead9f002f96867111758a8474ada928ba1369e3122b767f0b27052ed41157d8eac008fade27bdb779389cd65c74ad7cadbb87129ee9c238ff
|
|
7
|
+
data.tar.gz: 7c0f5eaae8592a93192e08ca4cf88e604629de246b8e2f9272880d19e39a218d01a027387720a6c289b7f4490bc6617b57c637ab00201868ecd36fd178748031
|
data/Gemfile.lock
CHANGED
data/Readme.md
CHANGED
|
@@ -77,6 +77,10 @@ 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
|
+
#### Without an iMIS ID
|
|
81
|
+
|
|
82
|
+
Running requests without an iMIS ID set will result in query results returned from the API.
|
|
83
|
+
|
|
80
84
|
### Business Object and Panel Actions
|
|
81
85
|
|
|
82
86
|
Business Objects and Panels support the following actions.
|
|
@@ -91,6 +95,12 @@ To fetch member data, run e.g.:
|
|
|
91
95
|
data = api.on('ABC_ASC_Individual_Demog').get
|
|
92
96
|
```
|
|
93
97
|
|
|
98
|
+
You can also pass in specific field names to filter the returned member data, e.g.:
|
|
99
|
+
|
|
100
|
+
```ruby
|
|
101
|
+
data = api.on('ABC_ASC_Individual_Demog').get('TotMMS', 'MMS_Updated')
|
|
102
|
+
```
|
|
103
|
+
|
|
94
104
|
Alias: `read`
|
|
95
105
|
|
|
96
106
|
#### GET Field
|
|
@@ -103,6 +113,16 @@ tot_mms = api.on('ABC_ASC_Individual_Demog').get_field('TotMMS')
|
|
|
103
113
|
|
|
104
114
|
Alias: `fetch`
|
|
105
115
|
|
|
116
|
+
#### GET Fields
|
|
117
|
+
|
|
118
|
+
To fetch multiple specific fields from member data, run e.g.:
|
|
119
|
+
|
|
120
|
+
```ruby
|
|
121
|
+
data = api.on('ABC_ASC_Individual_Demog').get_fields('TotMMS', 'MMS_Updated')
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Alias: `fetch_all`
|
|
125
|
+
|
|
106
126
|
#### PUT Fields
|
|
107
127
|
|
|
108
128
|
To update member data, run e.g.:
|
|
@@ -34,28 +34,35 @@ module Usps
|
|
|
34
34
|
|
|
35
35
|
# Get a business object for the current member
|
|
36
36
|
#
|
|
37
|
-
#
|
|
37
|
+
# If +fields+ is provided, will return only those field values
|
|
38
38
|
#
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
# @param fields [String] Field names to return
|
|
40
|
+
#
|
|
41
|
+
# @return [Hash, Array<Hash>] Response data from the API
|
|
42
|
+
#
|
|
43
|
+
def get(*fields) = fields.any? ? get_fields(*fields) : raw_object
|
|
44
44
|
alias read get
|
|
45
45
|
|
|
46
46
|
# Get a single named field from a business object for the current member
|
|
47
47
|
#
|
|
48
|
-
# @param
|
|
48
|
+
# @param field [String] Field name to return
|
|
49
49
|
#
|
|
50
50
|
# @return [Hash] Response data from the API
|
|
51
51
|
#
|
|
52
|
-
def get_field(
|
|
53
|
-
|
|
54
|
-
value = values.find { it['Name'] == name }['Value']
|
|
52
|
+
def get_field(field) = extract_field_value(raw_object_values, field)
|
|
53
|
+
alias fetch get_field
|
|
55
54
|
|
|
56
|
-
|
|
55
|
+
# Get named fields from a business object for the current member
|
|
56
|
+
#
|
|
57
|
+
# @param names [Array<String>] Field names to return
|
|
58
|
+
#
|
|
59
|
+
# @return [Array<Hash>] Response data from the API
|
|
60
|
+
#
|
|
61
|
+
def get_fields(*fields)
|
|
62
|
+
values = raw_object_values
|
|
63
|
+
fields.map { extract_field_value(values, it) }
|
|
57
64
|
end
|
|
58
|
-
alias
|
|
65
|
+
alias fetch_all get_fields
|
|
59
66
|
|
|
60
67
|
# Update only specific fields on a business object for the current member
|
|
61
68
|
#
|
|
@@ -63,10 +70,7 @@ module Usps
|
|
|
63
70
|
#
|
|
64
71
|
# @return [Hash] Response data from the API
|
|
65
72
|
#
|
|
66
|
-
def put_fields(fields)
|
|
67
|
-
updated = filter_fields(fields)
|
|
68
|
-
put(updated)
|
|
69
|
-
end
|
|
73
|
+
def put_fields(fields) = put(filter_fields(fields))
|
|
70
74
|
alias patch put_fields
|
|
71
75
|
|
|
72
76
|
# Update a business object for the current member
|
|
@@ -77,12 +81,7 @@ module Usps
|
|
|
77
81
|
#
|
|
78
82
|
# @return [Hash] Response data from the API
|
|
79
83
|
#
|
|
80
|
-
def put(body)
|
|
81
|
-
request = Net::HTTP::Put.new(uri)
|
|
82
|
-
request.body = JSON.dump(body)
|
|
83
|
-
result = submit(uri, authorize(request))
|
|
84
|
-
JSON.parse(result.body)
|
|
85
|
-
end
|
|
84
|
+
def put(body) = put_object(Net::HTTP::Put.new(uri), body)
|
|
86
85
|
alias update put
|
|
87
86
|
|
|
88
87
|
# Create a business object for the current member
|
|
@@ -91,23 +90,14 @@ module Usps
|
|
|
91
90
|
#
|
|
92
91
|
# @return [Hash] Response data from the API
|
|
93
92
|
#
|
|
94
|
-
def post(body)
|
|
95
|
-
request = Net::HTTP::Post.new(uri(id: ''))
|
|
96
|
-
request.body = JSON.dump(body)
|
|
97
|
-
result = submit(uri, authorize(request))
|
|
98
|
-
JSON.parse(result.body)
|
|
99
|
-
end
|
|
93
|
+
def post(body) = put_object(Net::HTTP::Post.new(uri(id: '')), body)
|
|
100
94
|
alias create post
|
|
101
95
|
|
|
102
96
|
# Remove a business object for the current member
|
|
103
97
|
#
|
|
104
|
-
# @return [
|
|
98
|
+
# @return [true] Only on success response (i.e. blank string from the API)
|
|
105
99
|
#
|
|
106
|
-
def delete
|
|
107
|
-
request = Net::HTTP::Delete.new(uri)
|
|
108
|
-
result = submit(uri, authorize(request))
|
|
109
|
-
result.body
|
|
110
|
-
end
|
|
100
|
+
def delete = submit(uri, authorize(Net::HTTP::Delete.new(uri))).body == '' # rubocop:disable Naming/PredicateMethod
|
|
111
101
|
alias destroy delete
|
|
112
102
|
|
|
113
103
|
private
|
|
@@ -159,6 +149,35 @@ module Usps
|
|
|
159
149
|
end
|
|
160
150
|
end
|
|
161
151
|
end
|
|
152
|
+
|
|
153
|
+
# Get a raw object response from the API
|
|
154
|
+
#
|
|
155
|
+
# Useful for stubbing data in tests
|
|
156
|
+
#
|
|
157
|
+
def raw_object
|
|
158
|
+
request = Net::HTTP::Get.new(uri)
|
|
159
|
+
result = submit(uri, authorize(request))
|
|
160
|
+
JSON.parse(result.body)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# Get just the property values from an object response from the API
|
|
164
|
+
#
|
|
165
|
+
def raw_object_values
|
|
166
|
+
raw_object['Properties']['$values']
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def extract_field_value(values, field)
|
|
170
|
+
value = values.find { it['Name'] == field }['Value']
|
|
171
|
+
value.is_a?(String) ? value : value['$value']
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
# Upload an object to the API
|
|
175
|
+
#
|
|
176
|
+
def put_object(request, body)
|
|
177
|
+
request.body = JSON.dump(body)
|
|
178
|
+
result = submit(uri, authorize(request))
|
|
179
|
+
JSON.parse(result.body)
|
|
180
|
+
end
|
|
162
181
|
end
|
|
163
182
|
end
|
|
164
183
|
end
|
|
@@ -17,25 +17,37 @@ module Usps
|
|
|
17
17
|
|
|
18
18
|
# Get a specific object from the Panel
|
|
19
19
|
#
|
|
20
|
+
# If +fields+ is provided, will return only those field values
|
|
21
|
+
#
|
|
22
|
+
# @param fields [String] Field names to return
|
|
23
|
+
#
|
|
20
24
|
# @param ordinal [Integer] The ordinal identifier for the desired object
|
|
21
25
|
#
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
# @return [Hash, Array<Hash>] Response data from the API
|
|
27
|
+
#
|
|
28
|
+
def get(ordinal, *fields) = api.on(business_object, ordinal:).get(*fields)
|
|
25
29
|
alias read get
|
|
26
30
|
|
|
27
31
|
# Get a single named field from a Panel for the current member
|
|
28
32
|
#
|
|
29
33
|
# @param ordinal [Integer] The ordinal identifier for the desired object
|
|
30
|
-
# @param
|
|
34
|
+
# @param field [String] Field name to return
|
|
31
35
|
#
|
|
32
36
|
# @return [Hash] Response data from the API
|
|
33
37
|
#
|
|
34
|
-
def get_field(ordinal,
|
|
35
|
-
api.on(business_object, ordinal:).get_field(name)
|
|
36
|
-
end
|
|
38
|
+
def get_field(ordinal, field) = api.on(business_object, ordinal:).get_field(field)
|
|
37
39
|
alias fetch get_field
|
|
38
40
|
|
|
41
|
+
# Get named fields from a Panel for the current member
|
|
42
|
+
#
|
|
43
|
+
# @param ordinal [Integer] The ordinal identifier for the desired object
|
|
44
|
+
# @param fields [Array<String>] Field names to return
|
|
45
|
+
#
|
|
46
|
+
# @return [Hash] Response data from the API
|
|
47
|
+
#
|
|
48
|
+
def get_fields(ordinal, *fields) = api.on(business_object, ordinal:).get_fields(*fields)
|
|
49
|
+
alias fetch_all get_fields
|
|
50
|
+
|
|
39
51
|
# Update only specific fields on a Panel for the current member
|
|
40
52
|
#
|
|
41
53
|
# @param ordinal [Integer] The ordinal identifier for the desired object
|
|
@@ -43,9 +55,7 @@ module Usps
|
|
|
43
55
|
#
|
|
44
56
|
# @return [Hash] Response data from the API
|
|
45
57
|
#
|
|
46
|
-
def put_fields(ordinal, fields)
|
|
47
|
-
api.on(business_object, ordinal:).put_fields(fields)
|
|
48
|
-
end
|
|
58
|
+
def put_fields(ordinal, fields) = api.on(business_object, ordinal:).put_fields(fields)
|
|
49
59
|
alias patch put_fields
|
|
50
60
|
|
|
51
61
|
# Update an existing object in the Panel
|
|
@@ -53,27 +63,21 @@ module Usps
|
|
|
53
63
|
# @param data [Hash] The record data for the desired object -- including the required
|
|
54
64
|
# +ordinal+ identifier
|
|
55
65
|
#
|
|
56
|
-
def put(data)
|
|
57
|
-
api.on(business_object, ordinal: data[:ordinal]).put(payload(data))
|
|
58
|
-
end
|
|
66
|
+
def put(data) = api.on(business_object, ordinal: data[:ordinal]).put(payload(data))
|
|
59
67
|
alias update put
|
|
60
68
|
|
|
61
69
|
# Create a new object in the Panel
|
|
62
70
|
#
|
|
63
71
|
# @param data [Hash] The record data for the desired object
|
|
64
72
|
#
|
|
65
|
-
def post(data)
|
|
66
|
-
api.on(business_object).post(payload(data))
|
|
67
|
-
end
|
|
73
|
+
def post(data) = api.on(business_object).post(payload(data))
|
|
68
74
|
alias create post
|
|
69
75
|
|
|
70
76
|
# Remove a specific object from the Panel
|
|
71
77
|
#
|
|
72
78
|
# @param ordinal [Integer] The ordinal identifier for the desired object
|
|
73
79
|
#
|
|
74
|
-
def delete(ordinal)
|
|
75
|
-
api.on(business_object, ordinal:).delete
|
|
76
|
-
end
|
|
80
|
+
def delete(ordinal) = api.on(business_object, ordinal:).delete
|
|
77
81
|
alias destroy delete
|
|
78
82
|
|
|
79
83
|
private
|
data/lib/usps/imis/version.rb
CHANGED
|
@@ -6,20 +6,8 @@ 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
|
-
let(:expected) do
|
|
10
|
-
{
|
|
11
|
-
'Properties' => {
|
|
12
|
-
'$values' => [
|
|
13
|
-
{ 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
|
|
14
|
-
{ 'Name' => 'Stub Integer', 'Value' => { '$value' => 43 } },
|
|
15
|
-
{ 'Name' => 'Stub String', 'Value' => 'other' }
|
|
16
|
-
]
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
end
|
|
20
|
-
|
|
21
9
|
before do
|
|
22
|
-
allow(business_object).to receive(:
|
|
10
|
+
allow(business_object).to receive(:raw_object).and_return({
|
|
23
11
|
'Properties' => {
|
|
24
12
|
'$values' => [
|
|
25
13
|
{ 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
|
|
@@ -30,6 +18,22 @@ describe Usps::Imis::BusinessObject do
|
|
|
30
18
|
})
|
|
31
19
|
end
|
|
32
20
|
|
|
21
|
+
describe '#get' do
|
|
22
|
+
it 'returns multiple values' do
|
|
23
|
+
expect(business_object.get('Stub String', 'Stub Integer')).to eq(['something', 42])
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe 'delegation to get_fields' do
|
|
27
|
+
before { allow(business_object).to receive(:get_fields).with('Stub String', 'Stub Integer') }
|
|
28
|
+
|
|
29
|
+
it 'delegates to get_fields' do
|
|
30
|
+
business_object.get('Stub String', 'Stub Integer')
|
|
31
|
+
|
|
32
|
+
expect(business_object).to have_received(:get_fields).with('Stub String', 'Stub Integer')
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
33
37
|
describe '#get_field' do
|
|
34
38
|
it 'returns a string value' do
|
|
35
39
|
expect(business_object.get_field('Stub String')).to eq('something')
|
|
@@ -40,7 +44,25 @@ describe Usps::Imis::BusinessObject do
|
|
|
40
44
|
end
|
|
41
45
|
end
|
|
42
46
|
|
|
47
|
+
describe '#get_fields' do
|
|
48
|
+
it 'returns multiple values' do
|
|
49
|
+
expect(business_object.get_fields('Stub String', 'Stub Integer')).to eq(['something', 42])
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
43
53
|
describe '#filter_fields' do
|
|
54
|
+
let(:expected) do
|
|
55
|
+
{
|
|
56
|
+
'Properties' => {
|
|
57
|
+
'$values' => [
|
|
58
|
+
{ 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
|
|
59
|
+
{ 'Name' => 'Stub Integer', 'Value' => { '$value' => 43 } },
|
|
60
|
+
{ 'Name' => 'Stub String', 'Value' => 'other' }
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
end
|
|
65
|
+
|
|
44
66
|
it 'formats fields correctly' do
|
|
45
67
|
updated = business_object.send(:filter_fields, 'Stub Integer' => 43, 'Stub String' => 'other')
|
|
46
68
|
|
|
@@ -23,6 +23,10 @@ describe Usps::Imis::Panels::Education do
|
|
|
23
23
|
it 'loads a specific object' do
|
|
24
24
|
expect(education.get(90737)).to be_a(Hash)
|
|
25
25
|
end
|
|
26
|
+
|
|
27
|
+
it 'returns specific fields' do
|
|
28
|
+
expect(education.get(90737, 'ABC_Product_Code', 'ABC_Other_Code')).to eq(%w[CRS AP])
|
|
29
|
+
end
|
|
26
30
|
end
|
|
27
31
|
|
|
28
32
|
describe '#get_field' do
|
|
@@ -31,6 +35,12 @@ describe Usps::Imis::Panels::Education do
|
|
|
31
35
|
end
|
|
32
36
|
end
|
|
33
37
|
|
|
38
|
+
describe '#get_fields' do
|
|
39
|
+
it 'returns specific fields' do
|
|
40
|
+
expect(education.get_fields(90737, 'ABC_Product_Code', 'ABC_Other_Code')).to eq(%w[CRS AP])
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
34
44
|
# rubocop:disable RSpec/ExampleLength
|
|
35
45
|
it 'interacts with records correctly', :aggregate_failures do
|
|
36
46
|
new_record = education.create(details)
|
|
@@ -51,7 +61,7 @@ describe Usps::Imis::Panels::Education do
|
|
|
51
61
|
end
|
|
52
62
|
expect(patched['Value']).to eq('Online Exams System - Mod2')
|
|
53
63
|
|
|
54
|
-
expect(education.destroy(ordinal)).to
|
|
64
|
+
expect(education.destroy(ordinal)).to be(true)
|
|
55
65
|
end
|
|
56
66
|
# rubocop:enable RSpec/ExampleLength
|
|
57
67
|
end
|
|
@@ -32,7 +32,7 @@ describe Usps::Imis::Panels::Vsc do
|
|
|
32
32
|
updated = update_result['Properties']['$values'].find { it['Name'] == 'Quantity' }
|
|
33
33
|
expect(updated['Value']['$value']).to eq(43)
|
|
34
34
|
|
|
35
|
-
expect(vsc.destroy(ordinal)).to
|
|
35
|
+
expect(vsc.destroy(ordinal)).to be(true)
|
|
36
36
|
end
|
|
37
37
|
# rubocop:enable RSpec/ExampleLength
|
|
38
38
|
end
|
data/usps-imis-api.gemspec
CHANGED
|
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
|
7
7
|
s.version = Usps::Imis::VERSION
|
|
8
8
|
s.summary = 'iMIS API Wrapper'
|
|
9
9
|
s.description = 'A wrapper for the iMIS API.'
|
|
10
|
-
s.homepage = '
|
|
10
|
+
s.homepage = 'https://github.com/unitedstatespowersquadrons/imis-api-ruby'
|
|
11
11
|
s.authors = ['Julian Fiander']
|
|
12
12
|
s.email = 'jsfiander@gmail.com'
|
|
13
13
|
s.require_paths = %w[lib]
|
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.7.
|
|
4
|
+
version: 0.7.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Julian Fiander
|
|
@@ -78,7 +78,7 @@ files:
|
|
|
78
78
|
- spec/lib/usps/imis_spec.rb
|
|
79
79
|
- spec/spec_helper.rb
|
|
80
80
|
- usps-imis-api.gemspec
|
|
81
|
-
homepage:
|
|
81
|
+
homepage: https://github.com/unitedstatespowersquadrons/imis-api-ruby
|
|
82
82
|
licenses: []
|
|
83
83
|
metadata:
|
|
84
84
|
rubygems_mfa_required: 'true'
|