usps-imis-api 0.1.1.pre.2 → 0.1.2
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 +20 -2
- data/lib/imis/api.rb +12 -0
- data/lib/imis/mapper.rb +17 -9
- data/spec/{api_spec.rb → lib/imis/api_spec.rb} +6 -0
- data/spec/spec_helper.rb +1 -1
- data/usps-imis-api.gemspec +1 -1
- metadata +4 -3
- /data/spec/{mapper_spec.rb → lib/imis/mapper_spec.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad19ed5d60abf0531fdc10f01113fada6a5bc9413574bda31783d41507000c87
|
4
|
+
data.tar.gz: 8d0fcf7a1881cfb262a248683346489be5e28f2d57ce8a18923210780fc9e847
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8abd5d2a143699aa7f184def0c97358bbc475c2248a1f56c5f5104ff9b9e08f917dd1f285637109ed3e0026c91e049661bf77a73f40bc56082a1d286d180951b
|
7
|
+
data.tar.gz: 823f16f923c71f7f0822a0d48fbe84152ea0221a96ded092570ee5554242acf9b619688625708bd9af89117f3d081c26125c02b5b879378e971072c4770cac08
|
@@ -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
|
@@ -136,6 +136,20 @@ If there is no known mapping for the requested field, the Mapper will give up, b
|
|
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)
|
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
|
@@ -24,18 +24,26 @@ module Imis
|
|
24
24
|
business_object_name, field = FIELD_MAPPING[field_name.to_sym]
|
25
25
|
api.put(business_object_name, { field => value })
|
26
26
|
else
|
27
|
+
missing_mapping(field_name)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def missing_mapping(field_name)
|
34
|
+
unless ENV['TESTING']
|
27
35
|
warn(
|
28
36
|
"Mapper does not know how to handle field \"#{field_name}\".\n\n" \
|
29
37
|
'You can use api.put(business_object_name, { field_name => value }) ' \
|
30
38
|
"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
39
|
)
|
38
40
|
end
|
41
|
+
|
42
|
+
raise(
|
43
|
+
Imis::Error::Mapper,
|
44
|
+
"Unrecognized field: \"#{field_name}\". " \
|
45
|
+
'Please report what data you are attempting to work with to ITCom leadership.'
|
46
|
+
)
|
39
47
|
end
|
40
48
|
end
|
41
49
|
end
|
@@ -18,4 +18,10 @@ 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' do
|
24
|
+
expect(api.with(31092) { put('ABC_ASC_Individual_Demog', { 'TotMMS' => 15 }) }).to be_a(Hash)
|
25
|
+
end
|
26
|
+
end
|
21
27
|
end
|
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.2
|
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
|
File without changes
|