usps-imis-api 0.6.10 → 0.6.12

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: 5103e3c7de24d79be7d86bfd21883d572d5cc88f6c58509973ab2bcce3d99202
4
- data.tar.gz: 1e96b2dbf536e4205f2fb721ddba91cd2640af1893c30db3d911fea6824b6ea9
3
+ metadata.gz: 03dbc937f5336d48ede502436a3ddcee7d77f8f357d18d807ac4119b52acf7e8
4
+ data.tar.gz: 9052ead6d9fb967e5faadb730d7000f32d0e97e83545e60fdef7e9a0b3deda18
5
5
  SHA512:
6
- metadata.gz: 53fa63489cda9a6dd09401605daf22329cad3a6f2f3313b068eb3ecd339d9ceff518134305601a2591451acdd03723f566096cb2bcc754c90da03d79d32de315
7
- data.tar.gz: df0052735b664cc91e4d4b923b1c7ecffe065acc44d320624cc84e834607f557df7c3c39b04cc95410642de07df665da56700c9d543be3cb0f15e1644bf12f15
6
+ metadata.gz: 33d7ced678ecc240e405b73fe5ba6c006fedece86612f76018296166c53e8226996b27617fb1a7212f885c4a5107c9c03186ad922106ccc79714e6a522127fd9
7
+ data.tar.gz: 78b04d51fde868adf81b86231083bdafdb6f08a7f6e7664ba3406b65557be09bb875cc9f1c37846a353872f784cdc872506b27415150ad1b5f79363b5baf29aa
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps-imis-api (0.6.10)
4
+ usps-imis-api (0.6.12)
5
5
  activesupport (~> 8.0)
6
6
 
7
7
  GEM
data/lib/usps/imis/api.rb CHANGED
@@ -113,6 +113,25 @@ 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
@@ -4,7 +4,7 @@ module Usps
4
4
  module Imis
5
5
  # Mock data response for testing
6
6
  #
7
- class Mock
7
+ class BusinessObjectMock
8
8
  attr_reader :fields
9
9
 
10
10
  def initialize(**fields)
@@ -18,6 +18,18 @@ module Usps
18
18
  fields.each { |name, value| props.add(name, value) }
19
19
  end
20
20
  end
21
+
22
+ def put_fields(data)
23
+ Usps::Imis::Properties.build do |props|
24
+ fields.merge(data.transform_keys(&:to_s)).each { |name, value| props.add(name, value) }
25
+ end
26
+ end
27
+
28
+ def put(data) = data
29
+
30
+ def post(data) = data
31
+
32
+ def delete = ''
21
33
  end
22
34
  end
23
35
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Imis
5
- VERSION = '0.6.10'
5
+ VERSION = '0.6.12'
6
6
  end
7
7
  end
data/lib/usps/imis.rb CHANGED
@@ -23,7 +23,7 @@ require_relative 'imis/business_object'
23
23
  require_relative 'imis/api'
24
24
  require_relative 'imis/mapper'
25
25
  require_relative 'imis/properties'
26
- require_relative 'imis/mock'
26
+ require_relative 'imis/business_object_mock'
27
27
  require_relative 'imis/panel/base_panel'
28
28
  require_relative 'imis/panel/vsc'
29
29
  require_relative 'imis/panel/education'
@@ -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
 
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Usps::Imis::BusinessObjectMock do
6
+ let(:mock) { described_class.new(**fields) }
7
+ let(:fields) { { TotMMS: 2 } }
8
+
9
+ let(:data) do
10
+ Usps::Imis::Properties.build do |props|
11
+ props.add 'TotMMS', 2
12
+ end
13
+ end
14
+
15
+ describe 'get' do
16
+ it 'returns the correct data' do
17
+ expect(mock.get).to eq(data)
18
+ end
19
+ end
20
+
21
+ describe 'get_field' do
22
+ it 'returns the correct field value' do
23
+ expect(mock.get_field('TotMMS')).to eq(2)
24
+ end
25
+ end
26
+
27
+ describe 'put_fields' do
28
+ let(:combined_data) do
29
+ Usps::Imis::Properties.build do |props|
30
+ props.add 'TotMMS', 2
31
+ props.add 'SomethingElse', 'interesting'
32
+ end
33
+ end
34
+
35
+ it 'returns the correct data' do
36
+ expect(mock.put_fields(SomethingElse: 'interesting')).to eq(combined_data)
37
+ end
38
+ end
39
+
40
+ describe 'put' do
41
+ it 'returns the correct data' do
42
+ expect(mock.put(data)).to eq(data)
43
+ end
44
+ end
45
+
46
+ describe 'post' do
47
+ it 'returns the correct data' do
48
+ expect(mock.post(data)).to eq(data)
49
+ end
50
+ end
51
+
52
+ describe 'delete' do
53
+ it 'returns the correct data' do
54
+ expect(mock.delete).to eq('')
55
+ end
56
+ end
57
+ end
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.10
4
+ version: 0.6.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
@@ -45,12 +45,12 @@ files:
45
45
  - lib/usps/imis.rb
46
46
  - lib/usps/imis/api.rb
47
47
  - lib/usps/imis/business_object.rb
48
+ - lib/usps/imis/business_object_mock.rb
48
49
  - lib/usps/imis/config.rb
49
50
  - lib/usps/imis/error/api_error.rb
50
51
  - lib/usps/imis/error/mapper_error.rb
51
52
  - lib/usps/imis/error/response_error.rb
52
53
  - lib/usps/imis/mapper.rb
53
- - lib/usps/imis/mock.rb
54
54
  - lib/usps/imis/panel/base_panel.rb
55
55
  - lib/usps/imis/panel/education.rb
56
56
  - lib/usps/imis/panel/vsc.rb
@@ -58,12 +58,12 @@ files:
58
58
  - lib/usps/imis/requests.rb
59
59
  - lib/usps/imis/version.rb
60
60
  - spec/lib/usps/imis/api_spec.rb
61
+ - spec/lib/usps/imis/business_object_mock_spec.rb
61
62
  - spec/lib/usps/imis/business_object_spec.rb
62
63
  - spec/lib/usps/imis/config_spec.rb
63
64
  - spec/lib/usps/imis/error/api_error_spec.rb
64
65
  - spec/lib/usps/imis/error/response_error_spec.rb
65
66
  - spec/lib/usps/imis/mapper_spec.rb
66
- - spec/lib/usps/imis/mock_spec.rb
67
67
  - spec/lib/usps/imis/panel/base_panel_spec.rb
68
68
  - spec/lib/usps/imis/panel/education_spec.rb
69
69
  - spec/lib/usps/imis/panel/vsc_spec.rb
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Usps::Imis::Mock do
6
- let(:mock) { described_class.new(**fields) }
7
- let(:fields) { { TotMMS: 2 } }
8
-
9
- describe 'get' do
10
- it 'returns the correct Properties data' do
11
- expect(mock.get).to eq(
12
- 'Properties' => {
13
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyDataCollection, Asi.Contracts',
14
- '$values' => [
15
- {
16
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
17
- 'Name' => 'TotMMS',
18
- 'Value' => {
19
- '$type' => 'System.Int32',
20
- '$value' => 2
21
- }
22
- }
23
- ]
24
- }
25
- )
26
- end
27
- end
28
- end