usps-imis-api 0.6.13 → 0.6.15

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: ce718cab17b65f021cb739faa943d2437f2f4e83f051ad50c37a9ae0cfe48131
4
- data.tar.gz: 34cece880ed383d43536f915b1c9480fe557587a61d69c9ed32c061932bbfd3a
3
+ metadata.gz: 1ece5a19e925e1ef85b9e54b1d8fe7139c4015b0a1fe7ddcb602e172fbb50cab
4
+ data.tar.gz: 723eb4ccbf3b0c86c3f309c83d32d2b892420c688fd1f8aa2bfedcc47d61d2a9
5
5
  SHA512:
6
- metadata.gz: a05b5e0bc67ac874b306e688decd19d61c28d4a734165817395f2194a5ac2e166c5e75bcfc900488036f83941c81b4fd0c840810a261813d8b2ae343d5597608
7
- data.tar.gz: aa402f52a26d2eb0d44928d9461707bc671d6ebf4f3e85325407762d2529b09668b02c2970f58528ad125d1e36c87718439817307f676b0858d764ac358cc7df
6
+ metadata.gz: fbca9aeda6a7a4e7fc6701c2767da349ab49e6b9126b36ea0a6225b4c18b2c7970dc22390ddabfbf571411d76b86ab2b37bbde79f471f4b5a3ceba9d271fdd5c
7
+ data.tar.gz: 3b09c75a050ad32e8077d9bc07772d91bb37a7e4628734c0159cb05a206f7f9128059532e22e90f014f07041f2ac87d0d37c2d7878845069c1220ec221cb4e69
data/.rubocop.yml CHANGED
@@ -37,6 +37,8 @@ Lint/UnusedMethodArgument:
37
37
  Enabled: true
38
38
  Lint/UselessAssignment:
39
39
  Enabled: true
40
+ Lint/ItWithoutArgumentsInBlock:
41
+ Enabled: false
40
42
 
41
43
  Metrics/MethodLength:
42
44
  Enabled: true
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps-imis-api (0.6.13)
4
+ usps-imis-api (0.6.15)
5
5
  activesupport (~> 8.0)
6
6
 
7
7
  GEM
data/Readme.md CHANGED
@@ -216,9 +216,9 @@ previous value.
216
216
  api.with(31092) do
217
217
  # These requests are identical:
218
218
 
219
- on('ABC_ASC_Individual_Demog') { put('TotMMS' => 15) }
219
+ on('ABC_ASC_Individual_Demog') { put_fields('TotMMS' => 15) }
220
220
 
221
- on('ABC_ASC_Individual_Demog').put('TotMMS' => 15)
221
+ on('ABC_ASC_Individual_Demog').put_fields('TotMMS' => 15)
222
222
 
223
223
  mapper.update(mm: 15)
224
224
 
@@ -237,7 +237,7 @@ api.with(31092) do
237
237
  # These requests are identical:
238
238
 
239
239
  on('ABC_ASC_Individual_Demog') do
240
- get['Properties']['$values'].find { |hash| hash['Name'] == 'TotMMS' }['Value']['$value']
240
+ get['Properties']['$values'].find { it['Name'] == 'TotMMS' }['Value']['$value']
241
241
  end
242
242
 
243
243
  on('ABC_ASC_Individual_Demog') { get_field('TotMMS') }
@@ -39,6 +39,7 @@ module Usps
39
39
  result = submit(uri, authorize(request))
40
40
  JSON.parse(result.body)
41
41
  end
42
+ alias read get
42
43
 
43
44
  # Get a single named field from a business object for the current member
44
45
  #
@@ -48,10 +49,11 @@ module Usps
48
49
  #
49
50
  def get_field(name)
50
51
  values = get['Properties']['$values']
51
- value = values.find { |hash| hash['Name'] == name }['Value']
52
+ value = values.find { it['Name'] == name }['Value']
52
53
 
53
54
  value.is_a?(String) ? value : value['$value']
54
55
  end
56
+ alias fetch get_field
55
57
 
56
58
  # Update only specific fields on a business object for the current member
57
59
  #
@@ -63,9 +65,12 @@ module Usps
63
65
  updated = filter_fields(fields)
64
66
  put(updated)
65
67
  end
68
+ alias patch put_fields
66
69
 
67
70
  # Update a business object for the current member
68
71
  #
72
+ # Any properties not included will be left unmodified
73
+ #
69
74
  # @param body [Hash] Full raw API object data
70
75
  #
71
76
  # @return [Hash] Response data from the API
@@ -76,6 +81,7 @@ module Usps
76
81
  result = submit(uri, authorize(request))
77
82
  JSON.parse(result.body)
78
83
  end
84
+ alias update put
79
85
 
80
86
  # Create a business object for the current member
81
87
  #
@@ -89,6 +95,7 @@ module Usps
89
95
  result = submit(uri, authorize(request))
90
96
  JSON.parse(result.body)
91
97
  end
98
+ alias create post
92
99
 
93
100
  # Remove a business object for the current member
94
101
  #
@@ -99,6 +106,7 @@ module Usps
99
106
  result = submit(uri, authorize(request))
100
107
  result.body
101
108
  end
109
+ alias destroy delete
102
110
 
103
111
  private
104
112
 
@@ -127,11 +135,13 @@ module Usps
127
135
  existing = get
128
136
 
129
137
  JSON.parse(JSON.dump(existing)).tap do |updated|
130
- # The first property is always the iMIS ID again
131
- updated['Properties']['$values'] = [existing['Properties']['$values'][0]]
138
+ # Preserve the iMIS ID, as well as the Ordinal (if present)
139
+ updated['Properties']['$values'], properties =
140
+ existing['Properties']['$values'].partition { %w[ID Ordinal].include?(it['Name']) }
132
141
 
133
142
  # Iterate through all existing fields
134
- existing['Properties']['$values'].each do |value|
143
+ properties.each do |value|
144
+ # Skip unmodified fields
135
145
  next unless fields.keys.include?(value['Name'])
136
146
 
137
147
  # Strings are not wrapped in the type definition structure
@@ -43,7 +43,7 @@ module Usps
43
43
  # @return [Hash]
44
44
  #
45
45
  def bugsnag_meta_data
46
- base_metadata.tap { |m| m[:api].merge!(metadata) }
46
+ base_metadata.tap { it[:api].merge!(metadata) }
47
47
  end
48
48
 
49
49
  # Auto-formatted exception message, based on the provided API response
@@ -22,31 +22,59 @@ module Usps
22
22
  def get(ordinal)
23
23
  api.on(business_object, ordinal:).get
24
24
  end
25
+ alias read get
25
26
 
26
- # Create a new object in the Panel
27
+ # Get a single named field from a Panel for the current member
27
28
  #
28
- # @param data [Hash] The record data for the desired object
29
+ # @param ordinal [Integer] The ordinal identifier for the desired object
30
+ # @param name [String] Field name to return
29
31
  #
30
- def create(data)
31
- api.on(business_object).post(payload(data))
32
+ # @return [Hash] Response data from the API
33
+ #
34
+ def get_field(ordinal, name)
35
+ api.on(business_object, ordinal:).get_field(name)
36
+ end
37
+ alias fetch get_field
38
+
39
+ # Update only specific fields on a Panel for the current member
40
+ #
41
+ # @param ordinal [Integer] The ordinal identifier for the desired object
42
+ # @param fields [Hash] Conforms to pattern +{ field_key => value }+
43
+ #
44
+ # @return [Hash] Response data from the API
45
+ #
46
+ def put_fields(ordinal, fields)
47
+ api.on(business_object, ordinal:).put_fields(fields)
32
48
  end
49
+ alias patch put_fields
33
50
 
34
51
  # Update an existing object in the Panel
35
52
  #
36
53
  # @param data [Hash] The record data for the desired object -- including the required
37
54
  # +ordinal+ identifier
38
55
  #
39
- def update(data)
56
+ def put(data)
40
57
  api.on(business_object, ordinal: data[:ordinal]).put(payload(data))
41
58
  end
59
+ alias update put
60
+
61
+ # Create a new object in the Panel
62
+ #
63
+ # @param data [Hash] The record data for the desired object
64
+ #
65
+ def post(data)
66
+ api.on(business_object).post(payload(data))
67
+ end
68
+ alias create post
42
69
 
43
70
  # Remove a specific object from the Panel
44
71
  #
45
72
  # @param ordinal [Integer] The ordinal identifier for the desired object
46
73
  #
47
- def destroy(ordinal)
74
+ def delete(ordinal)
48
75
  api.on(business_object, ordinal:).delete
49
76
  end
77
+ alias destroy delete
50
78
 
51
79
  private
52
80
 
@@ -20,7 +20,7 @@ module Usps
20
20
  #
21
21
  def authorize(request)
22
22
  authenticate if token_expiration < Time.now
23
- request.tap { |r| r.add_field('Authorization', "Bearer #{token}") }
23
+ request.tap { it.add_field('Authorization', "Bearer #{token}") }
24
24
  end
25
25
 
26
26
  def submit(uri, request)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Imis
5
- VERSION = '0.6.13'
5
+ VERSION = '0.6.15'
6
6
  end
7
7
  end
@@ -10,7 +10,7 @@ describe Usps::Imis::BusinessObject do
10
10
  {
11
11
  'Properties' => {
12
12
  '$values' => [
13
- { 'Name' => 'Stub iMIS ID', 'Value' => { '$value' => '31092' } },
13
+ { 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
14
14
  { 'Name' => 'Stub Integer', 'Value' => { '$value' => 43 } },
15
15
  { 'Name' => 'Stub String', 'Value' => 'other' }
16
16
  ]
@@ -22,7 +22,7 @@ describe Usps::Imis::BusinessObject do
22
22
  allow(business_object).to receive(:get).and_return({
23
23
  'Properties' => {
24
24
  '$values' => [
25
- { 'Name' => 'Stub iMIS ID', 'Value' => { '$value' => '31092' } },
25
+ { 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
26
26
  { 'Name' => 'Stub Integer', 'Value' => { '$value' => 42 } },
27
27
  { 'Name' => 'Stub String', 'Value' => 'something' }
28
28
  ]
@@ -24,7 +24,7 @@ describe Usps::Imis::Config do
24
24
  subject { config.environment }
25
25
 
26
26
  let(:config) do
27
- described_class.new { |c| c.environment = 'test' }
27
+ described_class.new { it.environment = 'test' }
28
28
  end
29
29
 
30
30
  it { is_expected.to be_test }
@@ -14,7 +14,6 @@ describe Usps::Imis::Panel::Education do
14
14
  source: 'Online Exams System',
15
15
  code: 'MN',
16
16
  type_code: 'CRS'
17
-
18
17
  }
19
18
  end
20
19
 
@@ -26,8 +25,14 @@ describe Usps::Imis::Panel::Education do
26
25
  end
27
26
  end
28
27
 
28
+ describe '#get_field' do
29
+ it 'returns a specific field' do
30
+ expect(education.get_field(90737, 'ABC_Product_Code')).to eq('CRS')
31
+ end
32
+ end
33
+
29
34
  # rubocop:disable RSpec/ExampleLength
30
- it 'handles new records correctly', :aggregate_failures do
35
+ it 'interacts with records correctly', :aggregate_failures do
31
36
  new_record = education.create(details)
32
37
  expect(new_record).to be_a(Hash)
33
38
 
@@ -40,6 +45,12 @@ describe Usps::Imis::Panel::Education do
40
45
  end
41
46
  expect(updated['Value']).to eq('Online Exams System - Modified')
42
47
 
48
+ put_fields_result = education.put_fields(ordinal, 'ABC_Educ_Source_System' => 'Online Exams System - Mod2')
49
+ patched = put_fields_result['Properties']['$values'].find do |v|
50
+ v['Name'] == 'ABC_Educ_Source_System'
51
+ end
52
+ expect(patched['Value']).to eq('Online Exams System - Mod2')
53
+
43
54
  expect(education.destroy(ordinal)).to eq('')
44
55
  end
45
56
  # rubocop:enable RSpec/ExampleLength
@@ -29,7 +29,7 @@ describe Usps::Imis::Panel::Vsc do
29
29
  ordinal = new_record['Identity']['IdentityElements']['$values'][1]
30
30
 
31
31
  update_result = vsc.update(details.merge(count: 43, ordinal:))
32
- updated = update_result['Properties']['$values'].find { |v| v['Name'] == 'Quantity' }
32
+ updated = update_result['Properties']['$values'].find { it['Name'] == 'Quantity' }
33
33
  expect(updated['Value']['$value']).to eq(43)
34
34
 
35
35
  expect(vsc.destroy(ordinal)).to eq('')
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.13
4
+ version: 0.6.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander