usps-imis-api 0.6.14 → 0.6.16

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: 05b1b663fab7b4f81c95f105c0c7f667bc2f5b9855b5fd48e5f384ce0adba8dc
4
- data.tar.gz: '02529c44a577d5e239b3bd306cec0f9f91e53413ef3d921c5564352e8dca3d5f'
3
+ metadata.gz: 9d68eb23f00014bc9cb6173f716084f8eff9cedfc48e70507c07a35fe8e7b207
4
+ data.tar.gz: fda5c7882bc758d9cfdd2889e734ff8c0d319f456e39bf1965f030765ec82a0e
5
5
  SHA512:
6
- metadata.gz: e81f01c677aa5a22b1c7c5cfeb6e3119cc1f4387dc2076fec0001032879378f5be3cd562c3ccdd689a5e26e7becb4381a891249c175b025014d78638a36dd03e
7
- data.tar.gz: 3e3f53303d8316f814cefffb3473ccb8e91c5fbd5146bc94b1701532c006fbf8b0ab905a156bd880e3fe6a2f1c2c4f79528c591df8b6ad6e26cb8cee7ab88346
6
+ metadata.gz: bb42f257b1e4e6c6383dd9b1f37d68e9c89f358f98bfccb09c53190573da28b0259fabe27e12f50c5420daa8f009661e928463c19a48e854abd86b8dd34021f1
7
+ data.tar.gz: a4fb539ef056e6936e1546b303ef8b20bf52a822185063d8b6eabc042eb5b3f2b2fceb5d0cff5959c40ce524175a137dd1821783af7eea495803342c1d065cff
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.14)
4
+ usps-imis-api (0.6.16)
5
5
  activesupport (~> 8.0)
6
6
 
7
7
  GEM
data/Readme.md CHANGED
@@ -77,7 +77,13 @@ You can also manually set the current ID, if you already have it for a given mem
77
77
  api.imis_id = imis_id
78
78
  ```
79
79
 
80
- ### GET
80
+ ### Business Object and Panel Actions
81
+
82
+ Business Objects and Panels support the following actions.
83
+
84
+ Panels require passing in the ordinal identifier as an argument, except for `POST`.
85
+
86
+ #### GET
81
87
 
82
88
  To fetch member data, run e.g.:
83
89
 
@@ -87,7 +93,9 @@ api.imis_id = 31092
87
93
  data = api.on('ABC_ASC_Individual_Demog').get
88
94
  ```
89
95
 
90
- ### GET Field
96
+ Alias: `read`
97
+
98
+ #### GET Field
91
99
 
92
100
  To fetch a specific field from member data, run e.g.:
93
101
 
@@ -97,7 +105,9 @@ api.imis_id = 31092
97
105
  tot_mms = api.on('ABC_ASC_Individual_Demog').get_field('TotMMS')
98
106
  ```
99
107
 
100
- ### PUT Fields
108
+ Alias: `fetch`
109
+
110
+ #### PUT Fields
101
111
 
102
112
  To update member data, run e.g.:
103
113
 
@@ -111,7 +121,9 @@ update = api.on('ABC_ASC_Individual_Demog').put_fields(data)
111
121
  This method fetches the current data structure, and filters it down to just what you want to
112
122
  update, to reduce the likelihood of update collisions or type validation failures.
113
123
 
114
- ### PUT
124
+ Alias: `patch`
125
+
126
+ #### PUT
115
127
 
116
128
  To update member data, run e.g.:
117
129
 
@@ -121,9 +133,13 @@ api.imis_id = 31092
121
133
  update = api.on('ABC_ASC_Individual_Demog').put(complete_imis_object)
122
134
  ```
123
135
 
124
- This method requires a complete iMIS data structure.
136
+ This method requires a complete iMIS data structure. However, any properties not included will be
137
+ left unmodified (meaning this also effectively handles `PATCH`, though iMIS does not accept that
138
+ HTTP verb).
139
+
140
+ Alias: `update`
125
141
 
126
- ### POST
142
+ #### POST
127
143
 
128
144
  To create new member data, run e.g.:
129
145
 
@@ -133,7 +149,9 @@ created = api.on('ABC_ASC_Individual_Demog').post(complete_imis_object)
133
149
 
134
150
  This method requires a complete iMIS data structure.
135
151
 
136
- ### DELETE
152
+ Alias: `create`
153
+
154
+ #### DELETE
137
155
 
138
156
  To remove member data, run e.g.:
139
157
 
@@ -145,6 +163,8 @@ api.on('ABC_ASC_Individual_Demog').delete
145
163
 
146
164
  This returns a blank string on success.
147
165
 
166
+ Alias: `destroy`
167
+
148
168
  ### QUERY
149
169
 
150
170
  Run an IQA Query
@@ -187,7 +207,8 @@ vsc.api.imis_id = 6374
187
207
  vsc.get(1417)
188
208
 
189
209
  created = vsc.create(certificate: 'E136924', year: 2024, count: 42)
190
- ordinal = created['Properties']['$values'][1]['Value']['$value']
210
+ ordinal = created['Properties']['$values'].find { it['Name'] == 'Ordinal' }['Value']['$value']
211
+ # ordinal = created['Identity']['IdentityElements']['$values'][1] # Alternative
191
212
 
192
213
  vsc.update(certificate: 'E136924', year: 2024, count: 43, ordinal: ordinal)
193
214
 
@@ -237,7 +258,7 @@ api.with(31092) do
237
258
  # These requests are identical:
238
259
 
239
260
  on('ABC_ASC_Individual_Demog') do
240
- get['Properties']['$values'].find { |hash| hash['Name'] == 'TotMMS' }['Value']['$value']
261
+ get['Properties']['$values'].find { it['Name'] == 'TotMMS' }['Value']['$value']
241
262
  end
242
263
 
243
264
  on('ABC_ASC_Individual_Demog') { get_field('TotMMS') }
data/lib/usps/imis/api.rb CHANGED
@@ -132,15 +132,6 @@ module Usps
132
132
  results
133
133
  end
134
134
 
135
- # An instance of +BusinessObject+, using this instance as its parent +Api+
136
- #
137
- # @param business_object_name [String] Name of the business object
138
- # @param ordinal [Integer] Ordinal to build override ID param of the URL (e.g. used for Panels)
139
- #
140
- def business_object(business_object_name, ordinal: nil)
141
- BusinessObject.new(self, business_object_name, ordinal:)
142
- end
143
-
144
135
  # Run requests as DSL, with specific +BusinessObject+ only maintained for this scope
145
136
  #
146
137
  # If no block is given, this returns the specified +BusinessObject+.
@@ -149,7 +140,7 @@ module Usps
149
140
  # @param ordinal [Integer] Ordinal to build override ID param of the URL (e.g. used for Panels)
150
141
  #
151
142
  def on(business_object_name, ordinal: nil, &)
152
- object = business_object(business_object_name, ordinal:)
143
+ object = BusinessObject.new(self, business_object_name, ordinal:)
153
144
  return object unless block_given?
154
145
 
155
146
  object.instance_eval(&)
@@ -49,7 +49,7 @@ module Usps
49
49
  #
50
50
  def get_field(name)
51
51
  values = get['Properties']['$values']
52
- value = values.find { |hash| hash['Name'] == name }['Value']
52
+ value = values.find { it['Name'] == name }['Value']
53
53
 
54
54
  value.is_a?(String) ? value : value['$value']
55
55
  end
@@ -69,6 +69,8 @@ module Usps
69
69
 
70
70
  # Update a business object for the current member
71
71
  #
72
+ # Any properties not included will be left unmodified
73
+ #
72
74
  # @param body [Hash] Full raw API object data
73
75
  #
74
76
  # @return [Hash] Response data from the API
@@ -133,22 +135,21 @@ module Usps
133
135
  existing = get
134
136
 
135
137
  JSON.parse(JSON.dump(existing)).tap do |updated|
136
- # Wipe the array on the duped object
137
- #
138
- # The first property is always the iMIS ID again
139
- #
140
- updated['Properties']['$values'] = []
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']) }
141
141
 
142
142
  # Iterate through all existing fields
143
- existing['Properties']['$values'].each do |value|
144
- if fields.keys.include?(value['Name'])
145
- # Strings are not wrapped in the type definition structure
146
- new_value = fields[value['Name']]
147
- if new_value.is_a?(String)
148
- value['Value'] = new_value
149
- else
150
- value['Value']['$value'] = new_value
151
- end
143
+ properties.each do |value|
144
+ # Skip unmodified fields
145
+ next unless fields.keys.include?(value['Name'])
146
+
147
+ # Strings are not wrapped in the type definition structure
148
+ new_value = fields[value['Name']]
149
+ if new_value.is_a?(String)
150
+ value['Value'] = new_value
151
+ else
152
+ value['Value']['$value'] = new_value
152
153
  end
153
154
 
154
155
  # Add the completed field with the updated value
@@ -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
@@ -47,7 +47,7 @@ module Usps
47
47
  end
48
48
 
49
49
  updates.map do |business_object_name, field_updates|
50
- api.business_object(business_object_name).put_fields(field_updates)
50
+ api.on(business_object_name).put_fields(field_updates)
51
51
  end
52
52
  end
53
53
 
@@ -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.14'
5
+ VERSION = '0.6.16'
6
6
  end
7
7
  end
@@ -56,7 +56,7 @@ describe Usps::Imis::Api do
56
56
  before { api.imis_id = 31092 }
57
57
 
58
58
  it 'sends an update' do
59
- expect(api.business_object('ABC_ASC_Individual_Demog').put_fields('TotMMS' => 15)).to(
59
+ expect(api.on('ABC_ASC_Individual_Demog').put_fields('TotMMS' => 15)).to(
60
60
  be_a(Hash)
61
61
  )
62
62
  end
@@ -78,7 +78,7 @@ describe Usps::Imis::Api do
78
78
  end
79
79
 
80
80
  it 'wraps the error' do
81
- expect { api.business_object('ABC_ASC_Individual_Demog').put_fields('TotMMS' => 15) }.to(
81
+ expect { api.on('ABC_ASC_Individual_Demog').put_fields('TotMMS' => 15) }.to(
82
82
  raise_error(Usps::Imis::Error::ApiError, warning_text)
83
83
  )
84
84
  end
@@ -88,7 +88,7 @@ describe Usps::Imis::Api do
88
88
  describe '#with' do
89
89
  it 'sends an update from put' do
90
90
  expect(
91
- api.with(31092) { business_object('ABC_ASC_Individual_Demog').put_fields('TotMMS' => 15) }
91
+ api.with(31092) { on('ABC_ASC_Individual_Demog').put_fields('TotMMS' => 15) }
92
92
  ).to be_a(Hash)
93
93
  end
94
94
 
@@ -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
 
@@ -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.14
4
+ version: 0.6.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander