usps-imis-api 0.9.7 → 0.9.8

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: a78cd8daed5969574e8ec5fc3120a8a5a6c362e519918620ce41c2ed0fc0f26c
4
- data.tar.gz: 0f20aa470ec2f2b8501f670046ee1071fea8552c22dd9f70165fb2ea986a46aa
3
+ metadata.gz: 80cb6198e125d3dc201641a6a70c639c8890094582fe6c293c807fb212a59738
4
+ data.tar.gz: e5382f2b08c9bffd26204cd06c3d55bc8604e7fa62ebc612a5b88a42a4029ab1
5
5
  SHA512:
6
- metadata.gz: 41f2a2c9082ce49399a1a9b3e44ddd2cb86a8624d112ea6c36875e05da74db61cd6272f96819d0d889c5ac83e857f900ecaad357da9dd25a3b3094b7354dbce4
7
- data.tar.gz: 131e53225ae3d111b49c64302a99d5b32227e45b2734c42ea2131d5de986c60c2d359c43aef10a5191ce03d6406c5f6bbe0fcfadd11843347533cef0dcd555f3
6
+ metadata.gz: ba2f8613ca13a61eda5d8a0c5a229e09d8226e74ca8611f83e80d6d3259e2f120f6fddab9ee2eb7740c0de150de8462537219147fe7d3c2aceafc5e0c8652dfc
7
+ data.tar.gz: 472196fce4e1a5e05287889b6d70e56bc72f5326944dafd114527865688d82f3208d7e4ae38b4161a176ea43663a7981eee196e145bbeac3d62f9c2f9b941713
data/.rubocop.yml CHANGED
@@ -84,3 +84,6 @@ Security/JSONLoad:
84
84
  Enabled: true
85
85
  Security/YAMLLoad:
86
86
  Enabled: true
87
+
88
+ RSpec/NestedGroups:
89
+ Max: 4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps-imis-api (0.9.7)
4
+ usps-imis-api (0.9.8)
5
5
  activesupport (~> 8.0)
6
6
 
7
7
  GEM
data/Readme.md CHANGED
@@ -213,7 +213,7 @@ end
213
213
  ### Field Mapper
214
214
 
215
215
  For fields that have already been mapped between the ITCom database and iMIS, you can use the
216
- Mapper class to further simplify the fetch / update interfaces:
216
+ Mapper class to further simplify the `fetch` / `update` interfaces:
217
217
 
218
218
  ```ruby
219
219
  mm = api.mapper.fetch(:mm)
@@ -234,6 +234,7 @@ api[:mm]
234
234
 
235
235
  ```ruby
236
236
  api.update(mm: 15)
237
+ api[:mm] = 15
237
238
  ```
238
239
 
239
240
  If there is no known mapping for the requested field, the Mapper will give up, but will provide
@@ -272,6 +273,7 @@ ordinal = created.raw['Identity']['IdentityElements']['$values'][1].to_i # Value
272
273
  vsc.update(certificate: 'E136924', year: 2024, count: 43, ordinal: ordinal)
273
274
 
274
275
  vsc.put_fields(ordinal, 'Quantity' => 44)
276
+ vsc['Quantity'] = 44
275
277
 
276
278
  vsc.destroy(ordinal)
277
279
  ```
@@ -305,7 +307,12 @@ api.with(31092) do
305
307
  mapper.update(mm: 15)
306
308
 
307
309
  update(mm: 15)
310
+
311
+ mapper[:mm] = 15
308
312
  end
313
+
314
+ # This request fetches the same data, but leaves the iMIS ID selected
315
+ api.with(31092)[:mm] = 15
309
316
  ```
310
317
 
311
318
  ```ruby
@@ -333,8 +340,9 @@ api.with(31092) do
333
340
  on('ABC_ASC_Individual_Demog')['TotMMS']
334
341
  end
335
342
 
336
- # This request fetches the same data, but leaves the iMIS ID selected
343
+ # These requests fetch the same data, but leave the iMIS ID selected
337
344
  api.with(31092).on('ABC_ASC_Individual_Demog').get_field('TotMMS')
345
+ api.with(31092).on('ABC_ASC_Individual_Demog')['TotMMS']
338
346
  ```
339
347
 
340
348
  ### Data Methods
data/lib/usps/imis/api.rb CHANGED
@@ -133,6 +133,11 @@ module Usps
133
133
  def fetch(field_key) = mapper.fetch(field_key)
134
134
  alias [] fetch
135
135
 
136
+ # Convenience alias for updating mapped fields
137
+ #
138
+ def put_field(field_key, value) = update(field_key => value)
139
+ alias []= put_field
140
+
136
141
  # Convenience alias for updating mapped fields
137
142
  #
138
143
  def update(data) = mapper.update(data)
@@ -66,6 +66,16 @@ module Usps
66
66
  end
67
67
  alias fetch_all get_fields
68
68
 
69
+ # Update a single named field on a business object for the current member
70
+ #
71
+ # @param field [String] Name of the field
72
+ # @param value Value of the field
73
+ #
74
+ # @return [Usps::Imis::Data] Response data from the API
75
+ #
76
+ def put_field(field, value) = put(filter_fields(field => value))
77
+ alias []= put_field
78
+
69
79
  # Update only specific fields on a business object for the current member
70
80
  #
71
81
  # @param fields [Hash] Conforms to pattern +{ field_key => value }+
@@ -17,6 +17,8 @@ module Usps
17
17
  def initialize(message, metadata = {})
18
18
  super(message)
19
19
  @metadata = metadata
20
+
21
+ Imis.logger.debug self
20
22
  end
21
23
 
22
24
  # Additional metadata to include in Bugsnag reports
@@ -28,6 +28,16 @@ module Usps
28
28
  @api.imis_id = imis_id if imis_id
29
29
  end
30
30
 
31
+ # Get a member's data for a specific field by arbitrary field name
32
+ #
33
+ # Does not require knowing which business object / iMIS-specific field name to use
34
+ #
35
+ # Only available for fields defined in +FIELD_MAPPING+
36
+ #
37
+ # @param field_key [Symbol] Internal name of the field
38
+ #
39
+ # @return Value of the field
40
+ #
31
41
  def fetch(field_key)
32
42
  missing_mapping!(field_key) unless FIELD_MAPPING.key?(field_key.to_sym)
33
43
 
@@ -36,6 +46,19 @@ module Usps
36
46
  end
37
47
  alias [] fetch
38
48
 
49
+ # Update a member's data for a specific field by arbitrary field name
50
+ #
51
+ # Does not require knowing which business object / iMIS-specific field name to use
52
+ #
53
+ # Only available for fields defined in +FIELD_MAPPING+
54
+ #
55
+ # @param field_key [Symbol] Internal name of the field
56
+ #
57
+ # @return Value of the field
58
+ #
59
+ def put_field(field_key, value) = update(field_key => value)
60
+ alias []= put_field
61
+
39
62
  # Update a member's data on multiple affected business objects by arbitrary field names
40
63
  #
41
64
  # Does not require knowing which business object / iMIS-specific field name to use
@@ -49,6 +49,16 @@ module Usps
49
49
  def get_fields(ordinal, *fields) = api.on(business_object, ordinal:).get_fields(*fields)
50
50
  alias fetch_all get_fields
51
51
 
52
+ # Update a single named field on a business object for the current member
53
+ #
54
+ # @param field [String] Name of the field
55
+ # @param value Value of the field
56
+ #
57
+ # @return [Usps::Imis::Data] Response data from the API
58
+ #
59
+ def put_field(field, value) = api.on(business_object, ordinal:).put_field(field, value)
60
+ alias []= put_field
61
+
52
62
  # Update only specific fields on a Panel for the current member
53
63
  #
54
64
  # @param ordinal [Integer] The ordinal identifier for the desired object
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Imis
5
- VERSION = '0.9.7'
5
+ VERSION = '0.9.8'
6
6
  end
7
7
  end
@@ -3,72 +3,85 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Usps::Imis::BusinessObject do
6
- let(:business_object) { described_class.new(api, 'Stub') }
7
- let(:api) { Usps::Imis::Api.new }
8
-
9
- before do
10
- allow(business_object).to receive(:raw_object).and_return(
11
- Usps::Imis::Data[
12
- 'Properties' => {
13
- '$values' => [
14
- { 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
15
- { 'Name' => 'Stub Integer', 'Value' => { '$value' => 42 } },
16
- { 'Name' => 'Stub String', 'Value' => 'something' }
17
- ]
18
- }
19
- ]
20
- )
6
+ describe '#put_field' do
7
+ let(:business_object) { api.on('ABC_ASC_Individual_Demog') }
8
+ let(:api) { Usps::Imis::Api.new.with(31092) }
9
+
10
+ before { business_object.put_field('TotMMS', 15) }
11
+
12
+ it 'submits the correct update request' do
13
+ expect { business_object['TotMMS'] = 16 }.to change { business_object['TotMMS'] }.from(15).to(16)
14
+ end
21
15
  end
22
16
 
23
- describe '#get' do
24
- it 'returns multiple values' do
25
- expect(business_object.get('Stub String', 'Stub Integer')).to eq(['something', 42])
17
+ context 'with stubbed data' do
18
+ let(:business_object) { described_class.new(api, 'Stub') }
19
+ let(:api) { Usps::Imis::Api.new }
20
+
21
+ before do
22
+ allow(business_object).to receive(:raw_object).and_return(
23
+ Usps::Imis::Data[
24
+ 'Properties' => {
25
+ '$values' => [
26
+ { 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
27
+ { 'Name' => 'Stub Integer', 'Value' => { '$value' => 42 } },
28
+ { 'Name' => 'Stub String', 'Value' => 'something' }
29
+ ]
30
+ }
31
+ ]
32
+ )
26
33
  end
27
34
 
28
- describe 'delegation to get_fields' do
29
- before { allow(business_object).to receive(:get_fields).with('Stub String', 'Stub Integer') }
35
+ describe '#get' do
36
+ it 'returns multiple values' do
37
+ expect(business_object.get('Stub String', 'Stub Integer')).to eq(['something', 42])
38
+ end
39
+
40
+ describe 'delegation to get_fields' do
41
+ before { allow(business_object).to receive(:get_fields).with('Stub String', 'Stub Integer') }
30
42
 
31
- it 'delegates to get_fields' do
32
- business_object.get('Stub String', 'Stub Integer')
43
+ it 'delegates to get_fields' do
44
+ business_object.get('Stub String', 'Stub Integer')
33
45
 
34
- expect(business_object).to have_received(:get_fields).with('Stub String', 'Stub Integer')
46
+ expect(business_object).to have_received(:get_fields).with('Stub String', 'Stub Integer')
47
+ end
35
48
  end
36
49
  end
37
- end
38
50
 
39
- describe '#get_field' do
40
- it 'returns a string value' do
41
- expect(business_object.get_field('Stub String')).to eq('something')
42
- end
51
+ describe '#get_field' do
52
+ it 'returns a string value' do
53
+ expect(business_object.get_field('Stub String')).to eq('something')
54
+ end
43
55
 
44
- it 'returns an integer value' do
45
- expect(business_object.get_field('Stub Integer')).to eq(42)
56
+ it 'returns an integer value' do
57
+ expect(business_object.get_field('Stub Integer')).to eq(42)
58
+ end
46
59
  end
47
- end
48
60
 
49
- describe '#get_fields' do
50
- it 'returns multiple values' do
51
- expect(business_object.get_fields('Stub String', 'Stub Integer')).to eq(['something', 42])
61
+ describe '#get_fields' do
62
+ it 'returns multiple values' do
63
+ expect(business_object.get_fields('Stub String', 'Stub Integer')).to eq(['something', 42])
64
+ end
52
65
  end
53
- end
54
66
 
55
- describe '#filter_fields' do
56
- let(:expected) do
57
- {
58
- 'Properties' => {
59
- '$values' => [
60
- { 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
61
- { 'Name' => 'Stub Integer', 'Value' => { '$value' => 43 } },
62
- { 'Name' => 'Stub String', 'Value' => 'other' }
63
- ]
67
+ describe '#filter_fields' do
68
+ let(:expected) do
69
+ {
70
+ 'Properties' => {
71
+ '$values' => [
72
+ { 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
73
+ { 'Name' => 'Stub Integer', 'Value' => { '$value' => 43 } },
74
+ { 'Name' => 'Stub String', 'Value' => 'other' }
75
+ ]
76
+ }
64
77
  }
65
- }
66
- end
78
+ end
67
79
 
68
- it 'formats fields correctly' do
69
- updated = business_object.send(:filter_fields, 'Stub Integer' => 43, 'Stub String' => 'other')
80
+ it 'formats fields correctly' do
81
+ updated = business_object.send(:filter_fields, 'Stub Integer' => 43, 'Stub String' => 'other')
70
82
 
71
- expect(updated).to eq(expected)
83
+ expect(updated).to eq(expected)
84
+ end
72
85
  end
73
86
  end
74
87
  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.9.7
4
+ version: 0.9.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander