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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd7f53417285bbe15766b1e79e88448807a1e481f13cb20a16d1bfb791a96f15
4
- data.tar.gz: fb6c040f10270293db091bd20c25de73679de83fd24bf1253cbd50f82e53c1e3
3
+ metadata.gz: ce718cab17b65f021cb739faa943d2437f2f4e83f051ad50c37a9ae0cfe48131
4
+ data.tar.gz: 34cece880ed383d43536f915b1c9480fe557587a61d69c9ed32c061932bbfd3a
5
5
  SHA512:
6
- metadata.gz: e65d398030e74648c5c0ceadcc1ab9bd3b94e481d5c20c14761d30e3efa4dcb6a3293e1b4d2d5de2f3678acd8cac80f0051074cff86c99386023e097ce3e2b4e
7
- data.tar.gz: f436a6c796ffef704e7fd73ceb59e9352b77bb1a35efa0cbf96909e47a3ee7c24fbf4288cbe413941da49e6bf69c8b88aa2a952c0426523ec4ff9b5ae8f2c3df
6
+ metadata.gz: a05b5e0bc67ac874b306e688decd19d61c28d4a734165817395f2194a5ac2e166c5e75bcfc900488036f83941c81b4fd0c840810a261813d8b2ae343d5597608
7
+ data.tar.gz: aa402f52a26d2eb0d44928d9461707bc671d6ebf4f3e85325407762d2529b09668b02c2970f58528ad125d1e36c87718439817307f676b0858d764ac358cc7df
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps-imis-api (0.6.11)
4
+ usps-imis-api (0.6.13)
5
5
  activesupport (~> 8.0)
6
6
 
7
7
  GEM
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 url_id [String] Override the ID param of the URL (e.g. used for Panels)
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, url_id: nil)
122
- BusinessObject.new(self, business_object_name, url_id:)
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 url_id [String] Override the ID param of the URL (e.g. used for Panels)
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, url_id: nil, &)
133
- object = business_object(business_object_name, url_id:)
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
- result = nil
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
- # Override ID param of the URL (e.g. used for Panels)
21
+ # Ordinal to build override ID param of the URL (e.g. used for Panels)
22
22
  #
23
- attr_reader :url_id
23
+ attr_reader :ordinal
24
24
 
25
25
  # A new instance of +BusinessObject+
26
26
  #
27
- def initialize(api, business_object_name, url_id: nil)
27
+ def initialize(api, business_object_name, ordinal: nil)
28
28
  @api = api
29
29
  @business_object_name = business_object_name
30
- @url_id = url_id
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
- id_for_url = url_id ? CGI.escape(url_id) : api.imis_id
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.business_object(business_object, url_id: "~#{api.imis_id}|#{ordinal}").get
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.business_object(business_object, url_id: '').post(payload(data))
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.business_object(business_object, url_id: "~#{api.imis_id}|#{ordinal}").delete
48
+ api.on(business_object, ordinal:).delete
51
49
  end
52
50
 
53
51
  private
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Imis
5
- VERSION = '0.6.11'
5
+ VERSION = '0.6.13'
6
6
  end
7
7
  end
@@ -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
 
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.6.11
4
+ version: 0.6.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander