usps-imis-api 0.1.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '08fbe2f408147a553ac2bf52e2a99d5919b6a26b3361c70455c3f231d099ec6f'
4
- data.tar.gz: 2e59bcf317e9f0cff940a3da5e3d84293fd24f98d7eca489f43a074bf42525be
3
+ metadata.gz: ad19ed5d60abf0531fdc10f01113fada6a5bc9413574bda31783d41507000c87
4
+ data.tar.gz: 8d0fcf7a1881cfb262a248683346489be5e28f2d57ce8a18923210780fc9e847
5
5
  SHA512:
6
- metadata.gz: d8117d16b3fa0d05e4002d0860d2ad91f282653a3b4af215bc69c67580c2dbaccc31e0b02f3a71a8bfbc136d9e76e2a64ad7c2f68a29b61511a141317ae4dc24
7
- data.tar.gz: 1dcea3e725a174d1024bbd9b042afa6706599005b1f858302ebb214723df2e2cb9f8ef705f843e226ddb00aca1a545df6665806e8dc40948c1508f2873ae37d7
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: true
70
+ Enabled: false
69
71
  Style/StringLiterals:
70
72
  EnforcedStyle: single_quotes
71
73
  Style/AndOr:
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps-imis-api (0.1.1)
4
+ usps-imis-api (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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.0'
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 'usps_imis_api'
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: ['ABC_ASC_Individual_Demog', 'Vol_Vessel_Examiner'],
7
- mm: ['ABC_ASC_Individual_Demog', 'TotMMS'],
8
- mm_updated: ['ABC_ASC_Individual_Demog', 'MMS_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
@@ -9,7 +9,7 @@ end
9
9
  # SimpleCov.minimum_coverage(100)
10
10
 
11
11
  require 'dotenv/load'
12
- require 'usps_imis_api'
12
+ require 'usps-imis-api'
13
13
 
14
14
  ENV['TESTING'] = 'true'
15
15
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'usps-imis-api'
5
- s.version = '0.1.1'
5
+ s.version = '0.1.2'
6
6
  s.summary = 'iMIS API Wrapper'
7
7
  s.description = 'A wrapper for the iMIS API.'
8
8
  s.homepage = 'http://rubygems.org/gems/usps-imis-api'
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.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