usps-imis-api 0.6.6 → 0.6.8

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: ac6724a275018ca6e957f9342236882dde2232e1c6e9cf8f0f11e962e2ae5bb7
4
- data.tar.gz: 196dc78c0f36f2921e79aba9cfd6157818932f62751475817f0b054cd2decc8d
3
+ metadata.gz: 81e2ba39cba54049cb049ddaa01817fe51e0e1212768359b0a0d5151b7de23f6
4
+ data.tar.gz: fcd351bc3eb4ed7325ebb35a74e9609e1437c5c63219ae679a5da036a71c496d
5
5
  SHA512:
6
- metadata.gz: 6ef1c062d0d887efcb0d9c0884e43df859d992f65546b16de6d359545c6f0fa92bc0d6d533c6dbca212e5fbdd47b1e3d1cd23e7a91b4af304ed4e95199e8cdb1
7
- data.tar.gz: 1fe0de2b0c8f722afa9159779973ef9491f007dad2667cd18f2e863128d69c487f7a09801fba1c9bb0c0710c002e84396064d0a3a98c725f43b4d75f006ca907
6
+ metadata.gz: 1678dd35cf80cf95741ced1140eb208358f1ccf4ae2ec2da8af5e518feacba53acbf27c3e3afa61d26265bc1f459eb77c7c55b67ad0afefa1f19b35f0f1a314f
7
+ data.tar.gz: 4498ecff60bc76446b2e053e9908cadbe2f9a1f095eda8d4d1bcdfca916d9bc2a113d2ee4740faff730547426527ad965ef8e1a44e21fcfe1d0fb1dd975f7798
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps-imis-api (0.6.6)
4
+ usps-imis-api (0.6.8)
5
5
  activesupport (~> 8.0)
6
6
 
7
7
  GEM
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.3'
16
+ gem 'usps-imis-api'
17
17
  ```
18
18
 
19
19
  ## Setup
@@ -92,45 +92,9 @@ module Usps
92
92
  }
93
93
  end
94
94
 
95
- def identity_type
96
- 'System.Collections.ObjectModel.Collection`1[[System.String, mscorlib]], mscorlib'
97
- end
98
-
99
- def properties(data, &)
100
- @properties = []
101
-
102
- instance_eval(&)
103
-
104
- payload_header(data).merge(
105
- 'Properties' => {
106
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyDataCollection, Asi.Contracts',
107
- '$values' => @properties
108
- }
109
- )
110
- ensure
111
- remove_instance_variable(:@properties)
112
- end
95
+ def identity_type = 'System.Collections.ObjectModel.Collection`1[[System.String, mscorlib]], mscorlib'
113
96
 
114
- def property(name, value)
115
- raise Error::ApiError, 'Must be called within a `properties` block' unless defined?(@properties)
116
-
117
- @properties << {
118
- '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
119
- 'Name' => name,
120
- 'Value' => property_value(value)
121
- }
122
- end
123
-
124
- def property_value(value)
125
- case value
126
- when String then value
127
- when Time, DateTime then value.strftime('%Y-%m-%dT%H:%I:%S')
128
- when Integer then { '$type' => 'System.Int32', '$value' => value }
129
- when true, false then { '$type' => 'System.Boolean', '$value' => value }
130
- else
131
- raise Error::ApiError, "Unexpected property type: #{value.inspect}"
132
- end
133
- end
97
+ def build_payload(data, &) = payload_header(data).merge(Properties.build(&))
134
98
  end
135
99
  end
136
100
  end
@@ -13,18 +13,18 @@ module Usps
13
13
  end
14
14
 
15
15
  def payload(data)
16
- properties(data) do
17
- property 'ID', api.imis_id
18
- property 'Ordinal', data[:ordinal] if data[:ordinal]
19
- property 'ABC_EDUC_THRU_DATE', data[:thru_date] || '0001-01-01T00:00:00'
20
- property 'ABC_ECertificate', data[:certificate]
21
- property 'ABC_Educ_Description', data[:description]
22
- property 'ABC_Educ_Effective_Date', data[:effective_date]
23
- property 'ABC_Educ_Source_System', data[:source]
24
- property 'ABC_Educ_Transaction_Date', Time.now
25
- property 'ABC_Other_Code', data[:code]
26
- property 'ABC_Product_Code', data[:type_code]
27
- property 'ABC_TYPE', data[:abc_type_code] || 'EDUC'
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
28
  end
29
29
  end
30
30
  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 Properties
9
+ # Build the data for a new Properties field
10
+ #
11
+ def self.build(&) = new.build(&)
12
+
13
+ # Build the data for 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' => wrap(value)
34
+ }
35
+ end
36
+
37
+ private
38
+
39
+ def wrap(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
@@ -13,17 +13,17 @@ module Usps
13
13
  end
14
14
 
15
15
  def payload(data)
16
- properties(data) do
17
- property 'ID', api.imis_id
18
- property 'Ordinal', data[:ordinal] if data[:ordinal]
19
- property 'Source_System', 'Manual ITCom Entry'
20
- property 'ABC_ECertificate', data[:certificate]
21
- property 'Activity_Type', 'VSC'
22
- property 'Description', 'Vessel Safety Checks'
23
- property 'Effective_Date', "#{data[:year]}-12-01T00:00:00"
24
- property 'Quantity', data[:count]
25
- property 'Thru_Date', "#{data[:year]}-12-31T00:00:00"
26
- property 'Transaction_Date', Time.now
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
27
  end
28
28
  end
29
29
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Imis
5
- VERSION = '0.6.6'
5
+ VERSION = '0.6.8'
6
6
  end
7
7
  end
data/lib/usps/imis.rb CHANGED
@@ -23,6 +23,7 @@ require_relative 'imis/business_object'
23
23
  require_relative 'imis/api'
24
24
  require_relative 'imis/mapper'
25
25
  require_relative 'imis/panel/base_panel'
26
+ require_relative 'imis/panel/properties'
26
27
  require_relative 'imis/panel/vsc'
27
28
  require_relative 'imis/panel/education'
28
29
 
@@ -29,22 +29,4 @@ describe Usps::Imis::Panel::BasePanel do
29
29
  'Usps::Imis::Panel::InvalidPanelWithBusinessObject must implement #payload(data)'
30
30
  )
31
31
  end
32
-
33
- it 'does not allow calling property outside of a properties block' do
34
- expect { described_class.new.send(:property, 'name', 'value') }.to raise_error(
35
- Usps::Imis::Error::ApiError, 'Must be called within a `properties` block'
36
- )
37
- end
38
-
39
- it 'handles boolean property values' do
40
- expect(described_class.new.send(:property_value, true)).to eq(
41
- '$type' => 'System.Boolean', '$value' => true
42
- )
43
- end
44
-
45
- it 'raises an error for unexpected property types' do
46
- expect { described_class.new.send(:property_value, {}) }.to raise_error(
47
- Usps::Imis::Error::ApiError, 'Unexpected property type: {}'
48
- )
49
- end
50
32
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Usps::Imis::Panel::Properties do
6
+ let(:builder) { described_class.new }
7
+
8
+ it 'wraps boolean property values' do
9
+ expect(builder.send(:wrap, 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(:wrap, {}) }.to raise_error(
16
+ Usps::Imis::Error::ApiError, 'Unexpected property type: {}'
17
+ )
18
+ end
19
+ end
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.6.6
4
+ version: 0.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
@@ -52,6 +52,7 @@ files:
52
52
  - lib/usps/imis/mapper.rb
53
53
  - lib/usps/imis/panel/base_panel.rb
54
54
  - lib/usps/imis/panel/education.rb
55
+ - lib/usps/imis/panel/properties.rb
55
56
  - lib/usps/imis/panel/vsc.rb
56
57
  - lib/usps/imis/requests.rb
57
58
  - lib/usps/imis/version.rb
@@ -63,6 +64,7 @@ files:
63
64
  - spec/lib/usps/imis/mapper_spec.rb
64
65
  - spec/lib/usps/imis/panel/base_panel_spec.rb
65
66
  - spec/lib/usps/imis/panel/education_spec.rb
67
+ - spec/lib/usps/imis/panel/properties_spec.rb
66
68
  - spec/lib/usps/imis/panel/vsc_spec.rb
67
69
  - spec/lib/usps/imis_spec.rb
68
70
  - spec/spec_helper.rb