usps-imis-api 1.0.0.pre.rc.4 → 1.0.0.pre.rc.5

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: bb187f7e4a8497da991378eec6a9893c5c2a5e637b808a9225ab72ebd5ee385d
4
- data.tar.gz: 0d09118f25fce28b94ddbc1257e9670fe3454e34df094885bc9cf35cbb1a86a0
3
+ metadata.gz: 1c0abf715f3c6019016bc6b8bdf867ce9d83234ba093c6150a4885997e9156f4
4
+ data.tar.gz: bcd2727e5f74b7a8681ae8ea1c510539fc24b62085719b439a01a331989a59c9
5
5
  SHA512:
6
- metadata.gz: f50698bc529a6d66d3c69e201d696cdfde1f24c7bf414ab1f655ebdf3b21e1bd512b8e00476ffa62e3ded1a50d72e82586b8f11c002291c5a8038ad5f4cdd2d6
7
- data.tar.gz: '09e2849e666c312d0a974efc14b5133ac6e2f0ef181a6715f83ae420b6ba48f6a1566cc749a1dcbce614989c9e5b9fa343ba4dd6a56f1ecd47a9a14b7572617a'
6
+ metadata.gz: e0f98c36fd93ae643a949980e590fbb327cc40e1947ef5c8b530156e3961073082702dd38916fa27da4db10c642316c3c3db9f97d82d2f7c616032917cea22f1
7
+ data.tar.gz: 3195ecb427cff0fea1c6d1cef0d877507c2bb7baaa3a3db6d669f281048a03de7fb06c15e3b5f1cfe36625ece30d2e890f05202accfaf56148de40dda0fdce4d
data/.rubocop.yml CHANGED
@@ -32,8 +32,6 @@ Layout/SpaceInsideHashLiteralBraces:
32
32
  EnforcedStyleForEmptyBraces: no_space
33
33
  Layout/SpaceInsideArrayLiteralBrackets:
34
34
  EnforcedStyle: no_space
35
- Layout/LineLength:
36
- Max: 100
37
35
 
38
36
  Lint/UnusedMethodArgument:
39
37
  Enabled: true
data/Gemfile.lock CHANGED
@@ -1,17 +1,39 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps-imis-api (1.0.0.pre.rc.4)
4
+ usps-imis-api (1.0.0.pre.rc.5)
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', '>= 0.6.0'
16
+ gem 'usps-imis-api', '~> 0.6.3'
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
- config.environment = :development # Rails.env
29
- config.imis_id_query_name = ENV['IMIS_ID_QUERY_NAME']
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
@@ -85,6 +87,16 @@ api.imis_id = 31092
85
87
  data = api.on('ABC_ASC_Individual_Demog').get
86
88
  ```
87
89
 
90
+ ### GET Field
91
+
92
+ To fetch a specific field from member data, run e.g.:
93
+
94
+ ```ruby
95
+ api.imis_id = 31092
96
+
97
+ tot_mms = api.on('ABC_ASC_Individual_Demog').get_field('TotMMS')
98
+ ```
99
+
88
100
  ### PUT Fields
89
101
 
90
102
  To update member data, run e.g.:
@@ -202,7 +214,7 @@ previous value.
202
214
 
203
215
  ```ruby
204
216
  api.with(31092) do
205
- # These four requests are identical:
217
+ # These requests are identical:
206
218
 
207
219
  on('ABC_ASC_Individual_Demog') { put('TotMMS' => 15) }
208
220
 
@@ -220,12 +232,26 @@ api.with(6374) do
220
232
  end
221
233
  ```
222
234
 
223
- ## Exception Handling
235
+ ```ruby
236
+ api.with(31092) do
237
+ # These requests are identical:
238
+
239
+ on('ABC_ASC_Individual_Demog') do
240
+ get['Properties']['$values'].find { |hash| hash['Name'] == 'TotMMS' }['Value']['$value']
241
+ end
242
+
243
+ on('ABC_ASC_Individual_Demog') { get_field('TotMMS') }
244
+
245
+ on('ABC_ASC_Individual_Demog').get_field('TotMMS')
246
+ end
224
247
 
225
- Exception and error response handling will be added later.
248
+ # This request fetches the same data, but leaves the iMIS ID selected
249
+ api.with(31092).on('ABC_ASC_Individual_Demog').get_field('TotMMS')
250
+ ```
226
251
 
227
- To print exception information to STDERR when raising, set the environment
228
- variable `IMIS_ERROR_LOG_TO_STDERR=true`.
252
+ ## Exception Handling
253
+
254
+ All internal exceptions inherit from `Usps::Imis::ApiError`.
229
255
 
230
256
  ## Automated Testing and Linting
231
257
 
@@ -241,6 +267,8 @@ Linting is available by running:
241
267
  bundle exec rubocop
242
268
  ```
243
269
 
270
+ 100% branch coverage is enforced on the test suite.
271
+
244
272
  ### GitHub Actions
245
273
 
246
274
  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 }+
@@ -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 :environment, :imis_id_query_name, :username, :password
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
- case environment.to_sym
23
- when :production
24
- IMIS_ROOT_URL_PROD
25
- when :development
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
@@ -59,6 +59,42 @@ module Usps
59
59
  def payload(_data)
60
60
  raise Error::ApiError, "#{self.class.name} must implement #payload(data)"
61
61
  end
62
+
63
+ def payload_header(data)
64
+ {
65
+ '$type' => 'Asi.Soa.Core.DataContracts.GenericEntityData, Asi.Contracts',
66
+ 'EntityTypeName' => business_object,
67
+ 'PrimaryParentEntityTypeName' => 'Party',
68
+ 'Identity' => identity(data[:ordinal]),
69
+ 'PrimaryParentIdentity' => primary_parent_identity
70
+ }
71
+ end
72
+
73
+ def identity(ordinal = nil)
74
+ {
75
+ '$type' => 'Asi.Soa.Core.DataContracts.IdentityData, Asi.Contracts',
76
+ 'EntityTypeName' => business_object,
77
+ 'IdentityElements' => {
78
+ '$type' => identity_type,
79
+ '$values' => [api.imis_id, ordinal&.to_s].compact
80
+ }
81
+ }
82
+ end
83
+
84
+ def primary_parent_identity
85
+ {
86
+ '$type' => 'Asi.Soa.Core.DataContracts.IdentityData, Asi.Contracts',
87
+ 'EntityTypeName' => 'Party',
88
+ 'IdentityElements' => {
89
+ '$type' => identity_type,
90
+ '$values' => [api.imis_id]
91
+ }
92
+ }
93
+ end
94
+
95
+ def identity_type = 'System.Collections.ObjectModel.Collection`1[[System.String, mscorlib]], mscorlib'
96
+
97
+ def build_payload(data, &) = payload_header(data).merge(PanelProperties.build(&))
62
98
  end
63
99
  end
64
100
  end
@@ -12,101 +12,21 @@ module Usps
12
12
  'ABC_ASC_Educ'
13
13
  end
14
14
 
15
- # rubocop:disable Metrics/MethodLength
16
15
  def payload(data)
17
- identity_type =
18
- 'System.Collections.ObjectModel.Collection`1[[System.String, mscorlib]], mscorlib'
19
-
20
- {
21
- '$type' => 'Asi.Soa.Core.DataContracts.GenericEntityData, Asi.Contracts',
22
- 'EntityTypeName' => 'ABC_ASC_EDUC',
23
- 'PrimaryParentEntityTypeName' => 'Party',
24
- 'Identity' => {
25
- '$type' => 'Asi.Soa.Core.DataContracts.IdentityData, Asi.Contracts',
26
- 'EntityTypeName' => 'ABC_ASC_EDUC',
27
- 'IdentityElements' => {
28
- '$type' => identity_type,
29
- '$values' => [api.imis_id, data[:ordinal]&.to_s].compact
30
- }
31
- },
32
- 'PrimaryParentIdentity' => {
33
- '$type' => 'Asi.Soa.Core.DataContracts.IdentityData, Asi.Contracts',
34
- 'EntityTypeName' => 'Party',
35
- 'IdentityElements' => {
36
- '$type' => identity_type,
37
- '$values' => [api.imis_id]
38
- }
39
- },
40
- 'Properties' => {
41
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyDataCollection, Asi.Contracts',
42
- '$values' => [
43
- {
44
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
45
- 'Name' => 'ID',
46
- 'Value' => api.imis_id
47
- },
48
- (
49
- if data[:ordinal]
50
- {
51
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
52
- 'Name' => 'Ordinal',
53
- 'Value' => {
54
- '$type' => 'System.Int32',
55
- '$value' => data[:ordinal]
56
- }
57
- }
58
- end
59
- ),
60
- {
61
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
62
- 'Name' => 'ABC_EDUC_THRU_DATE',
63
- 'Value' => data[:thru_date] || '0001-01-01T00:00:00'
64
- },
65
- {
66
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
67
- 'Name' => 'ABC_ECertificate',
68
- 'Value' => data[:certificate]
69
- },
70
- {
71
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
72
- 'Name' => 'ABC_Educ_Description',
73
- 'Value' => data[:description]
74
- },
75
- {
76
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
77
- 'Name' => 'ABC_Educ_Effective_Date',
78
- 'Value' => data[:effective_date]
79
- },
80
- {
81
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
82
- 'Name' => 'ABC_Educ_Source_System',
83
- 'Value' => data[:source]
84
- },
85
- {
86
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
87
- 'Name' => 'ABC_Educ_Transaction_Date',
88
- 'Value' => Time.now.strftime('%Y-%m-%dT%H:%I:%S')
89
- },
90
- {
91
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
92
- 'Name' => 'ABC_Other_Code',
93
- 'Value' => data[:code]
94
- },
95
- {
96
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
97
- 'Name' => 'ABC_Product_Code',
98
- 'Value' => data[:type_code]
99
- },
100
- {
101
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
102
- 'Name' => 'ABC_TYPE',
103
- 'Value' => data[:abc_type_code] || 'EDUC'
104
- }
105
- ].compact
106
- }
107
- }
16
+ build_payload(data) do |props|
17
+ props.add 'ID', api.imis_id
18
+ props.add 'Ordinal', data[:ordinal] if data[:ordinal]
19
+ props.add 'ABC_EDUC_THRU_DATE', data[:thru_date] || '0001-01-01T00:00:00'
20
+ props.add 'ABC_ECertificate', data[:certificate]
21
+ props.add 'ABC_Educ_Description', data[:description]
22
+ props.add 'ABC_Educ_Effective_Date', data[:effective_date]
23
+ props.add 'ABC_Educ_Source_System', data[:source]
24
+ props.add 'ABC_Educ_Transaction_Date', Time.now
25
+ props.add 'ABC_Other_Code', data[:code]
26
+ props.add 'ABC_Product_Code', data[:type_code]
27
+ props.add 'ABC_TYPE', data[:abc_type_code] || 'EDUC'
28
+ end
108
29
  end
109
- # rubocop:enable Metrics/MethodLength
110
30
  end
111
31
  end
112
32
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Usps
4
+ module Imis
5
+ module Panel
6
+ # Constructor for the Properties field for Panel requests
7
+ #
8
+ class PanelProperties
9
+ # Build a new Properties field
10
+ #
11
+ def self.build(&) = new.build(&)
12
+
13
+ # Build the Properties field
14
+ #
15
+ def build
16
+ yield(self)
17
+
18
+ {
19
+ 'Properties' => {
20
+ '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyDataCollection, Asi.Contracts',
21
+ '$values' => @properties
22
+ }
23
+ }
24
+ end
25
+
26
+ # Add an individual property to the field
27
+ #
28
+ def add(name, value)
29
+ @properties ||= []
30
+ @properties << {
31
+ '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
32
+ 'Name' => name,
33
+ 'Value' => property_value(value)
34
+ }
35
+ end
36
+
37
+ private
38
+
39
+ def property_value(value)
40
+ case value
41
+ when String then value
42
+ when Time, DateTime then value.strftime('%Y-%m-%dT%H:%I:%S')
43
+ when Integer then { '$type' => 'System.Int32', '$value' => value }
44
+ when true, false then { '$type' => 'System.Boolean', '$value' => value }
45
+ else
46
+ raise Error::ApiError, "Unexpected property type: #{value.inspect}"
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -12,99 +12,20 @@ module Usps
12
12
  'ABC_ASC_Vessel_Safety_Checks'
13
13
  end
14
14
 
15
- # rubocop:disable Metrics/MethodLength
16
15
  def payload(data)
17
- identity_type =
18
- 'System.Collections.ObjectModel.Collection`1[[System.String, mscorlib]], mscorlib'
19
-
20
- {
21
- '$type' => 'Asi.Soa.Core.DataContracts.GenericEntityData, Asi.Contracts',
22
- 'EntityTypeName' => 'ABC_ASC_Vessel_Safety_Checks',
23
- 'PrimaryParentEntityTypeName' => 'Party',
24
- 'Identity' => {
25
- '$type' => 'Asi.Soa.Core.DataContracts.IdentityData, Asi.Contracts',
26
- 'EntityTypeName' => 'ABC_ASC_Vessel_Safety_Checks',
27
- 'IdentityElements' => {
28
- '$type' => identity_type,
29
- '$values' => [api.imis_id, data[:ordinal]&.to_s].compact
30
- }
31
- },
32
- 'PrimaryParentIdentity' => {
33
- '$type' => 'Asi.Soa.Core.DataContracts.IdentityData, Asi.Contracts',
34
- 'EntityTypeName' => 'Party',
35
- 'IdentityElements' => {
36
- '$type' => identity_type,
37
- '$values' => [api.imis_id]
38
- }
39
- },
40
- 'Properties' => {
41
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyDataCollection, Asi.Contracts',
42
- '$values' => [
43
- {
44
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
45
- 'Name' => 'ID',
46
- 'Value' => api.imis_id
47
- },
48
- (
49
- if data[:ordinal]
50
- {
51
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
52
- 'Name' => 'Ordinal',
53
- 'Value' => {
54
- '$type' => 'System.Int32',
55
- '$value' => data[:ordinal]
56
- }
57
- }
58
- end
59
- ),
60
- {
61
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
62
- 'Name' => 'Source_System',
63
- 'Value' => 'Manual ITCom Entry'
64
- },
65
- {
66
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
67
- 'Name' => 'ABC_ECertificate',
68
- 'Value' => data[:certificate]
69
- },
70
- {
71
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
72
- 'Name' => 'Activity_Type',
73
- 'Value' => 'VSC'
74
- },
75
- {
76
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
77
- 'Name' => 'Description',
78
- 'Value' => 'Vessel Safety Checks'
79
- },
80
- {
81
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
82
- 'Name' => 'Effective_Date',
83
- 'Value' => "#{data[:year]}-12-01T00:00:00"
84
- },
85
- {
86
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
87
- 'Name' => 'Quantity',
88
- 'Value' => {
89
- '$type' => 'System.Int32',
90
- '$value' => data[:count]
91
- }
92
- },
93
- {
94
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
95
- 'Name' => 'Thru_Date',
96
- 'Value' => "#{data[:year]}-12-31T00:00:00"
97
- },
98
- {
99
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
100
- 'Name' => 'Transaction_Date',
101
- 'Value' => Time.now.strftime('%Y-%m-%dT%H:%M:%S')
102
- }
103
- ].compact
104
- }
105
- }
16
+ build_payload(data) do |props|
17
+ props.add 'ID', api.imis_id
18
+ props.add 'Ordinal', data[:ordinal] if data[:ordinal]
19
+ props.add 'Source_System', 'Manual ITCom Entry'
20
+ props.add 'ABC_ECertificate', data[:certificate]
21
+ props.add 'Activity_Type', 'VSC'
22
+ props.add 'Description', 'Vessel Safety Checks'
23
+ props.add 'Effective_Date', "#{data[:year]}-12-01T00:00:00"
24
+ props.add 'Quantity', data[:count]
25
+ props.add 'Thru_Date', "#{data[:year]}-12-31T00:00:00"
26
+ props.add 'Transaction_Date', Time.now
27
+ end
106
28
  end
107
- # rubocop:enable Metrics/MethodLength
108
29
  end
109
30
  end
110
31
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Usps
4
4
  module Imis
5
+ # @private
6
+ #
5
7
  module Requests
6
8
  private
7
9
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Imis
5
- VERSION = '1.0.0-rc.4'
5
+ VERSION = '1.0.0-rc.5'
6
6
  end
7
7
  end
data/lib/usps/imis.rb CHANGED
@@ -6,6 +6,8 @@ require 'json'
6
6
  require 'time'
7
7
  require 'cgi'
8
8
 
9
+ require 'active_support/string_inquirer'
10
+
9
11
  # Extensions
10
12
  # :nocov:
11
13
  require 'ext/hash' unless defined?(Rails)
@@ -21,6 +23,7 @@ require_relative 'imis/business_object'
21
23
  require_relative 'imis/api'
22
24
  require_relative 'imis/mapper'
23
25
  require_relative 'imis/panel/base_panel'
26
+ require_relative 'imis/panel/panel_properties'
24
27
  require_relative 'imis/panel/vsc'
25
28
  require_relative 'imis/panel/education'
26
29
 
@@ -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
- describe '#filter_fields' do
10
- let(:expected) do
11
- {
12
- 'Properties' => {
13
- '$values' => [
14
- { 'Name' => 'Stub iMIS ID', 'Value' => { '$value' => '31092' } },
15
- { 'Name' => 'Stub Integer', 'Value' => { '$value' => 43 } },
16
- { 'Name' => 'Stub String', 'Value' => 'other' }
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
- before do
23
- allow(business_object).to receive(:get).and_return({
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
- it 'sets values on initialize' do
9
- config = described_class.new { |c| c.environment = 'test' }
8
+ describe 'environment' do
9
+ subject { config.environment }
10
10
 
11
- expect(config.environment).to eq('test')
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
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Usps::Imis::Panel::PanelProperties do
6
+ let(:builder) { described_class.new }
7
+
8
+ it 'handles boolean property values' do
9
+ expect(builder.send(:property_value, true)).to eq(
10
+ '$type' => 'System.Boolean', '$value' => true
11
+ )
12
+ end
13
+
14
+ it 'raises an error for unexpected property types' do
15
+ expect { builder.send(:property_value, {}) }.to raise_error(
16
+ Usps::Imis::Error::ApiError, 'Unexpected property type: {}'
17
+ )
18
+ end
19
+ end
data/spec/spec_helper.rb CHANGED
@@ -7,6 +7,7 @@ SimpleCov.minimum_coverage(line: 100, branch: 100)
7
7
 
8
8
  require 'dotenv/load'
9
9
  require 'usps/imis'
10
+ require 'active_support/string_inquirer'
10
11
 
11
12
  ENV['TESTING'] = 'true'
12
13
 
@@ -15,4 +15,6 @@ Gem::Specification.new do |s|
15
15
  s.metadata['rubygems_mfa_required'] = 'true'
16
16
 
17
17
  s.required_ruby_version = '>= 3.4'
18
+
19
+ s.add_dependency 'activesupport', '~> 8.0'
18
20
  end
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: 1.0.0.pre.rc.4
4
+ version: 1.0.0.pre.rc.5
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: []
@@ -38,6 +52,7 @@ files:
38
52
  - lib/usps/imis/mapper.rb
39
53
  - lib/usps/imis/panel/base_panel.rb
40
54
  - lib/usps/imis/panel/education.rb
55
+ - lib/usps/imis/panel/panel_properties.rb
41
56
  - lib/usps/imis/panel/vsc.rb
42
57
  - lib/usps/imis/requests.rb
43
58
  - lib/usps/imis/version.rb
@@ -49,6 +64,7 @@ files:
49
64
  - spec/lib/usps/imis/mapper_spec.rb
50
65
  - spec/lib/usps/imis/panel/base_panel_spec.rb
51
66
  - spec/lib/usps/imis/panel/education_spec.rb
67
+ - spec/lib/usps/imis/panel/panel_properties_spec.rb
52
68
  - spec/lib/usps/imis/panel/vsc_spec.rb
53
69
  - spec/lib/usps/imis_spec.rb
54
70
  - spec/spec_helper.rb