usps-imis-api 0.6.4 → 0.6.6
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/Gemfile.lock +1 -1
- data/lib/usps/imis/panel/base_panel.rb +57 -22
- data/lib/usps/imis/panel/education.rb +13 -20
- data/lib/usps/imis/panel/vsc.rb +12 -19
- data/lib/usps/imis/version.rb +1 -1
- data/spec/lib/usps/imis/panel/base_panel_spec.rb +18 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ac6724a275018ca6e957f9342236882dde2232e1c6e9cf8f0f11e962e2ae5bb7
|
|
4
|
+
data.tar.gz: 196dc78c0f36f2921e79aba9cfd6157818932f62751475817f0b054cd2decc8d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6ef1c062d0d887efcb0d9c0884e43df859d992f65546b16de6d359545c6f0fa92bc0d6d533c6dbca212e5fbdd47b1e3d1cd23e7a91b4af304ed4e95199e8cdb1
|
|
7
|
+
data.tar.gz: 1fe0de2b0c8f722afa9159779973ef9491f007dad2667cd18f2e863128d69c487f7a09801fba1c9bb0c0710c002e84396064d0a3a98c725f43b4d75f006ca907
|
data/Gemfile.lock
CHANGED
|
@@ -60,42 +60,77 @@ module Usps
|
|
|
60
60
|
raise Error::ApiError, "#{self.class.name} must implement #payload(data)"
|
|
61
61
|
end
|
|
62
62
|
|
|
63
|
-
# rubocop:disable Metrics/MethodLength
|
|
64
63
|
def payload_header(data)
|
|
65
|
-
identity_type =
|
|
66
|
-
'System.Collections.ObjectModel.Collection`1[[System.String, mscorlib]], mscorlib'
|
|
67
|
-
|
|
68
64
|
{
|
|
69
65
|
'$type' => 'Asi.Soa.Core.DataContracts.GenericEntityData, Asi.Contracts',
|
|
70
66
|
'EntityTypeName' => business_object,
|
|
71
67
|
'PrimaryParentEntityTypeName' => 'Party',
|
|
72
|
-
'Identity' =>
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
'
|
|
81
|
-
|
|
82
|
-
'
|
|
83
|
-
'
|
|
84
|
-
'$type' => identity_type,
|
|
85
|
-
'$values' => [api.imis_id]
|
|
86
|
-
}
|
|
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
|
|
87
80
|
}
|
|
88
81
|
}
|
|
89
82
|
end
|
|
90
|
-
# rubocop:enable Metrics/MethodLength
|
|
91
83
|
|
|
92
|
-
def
|
|
84
|
+
def primary_parent_identity
|
|
93
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
|
|
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
|
|
113
|
+
|
|
114
|
+
def property(name, value)
|
|
115
|
+
raise Error::ApiError, 'Must be called within a `properties` block' unless defined?(@properties)
|
|
116
|
+
|
|
117
|
+
@properties << {
|
|
94
118
|
'$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
|
|
95
119
|
'Name' => name,
|
|
96
|
-
'Value' => value
|
|
120
|
+
'Value' => property_value(value)
|
|
97
121
|
}
|
|
98
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
|
|
99
134
|
end
|
|
100
135
|
end
|
|
101
136
|
end
|
|
@@ -12,28 +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
|
-
|
|
18
|
-
'
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
property('ABC_Product_Code', data[:type_code]),
|
|
31
|
-
property('ABC_TYPE', data[:abc_type_code] || 'EDUC')
|
|
32
|
-
].compact
|
|
33
|
-
}
|
|
34
|
-
)
|
|
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'
|
|
28
|
+
end
|
|
35
29
|
end
|
|
36
|
-
# rubocop:enable Metrics/MethodLength
|
|
37
30
|
end
|
|
38
31
|
end
|
|
39
32
|
end
|
data/lib/usps/imis/panel/vsc.rb
CHANGED
|
@@ -12,27 +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
|
-
|
|
18
|
-
'
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
property('Thru_Date', "#{data[:year]}-12-31T00:00:00"),
|
|
30
|
-
property('Transaction_Date', Time.now.strftime('%Y-%m-%dT%H:%M:%S'))
|
|
31
|
-
].compact
|
|
32
|
-
}
|
|
33
|
-
)
|
|
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
|
|
27
|
+
end
|
|
34
28
|
end
|
|
35
|
-
# rubocop:enable Metrics/MethodLength
|
|
36
29
|
end
|
|
37
30
|
end
|
|
38
31
|
end
|
data/lib/usps/imis/version.rb
CHANGED
|
@@ -29,4 +29,22 @@ 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
|
|
32
50
|
end
|