usps-imis-api 0.6.0 → 0.6.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/.rubocop.yml +0 -2
- data/Gemfile.lock +29 -1
- data/Readme.md +8 -7
- data/lib/usps/imis/business_object.rb +13 -0
- data/lib/usps/imis/config.rb +15 -9
- data/lib/usps/imis/version.rb +1 -1
- data/spec/lib/usps/imis/business_object_spec.rb +30 -20
- data/spec/lib/usps/imis/config_spec.rb +29 -3
- data/spec/spec_helper.rb +1 -0
- data/usps-imis-api.gemspec +2 -0
- metadata +16 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a7e57bee906686721fa8b760f9fa322e04b289087e9295713283a2f6fcd5d3e6
|
|
4
|
+
data.tar.gz: 6fe2a0b3405ddf20825ae24bb8986bf4e941a5fb46e37944988047faa5eb54e4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e635a0d05fb1ce0139b422be14d01de9118bc2fa7474ee63eb802c5671a793e4628eea5d320ca93c59c41807419089243e6f1bd3bbc87dbda6c1baee2f06d28c
|
|
7
|
+
data.tar.gz: a098bb43500c8db276cf03dd8b5f09954431b4a6011c6672656f061d05ca600972e70bab15ddd90877b62cedabb24f73d33575ea4ef5c6ef21d72e133f837cf7
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,17 +1,39 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
usps-imis-api (0.6.
|
|
4
|
+
usps-imis-api (0.6.2)
|
|
5
|
+
activesupport (~> 8.0)
|
|
5
6
|
|
|
6
7
|
GEM
|
|
7
8
|
remote: https://rubygems.org/
|
|
8
9
|
specs:
|
|
10
|
+
activesupport (8.0.3)
|
|
11
|
+
base64
|
|
12
|
+
benchmark (>= 0.3)
|
|
13
|
+
bigdecimal
|
|
14
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
15
|
+
connection_pool (>= 2.2.5)
|
|
16
|
+
drb
|
|
17
|
+
i18n (>= 1.6, < 2)
|
|
18
|
+
logger (>= 1.4.2)
|
|
19
|
+
minitest (>= 5.1)
|
|
20
|
+
securerandom (>= 0.3)
|
|
21
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
|
22
|
+
uri (>= 0.13.1)
|
|
9
23
|
ast (2.4.2)
|
|
24
|
+
base64 (0.3.0)
|
|
25
|
+
benchmark (0.4.1)
|
|
26
|
+
bigdecimal (3.3.1)
|
|
27
|
+
concurrent-ruby (1.3.5)
|
|
28
|
+
connection_pool (2.5.4)
|
|
10
29
|
date (3.4.1)
|
|
11
30
|
diff-lcs (1.5.1)
|
|
12
31
|
docile (1.4.1)
|
|
13
32
|
dotenv (3.1.4)
|
|
33
|
+
drb (2.2.3)
|
|
14
34
|
erb (5.0.3)
|
|
35
|
+
i18n (1.14.7)
|
|
36
|
+
concurrent-ruby (~> 1.0)
|
|
15
37
|
io-console (0.8.1)
|
|
16
38
|
irb (1.15.2)
|
|
17
39
|
pp (>= 0.6.0)
|
|
@@ -19,6 +41,8 @@ GEM
|
|
|
19
41
|
reline (>= 0.4.2)
|
|
20
42
|
json (2.7.2)
|
|
21
43
|
language_server-protocol (3.17.0.3)
|
|
44
|
+
logger (1.7.0)
|
|
45
|
+
minitest (5.26.0)
|
|
22
46
|
parallel (1.26.3)
|
|
23
47
|
parser (3.3.5.0)
|
|
24
48
|
ast (~> 2.4.1)
|
|
@@ -67,6 +91,7 @@ GEM
|
|
|
67
91
|
rubocop-rspec (3.1.0)
|
|
68
92
|
rubocop (~> 1.61)
|
|
69
93
|
ruby-progressbar (1.13.0)
|
|
94
|
+
securerandom (0.4.1)
|
|
70
95
|
simplecov (0.22.0)
|
|
71
96
|
docile (~> 1.1)
|
|
72
97
|
simplecov-html (~> 0.11)
|
|
@@ -75,7 +100,10 @@ GEM
|
|
|
75
100
|
simplecov_json_formatter (0.1.4)
|
|
76
101
|
stringio (3.1.7)
|
|
77
102
|
tsort (0.2.0)
|
|
103
|
+
tzinfo (2.0.6)
|
|
104
|
+
concurrent-ruby (~> 1.0)
|
|
78
105
|
unicode-display_width (2.6.0)
|
|
106
|
+
uri (1.0.4)
|
|
79
107
|
|
|
80
108
|
PLATFORMS
|
|
81
109
|
arm64-darwin-23
|
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', '
|
|
16
|
+
gem 'usps-imis-api', '~> 0.6.1'
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
## Setup
|
|
@@ -25,9 +25,11 @@ require 'dotenv/load' # Optionally load environment variables from `.env` file
|
|
|
25
25
|
require 'usps/imis'
|
|
26
26
|
|
|
27
27
|
Usps::Imis.configure do |config|
|
|
28
|
-
|
|
29
|
-
config.
|
|
28
|
+
# This will default to `Rails.env` if available.
|
|
29
|
+
config.environment = :development
|
|
30
30
|
|
|
31
|
+
# These options will default to the listed `ENV` variable if available.
|
|
32
|
+
config.imis_id_query_name = ENV['IMIS_ID_QUERY_NAME']
|
|
31
33
|
config.username = ENV['IMIS_USERNAME']
|
|
32
34
|
config.password = ENV['IMIS_PASSWORD']
|
|
33
35
|
end
|
|
@@ -222,10 +224,7 @@ end
|
|
|
222
224
|
|
|
223
225
|
## Exception Handling
|
|
224
226
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
To print exception information to STDERR when raising, set the environment
|
|
228
|
-
variable `IMIS_ERROR_LOG_TO_STDERR=true`.
|
|
227
|
+
All internal exceptions inherit from `Usps::Imis::ApiError`.
|
|
229
228
|
|
|
230
229
|
## Automated Testing and Linting
|
|
231
230
|
|
|
@@ -241,6 +240,8 @@ Linting is available by running:
|
|
|
241
240
|
bundle exec rubocop
|
|
242
241
|
```
|
|
243
242
|
|
|
243
|
+
100% branch coverage is enforced on the test suite.
|
|
244
|
+
|
|
244
245
|
### GitHub Actions
|
|
245
246
|
|
|
246
247
|
Testing and linting are automatically run on every push.
|
|
@@ -40,6 +40,19 @@ module Usps
|
|
|
40
40
|
JSON.parse(result.body)
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
+
# Get a single named field from a business object for the current member
|
|
44
|
+
#
|
|
45
|
+
# @param name [String] Field name to return
|
|
46
|
+
#
|
|
47
|
+
# @return [Hash] Response data from the API
|
|
48
|
+
#
|
|
49
|
+
def get_field(name)
|
|
50
|
+
values = get['Properties']['$values']
|
|
51
|
+
value = values.find { |hash| hash['Name'] == name }['Value']
|
|
52
|
+
|
|
53
|
+
value.is_a?(String) ? value : value['$value']
|
|
54
|
+
end
|
|
55
|
+
|
|
43
56
|
# Update only specific fields on a business object for the current member
|
|
44
57
|
#
|
|
45
58
|
# @param fields [Hash] Conforms to pattern +{ field_key => value }+
|
data/lib/usps/imis/config.rb
CHANGED
|
@@ -8,25 +8,31 @@ module Usps
|
|
|
8
8
|
IMIS_ROOT_URL_PROD = 'https://portal.americasboatingclub.org'
|
|
9
9
|
IMIS_ROOT_URL_DEV = 'https://abcdev.imiscloud.com'
|
|
10
10
|
|
|
11
|
-
attr_accessor :
|
|
11
|
+
attr_accessor :imis_id_query_name, :username, :password
|
|
12
|
+
attr_reader :environment
|
|
12
13
|
|
|
13
14
|
def initialize
|
|
15
|
+
@environment = defined?(Rails) ? Rails.env : ActiveSupport::StringInquirer.new('development')
|
|
16
|
+
@imis_id_query_name = ENV.fetch('IMIS_ID_QUERY_NAME', nil)
|
|
17
|
+
@username = ENV.fetch('IMIS_USERNAME', nil)
|
|
18
|
+
@password = ENV.fetch('IMIS_PASSWORD', nil)
|
|
19
|
+
|
|
14
20
|
yield self if block_given?
|
|
15
21
|
end
|
|
16
22
|
|
|
23
|
+
def environment=(env)
|
|
24
|
+
@environment = ActiveSupport::StringInquirer.new(env.to_s)
|
|
25
|
+
end
|
|
26
|
+
|
|
17
27
|
# Environment-specific API endpoint hostname
|
|
18
28
|
#
|
|
19
29
|
# @return The API hostname for the current environment
|
|
20
30
|
#
|
|
21
31
|
def hostname
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
IMIS_ROOT_URL_DEV
|
|
27
|
-
else
|
|
28
|
-
raise Error::ApiError, "Unexpected API environment: #{environment}"
|
|
29
|
-
end
|
|
32
|
+
return IMIS_ROOT_URL_PROD if environment.production?
|
|
33
|
+
return IMIS_ROOT_URL_DEV if environment.development?
|
|
34
|
+
|
|
35
|
+
raise Error::ApiError, "Unexpected API environment: #{environment}"
|
|
30
36
|
end
|
|
31
37
|
|
|
32
38
|
# Ruby 3.5 instance variable filter
|
data/lib/usps/imis/version.rb
CHANGED
|
@@ -6,31 +6,41 @@ describe Usps::Imis::BusinessObject do
|
|
|
6
6
|
let(:business_object) { described_class.new(api, 'Stub') }
|
|
7
7
|
let(:api) { Usps::Imis::Api.new }
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
{
|
|
12
|
-
'
|
|
13
|
-
'$
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
let(:expected) do
|
|
10
|
+
{
|
|
11
|
+
'Properties' => {
|
|
12
|
+
'$values' => [
|
|
13
|
+
{ 'Name' => 'Stub iMIS ID', 'Value' => { '$value' => '31092' } },
|
|
14
|
+
{ 'Name' => 'Stub Integer', 'Value' => { '$value' => 43 } },
|
|
15
|
+
{ 'Name' => 'Stub String', 'Value' => 'other' }
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
before do
|
|
22
|
+
allow(business_object).to receive(:get).and_return({
|
|
23
|
+
'Properties' => {
|
|
24
|
+
'$values' => [
|
|
25
|
+
{ 'Name' => 'Stub iMIS ID', 'Value' => { '$value' => '31092' } },
|
|
26
|
+
{ 'Name' => 'Stub Integer', 'Value' => { '$value' => 42 } },
|
|
27
|
+
{ 'Name' => 'Stub String', 'Value' => 'something' }
|
|
28
|
+
]
|
|
19
29
|
}
|
|
30
|
+
})
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe '#get_field' do
|
|
34
|
+
it 'returns a string value' do
|
|
35
|
+
expect(business_object.get_field('Stub String')).to eq('something')
|
|
20
36
|
end
|
|
21
37
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
'Properties' => {
|
|
25
|
-
'$values' => [
|
|
26
|
-
{ 'Name' => 'Stub iMIS ID', 'Value' => { '$value' => '31092' } },
|
|
27
|
-
{ 'Name' => 'Stub Integer', 'Value' => { '$value' => 42 } },
|
|
28
|
-
{ 'Name' => 'Stub String', 'Value' => 'something' }
|
|
29
|
-
]
|
|
30
|
-
}
|
|
31
|
-
})
|
|
38
|
+
it 'returns an integer value' do
|
|
39
|
+
expect(business_object.get_field('Stub Integer')).to eq(42)
|
|
32
40
|
end
|
|
41
|
+
end
|
|
33
42
|
|
|
43
|
+
describe '#filter_fields' do
|
|
34
44
|
it 'formats fields correctly' do
|
|
35
45
|
updated = business_object.send(:filter_fields, 'Stub Integer' => 43, 'Stub String' => 'other')
|
|
36
46
|
|
|
@@ -5,10 +5,36 @@ require 'spec_helper'
|
|
|
5
5
|
describe Usps::Imis::Config do
|
|
6
6
|
let(:config) { described_class.new }
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
describe 'environment' do
|
|
9
|
+
subject { config.environment }
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
let(:config) { described_class.new }
|
|
12
|
+
|
|
13
|
+
context 'when not specified' do
|
|
14
|
+
it { is_expected.to be_development }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
context 'when specified' do
|
|
18
|
+
before { config.environment = 'something' }
|
|
19
|
+
|
|
20
|
+
it { is_expected.to be_something }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
context 'when specified on initialize' do
|
|
24
|
+
subject { config.environment }
|
|
25
|
+
|
|
26
|
+
let(:config) do
|
|
27
|
+
described_class.new { |c| c.environment = 'test' }
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it { is_expected.to be_test }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
context 'when in Rails' do
|
|
34
|
+
before { stub_const('Rails', Struct.new(:env).new(ActiveSupport::StringInquirer.new('qa'))) }
|
|
35
|
+
|
|
36
|
+
it { is_expected.to be_qa }
|
|
37
|
+
end
|
|
12
38
|
end
|
|
13
39
|
|
|
14
40
|
describe '#hostname' do
|
data/spec/spec_helper.rb
CHANGED
data/usps-imis-api.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: usps-imis-api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.
|
|
4
|
+
version: 0.6.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Julian Fiander
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
-
dependencies:
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: activesupport
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '8.0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '8.0'
|
|
12
26
|
description: A wrapper for the iMIS API.
|
|
13
27
|
email: jsfiander@gmail.com
|
|
14
28
|
executables: []
|