usps-imis-api 0.1.1 → 0.1.3
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 +4 -4
- data/.github/workflows/main.yml +38 -0
- data/.rubocop.yml +5 -3
- data/Gemfile.lock +1 -1
- data/Readme.md +21 -3
- data/lib/imis/api.rb +16 -0
- data/lib/imis/mapper.rb +35 -12
- data/spec/{api_spec.rb → lib/imis/api_spec.rb} +10 -0
- data/spec/{mapper_spec.rb → lib/imis/mapper_spec.rb} +2 -2
- data/spec/spec_helper.rb +1 -1
- data/usps-imis-api.gemspec +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a27bda1b2938e0cfedde1da424a7694a001c539deb705032c4e7aefe126361a
|
4
|
+
data.tar.gz: f2fccb24b0f76b452a6b7b3719e225f6659f53d8e6251be130d920bff1f299dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a86560e9f859589317faf46dc524105d2b77b2e25d869c6eec604fa1f98592ed4bdf59a6675078e89345782ab45017fdf34f5895d99cf3944473fccf05e9faf
|
7
|
+
data.tar.gz: aea9d7c488dec4f017a3252d5294cc9f9fa03eed3e374bbd4d9cc0926c9e76b6c725df5a65ea6eca3314e483153e80be05002917fa49aab8993884fe4cfbd3fd
|
@@ -0,0 +1,38 @@
|
|
1
|
+
name: 'USPS iMIS API - Ruby'
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
workflow_dispatch:
|
5
|
+
|
6
|
+
jobs:
|
7
|
+
rubocop:
|
8
|
+
runs-on: ubuntu-24.04
|
9
|
+
environment: "USPS iMIS API - Ruby"
|
10
|
+
steps:
|
11
|
+
- name: Checkout Code
|
12
|
+
uses: actions/checkout@v4
|
13
|
+
- name: Setup Ruby
|
14
|
+
uses: ruby/setup-ruby@v1
|
15
|
+
with: { bundler-cache: true }
|
16
|
+
- name: Run Rubocop
|
17
|
+
run: bundle exec rubocop
|
18
|
+
rspec:
|
19
|
+
runs-on: ubuntu-24.04
|
20
|
+
environment: "USPS iMIS API - Ruby"
|
21
|
+
env:
|
22
|
+
IMIS_USERNAME: ${{ secrets.IMIS_USERNAME }}
|
23
|
+
IMIS_PASSWORD: ${{ secrets.IMIS_PASSWORD }}
|
24
|
+
IMIS_ID_QUERY_NAME: ${{ secrets.IMIS_ID_QUERY_NAME }}
|
25
|
+
steps:
|
26
|
+
- name: Checkout Code
|
27
|
+
uses: actions/checkout@v4
|
28
|
+
- name: Setup Ruby
|
29
|
+
uses: ruby/setup-ruby@v1
|
30
|
+
with: { bundler-cache: true }
|
31
|
+
- name: Run Rspec
|
32
|
+
run: bundle exec rspec --format documentation --order rand --color --tty
|
33
|
+
- name: Store Coverage
|
34
|
+
uses: actions/upload-artifact@v4
|
35
|
+
with:
|
36
|
+
name: coverage-rspec
|
37
|
+
include-hidden-files: true
|
38
|
+
path: coverage/
|
data/.rubocop.yml
CHANGED
@@ -31,14 +31,14 @@ Layout/SpaceInsideHashLiteralBraces:
|
|
31
31
|
EnforcedStyleForEmptyBraces: no_space
|
32
32
|
Layout/SpaceInsideArrayLiteralBrackets:
|
33
33
|
EnforcedStyle: no_space
|
34
|
+
Layout/LineLength:
|
35
|
+
Max: 100
|
34
36
|
|
35
37
|
Lint/UnusedMethodArgument:
|
36
38
|
Enabled: true
|
37
39
|
Lint/UselessAssignment:
|
38
40
|
Enabled: true
|
39
41
|
|
40
|
-
Metrics/LineLength:
|
41
|
-
Max: 100
|
42
42
|
Metrics/MethodLength:
|
43
43
|
Enabled: true
|
44
44
|
Max: 15
|
@@ -59,13 +59,15 @@ Naming/MemoizedInstanceVariableName:
|
|
59
59
|
Enabled: false
|
60
60
|
Naming/MethodParameterName:
|
61
61
|
Enabled: false
|
62
|
+
Naming/FileName:
|
63
|
+
Enabled: false
|
62
64
|
|
63
65
|
Style/Documentation:
|
64
66
|
Enabled: false
|
65
67
|
Style/FrozenStringLiteralComment:
|
66
68
|
Enabled: true
|
67
69
|
Style/NumericLiterals:
|
68
|
-
Enabled:
|
70
|
+
Enabled: false
|
69
71
|
Style/StringLiterals:
|
70
72
|
EnforcedStyle: single_quotes
|
71
73
|
Style/AndOr:
|
data/Gemfile.lock
CHANGED
data/Readme.md
CHANGED
@@ -13,7 +13,7 @@ gem install usps-imis-api
|
|
13
13
|
or add this line to your Gemfile:
|
14
14
|
|
15
15
|
```ruby
|
16
|
-
gem 'usps-imis-api', '>= 0.1.
|
16
|
+
gem 'usps-imis-api', '>= 0.1.1'
|
17
17
|
```
|
18
18
|
|
19
19
|
## Setup
|
@@ -22,7 +22,7 @@ Include the library, and set the configuration:
|
|
22
22
|
|
23
23
|
```ruby
|
24
24
|
require 'dotenv/load' # Optionally load environment variables from `.env` file
|
25
|
-
require '
|
25
|
+
require 'usps-imis-api'
|
26
26
|
|
27
27
|
Imis.configure do |config|
|
28
28
|
config.environment = :development # Rails.env
|
@@ -129,13 +129,27 @@ For fields that have already been mapped between the ITCom database and iMIS, yo
|
|
129
129
|
Mapper class to further simplify the update interface:
|
130
130
|
|
131
131
|
```ruby
|
132
|
-
api.mapper.update(:
|
132
|
+
api.mapper.update(mm: 15)
|
133
133
|
```
|
134
134
|
|
135
135
|
If there is no known mapping for the requested field, the Mapper will give up, but will provide
|
136
136
|
you with the standard API call syntax, and will suggest you inform ITCom leadership of the new
|
137
137
|
mapping you need.
|
138
138
|
|
139
|
+
### DSL Mode
|
140
|
+
|
141
|
+
Instead of manually setting the current iMIS ID, then running individual queries, you can instead
|
142
|
+
run queries in DSL mode. This specifies the iMIS ID for the scope of the block, then reverts to the
|
143
|
+
previous value.
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
api.with(31092) do
|
147
|
+
# These two requests are identical:
|
148
|
+
put('ABC_ASC_Individual_Demog', { 'TotMMS' => 15 })
|
149
|
+
mapper.update(mm: 15)
|
150
|
+
end
|
151
|
+
```
|
152
|
+
|
139
153
|
## Exception Handling
|
140
154
|
|
141
155
|
Exception and error response handling will be added later.
|
@@ -154,6 +168,10 @@ Linting is available by running:
|
|
154
168
|
bundle exec rubocop
|
155
169
|
```
|
156
170
|
|
171
|
+
### GitHub Actions
|
172
|
+
|
173
|
+
Testing and linting are automatically run on every push.
|
174
|
+
|
157
175
|
## PHP
|
158
176
|
|
159
177
|
This same API is
|
data/lib/imis/api.rb
CHANGED
@@ -25,6 +25,18 @@ module Imis
|
|
25
25
|
@imis_id = result['Items']['$values'][0]['ID']
|
26
26
|
end
|
27
27
|
|
28
|
+
# Run requests as DSL, with specific iMIS ID only maintained for this scope
|
29
|
+
#
|
30
|
+
# This should be used with methods that do not change the value of `imis_id`
|
31
|
+
#
|
32
|
+
def with(id, &block)
|
33
|
+
old_id = imis_id
|
34
|
+
self.imis_id = id
|
35
|
+
instance_eval(&block)
|
36
|
+
ensure
|
37
|
+
self.imis_id = old_id
|
38
|
+
end
|
39
|
+
|
28
40
|
# Get a business object for the current member
|
29
41
|
#
|
30
42
|
def get(business_object_name)
|
@@ -65,6 +77,10 @@ module Imis
|
|
65
77
|
@mapper ||= Mapper.new(self)
|
66
78
|
end
|
67
79
|
|
80
|
+
def update(data)
|
81
|
+
mapper.update(data)
|
82
|
+
end
|
83
|
+
|
68
84
|
private
|
69
85
|
|
70
86
|
def client(uri)
|
data/lib/imis/mapper.rb
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
module Imis
|
4
4
|
class Mapper
|
5
5
|
FIELD_MAPPING = {
|
6
|
-
vessel_examiner: [
|
7
|
-
mm: [
|
8
|
-
mm_updated: [
|
6
|
+
vessel_examiner: %w[ABC_ASC_Individual_Demog Vol_Vessel_Examiner],
|
7
|
+
mm: %w[ABC_ASC_Individual_Demog TotMMS],
|
8
|
+
mm_updated: %w[ABC_ASC_Individual_Demog MMS_Updated]
|
9
9
|
}.freeze
|
10
10
|
|
11
11
|
attr_reader :api
|
@@ -14,28 +14,51 @@ module Imis
|
|
14
14
|
@api = api
|
15
15
|
end
|
16
16
|
|
17
|
-
# Update a member's data by
|
17
|
+
# Update a member's data on multiple affected business objects by arbitrary field names
|
18
18
|
# Does not require knowing which business object / iMIS-specific field name to use
|
19
19
|
#
|
20
20
|
# Only available for previously-mapped fields
|
21
21
|
#
|
22
|
-
|
22
|
+
# `data` is a hash of shape { field_key => value }
|
23
|
+
#
|
24
|
+
def update(data)
|
25
|
+
updates = data.each_with_object({}) do |(field_key, value), hash|
|
26
|
+
map_update(field_key) do |business_object_name, field|
|
27
|
+
hash[business_object_name] ||= {}
|
28
|
+
hash[business_object_name][field] = value
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
updates.map do |business_object_name, field_updates|
|
33
|
+
api.put(business_object_name, field_updates)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def map_update(field_name)
|
23
40
|
if FIELD_MAPPING.key?(field_name.to_sym)
|
24
41
|
business_object_name, field = FIELD_MAPPING[field_name.to_sym]
|
25
|
-
|
42
|
+
yield(business_object_name, field)
|
26
43
|
else
|
44
|
+
missing_mapping(field_name)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def missing_mapping(field_name)
|
49
|
+
unless ENV['TESTING']
|
27
50
|
warn(
|
28
51
|
"Mapper does not know how to handle field \"#{field_name}\".\n\n" \
|
29
52
|
'You can use api.put(business_object_name, { field_name => value }) ' \
|
30
53
|
"if you know the business object and iMIS-specific field name.\n\n"
|
31
|
-
) unless ENV['TESTING']
|
32
|
-
|
33
|
-
raise(
|
34
|
-
Imis::Error::Mapper,
|
35
|
-
"Unrecognized field: \"#{field_name}\". " \
|
36
|
-
'Please report what data you are attempting to work with to ITCom leadership.'
|
37
54
|
)
|
38
55
|
end
|
56
|
+
|
57
|
+
raise(
|
58
|
+
Imis::Error::Mapper,
|
59
|
+
"Unrecognized field: \"#{field_name}\". " \
|
60
|
+
'Please report what data you are attempting to work with to ITCom leadership.'
|
61
|
+
)
|
39
62
|
end
|
40
63
|
end
|
41
64
|
end
|
@@ -18,4 +18,14 @@ describe Imis::Api do
|
|
18
18
|
expect(api.put('ABC_ASC_Individual_Demog', { 'TotMMS' => 15 })).to be_a(Hash)
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
describe '#with' do
|
23
|
+
it 'sends an update from put' do
|
24
|
+
expect(api.with(31092) { put('ABC_ASC_Individual_Demog', { 'TotMMS' => 15 }) }).to be_a(Hash)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'sends an update from update' do
|
28
|
+
expect(api.with(31092) { update(mm: 15) }.first).to be_a(Hash)
|
29
|
+
end
|
30
|
+
end
|
21
31
|
end
|
@@ -9,11 +9,11 @@ describe Imis::Mapper do
|
|
9
9
|
before { api.imis_id = 31092 }
|
10
10
|
|
11
11
|
it 'sends a mapped update' do
|
12
|
-
expect(api.mapper.update(:
|
12
|
+
expect(api.mapper.update(mm: 15).first).to be_a(Hash)
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'raises for unmapped updates' do
|
16
|
-
expect { api.mapper.update(:
|
16
|
+
expect { api.mapper.update(something: 'anything') }.to raise_error(
|
17
17
|
Imis::Error::Mapper,
|
18
18
|
'Unrecognized field: "something". ' \
|
19
19
|
'Please report what data you are attempting to work with to ITCom leadership.'
|
data/spec/spec_helper.rb
CHANGED
data/usps-imis-api.gemspec
CHANGED
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.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julian Fiander
|
@@ -16,6 +16,7 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
+
- ".github/workflows/main.yml"
|
19
20
|
- ".gitignore"
|
20
21
|
- ".rspec"
|
21
22
|
- ".rubocop.yml"
|
@@ -30,8 +31,8 @@ files:
|
|
30
31
|
- lib/imis/error/mapper.rb
|
31
32
|
- lib/imis/mapper.rb
|
32
33
|
- lib/usps-imis-api.rb
|
33
|
-
- spec/api_spec.rb
|
34
|
-
- spec/mapper_spec.rb
|
34
|
+
- spec/lib/imis/api_spec.rb
|
35
|
+
- spec/lib/imis/mapper_spec.rb
|
35
36
|
- spec/spec_helper.rb
|
36
37
|
- usps-imis-api.gemspec
|
37
38
|
homepage: http://rubygems.org/gems/usps-imis-api
|