usps-imis-api 0.6.11 → 0.6.13
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/lib/usps/imis/api.rb +26 -9
- data/lib/usps/imis/business_object.rb +16 -8
- data/lib/usps/imis/panel/base_panel.rb +4 -6
- data/lib/usps/imis/version.rb +1 -1
- data/spec/lib/usps/imis/api_spec.rb +15 -0
- 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: ce718cab17b65f021cb739faa943d2437f2f4e83f051ad50c37a9ae0cfe48131
|
|
4
|
+
data.tar.gz: 34cece880ed383d43536f915b1c9480fe557587a61d69c9ed32c061932bbfd3a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a05b5e0bc67ac874b306e688decd19d61c28d4a734165817395f2194a5ac2e166c5e75bcfc900488036f83941c81b4fd0c840810a261813d8b2ae343d5597608
|
|
7
|
+
data.tar.gz: aa402f52a26d2eb0d44928d9461707bc671d6ebf4f3e85325407762d2529b09668b02c2970f58528ad125d1e36c87718439817307f676b0858d764ac358cc7df
|
data/Gemfile.lock
CHANGED
data/lib/usps/imis/api.rb
CHANGED
|
@@ -113,13 +113,32 @@ module Usps
|
|
|
113
113
|
JSON.parse(result.body)
|
|
114
114
|
end
|
|
115
115
|
|
|
116
|
+
# Run an IQA Query, paging through all responses
|
|
117
|
+
#
|
|
118
|
+
# @param query_name [String] Full path of the query in IQA, e.g. +$/_ABC/Fiander/iMIS_ID+
|
|
119
|
+
# @query_params [Hash] Conforms to pattern +{ param_name => param_value }+
|
|
120
|
+
#
|
|
121
|
+
# @return [Array<Hash>] Collected response item values from the API
|
|
122
|
+
#
|
|
123
|
+
def query_all(query_name, query_params = {})
|
|
124
|
+
response = query(query_name, **query_params)
|
|
125
|
+
results = response['Items']['$values']
|
|
126
|
+
|
|
127
|
+
while response['HasNext']
|
|
128
|
+
response = query(query_name, **query_params, Offset: response['NextOffset'])
|
|
129
|
+
results += response['Items']['$values']
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
results
|
|
133
|
+
end
|
|
134
|
+
|
|
116
135
|
# An instance of +BusinessObject+, using this instance as its parent +Api+
|
|
117
136
|
#
|
|
118
137
|
# @param business_object_name [String] Name of the business object
|
|
119
|
-
# @param
|
|
138
|
+
# @param ordinal [Integer] Ordinal to build override ID param of the URL (e.g. used for Panels)
|
|
120
139
|
#
|
|
121
|
-
def business_object(business_object_name,
|
|
122
|
-
BusinessObject.new(self, business_object_name,
|
|
140
|
+
def business_object(business_object_name, ordinal: nil)
|
|
141
|
+
BusinessObject.new(self, business_object_name, ordinal:)
|
|
123
142
|
end
|
|
124
143
|
|
|
125
144
|
# Run requests as DSL, with specific +BusinessObject+ only maintained for this scope
|
|
@@ -127,15 +146,13 @@ module Usps
|
|
|
127
146
|
# If no block is given, this returns the specified +BusinessObject+.
|
|
128
147
|
#
|
|
129
148
|
# @param business_object_name [String] Name of the business object
|
|
130
|
-
# @param
|
|
149
|
+
# @param ordinal [Integer] Ordinal to build override ID param of the URL (e.g. used for Panels)
|
|
131
150
|
#
|
|
132
|
-
def on(business_object_name,
|
|
133
|
-
object = business_object(business_object_name,
|
|
151
|
+
def on(business_object_name, ordinal: nil, &)
|
|
152
|
+
object = business_object(business_object_name, ordinal:)
|
|
134
153
|
return object unless block_given?
|
|
135
154
|
|
|
136
|
-
|
|
137
|
-
object.tap { |obj| result = obj.instance_eval(&) }
|
|
138
|
-
result
|
|
155
|
+
object.instance_eval(&)
|
|
139
156
|
end
|
|
140
157
|
|
|
141
158
|
# An instance of +Mapper+, using this instance as its parent +Api+
|
|
@@ -18,16 +18,16 @@ module Usps
|
|
|
18
18
|
#
|
|
19
19
|
attr_reader :business_object_name
|
|
20
20
|
|
|
21
|
-
#
|
|
21
|
+
# Ordinal to build override ID param of the URL (e.g. used for Panels)
|
|
22
22
|
#
|
|
23
|
-
attr_reader :
|
|
23
|
+
attr_reader :ordinal
|
|
24
24
|
|
|
25
25
|
# A new instance of +BusinessObject+
|
|
26
26
|
#
|
|
27
|
-
def initialize(api, business_object_name,
|
|
27
|
+
def initialize(api, business_object_name, ordinal: nil)
|
|
28
28
|
@api = api
|
|
29
29
|
@business_object_name = business_object_name
|
|
30
|
-
@
|
|
30
|
+
@ordinal = ordinal
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
# Get a business object for the current member
|
|
@@ -84,7 +84,7 @@ module Usps
|
|
|
84
84
|
# @return [Hash] Response data from the API
|
|
85
85
|
#
|
|
86
86
|
def post(body)
|
|
87
|
-
request = Net::HTTP::Post.new(uri)
|
|
87
|
+
request = Net::HTTP::Post.new(uri(id: ''))
|
|
88
88
|
request.body = JSON.dump(body)
|
|
89
89
|
result = submit(uri, authorize(request))
|
|
90
90
|
JSON.parse(result.body)
|
|
@@ -107,12 +107,20 @@ module Usps
|
|
|
107
107
|
|
|
108
108
|
# Construct a business object API endpoint address
|
|
109
109
|
#
|
|
110
|
-
def uri
|
|
111
|
-
|
|
112
|
-
full_path = "#{API_PATH}/#{business_object_name}/#{id_for_url}"
|
|
110
|
+
def uri(id: nil)
|
|
111
|
+
full_path = "#{API_PATH}/#{business_object_name}/#{id_for_uri(id)}"
|
|
113
112
|
URI(File.join(Imis.configuration.hostname, full_path))
|
|
114
113
|
end
|
|
115
114
|
|
|
115
|
+
# Select the correct ID to use in the URI
|
|
116
|
+
#
|
|
117
|
+
def id_for_uri(id = nil)
|
|
118
|
+
return CGI.escape(id) unless id.nil?
|
|
119
|
+
return CGI.escape("~#{api.imis_id}|#{ordinal}") if ordinal
|
|
120
|
+
|
|
121
|
+
api.imis_id
|
|
122
|
+
end
|
|
123
|
+
|
|
116
124
|
# Manually assemble the matching data structure, with fields in the correct order
|
|
117
125
|
#
|
|
118
126
|
def filter_fields(fields)
|
|
@@ -20,7 +20,7 @@ module Usps
|
|
|
20
20
|
# @param ordinal [Integer] The ordinal identifier for the desired object
|
|
21
21
|
#
|
|
22
22
|
def get(ordinal)
|
|
23
|
-
api.
|
|
23
|
+
api.on(business_object, ordinal:).get
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
# Create a new object in the Panel
|
|
@@ -28,7 +28,7 @@ module Usps
|
|
|
28
28
|
# @param data [Hash] The record data for the desired object
|
|
29
29
|
#
|
|
30
30
|
def create(data)
|
|
31
|
-
api.
|
|
31
|
+
api.on(business_object).post(payload(data))
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
# Update an existing object in the Panel
|
|
@@ -37,9 +37,7 @@ module Usps
|
|
|
37
37
|
# +ordinal+ identifier
|
|
38
38
|
#
|
|
39
39
|
def update(data)
|
|
40
|
-
api
|
|
41
|
-
.business_object(business_object, url_id: "~#{api.imis_id}|#{data[:ordinal]}")
|
|
42
|
-
.put(payload(data))
|
|
40
|
+
api.on(business_object, ordinal: data[:ordinal]).put(payload(data))
|
|
43
41
|
end
|
|
44
42
|
|
|
45
43
|
# Remove a specific object from the Panel
|
|
@@ -47,7 +45,7 @@ module Usps
|
|
|
47
45
|
# @param ordinal [Integer] The ordinal identifier for the desired object
|
|
48
46
|
#
|
|
49
47
|
def destroy(ordinal)
|
|
50
|
-
api.
|
|
48
|
+
api.on(business_object, ordinal:).delete
|
|
51
49
|
end
|
|
52
50
|
|
|
53
51
|
private
|
data/lib/usps/imis/version.rb
CHANGED
|
@@ -37,6 +37,21 @@ describe Usps::Imis::Api do
|
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
+
describe '#query_all' do
|
|
41
|
+
before do
|
|
42
|
+
allow(api).to receive(:query).and_return(
|
|
43
|
+
{ 'Items' => { '$values' => [{ 'key1' => 'value1' }] }, 'HasNext' => true, 'NextOffset' => 1 },
|
|
44
|
+
{ 'Items' => { '$values' => [{ 'key1' => 'value2' }] }, 'HasNext' => false, 'NextOffset' => 0 }
|
|
45
|
+
)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'collects all query results' do
|
|
49
|
+
expect(api.query_all('$/ABC/ExampleQueryAll')).to eq(
|
|
50
|
+
[{ 'key1' => 'value1' }, { 'key1' => 'value2' }]
|
|
51
|
+
)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
40
55
|
describe '#put' do
|
|
41
56
|
before { api.imis_id = 31092 }
|
|
42
57
|
|