usps-imis-api 0.6.3 → 0.6.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: eeff742b04ebe9046cb57d7cf8501b3a175a9e50729cba6f812f44ed12d90c43
4
- data.tar.gz: 5960918afa1fd57e141cdd52408380ce135e53fa81eb7da4f9c48849436974ac
3
+ metadata.gz: 2cb3b6691433ac4025d4754b093d3843620e13396cdd61995cce7b8b0c330da5
4
+ data.tar.gz: a46f9929ea1dd7eabf47eb6364768014807129cf495f84748e6cb8d2cb95aa72
5
5
  SHA512:
6
- metadata.gz: eb267af35e92cfa0c7511b1ed78eae72b6811569324486ea0f411dcf988c0f5d0515f079b0356cac0776555dd93b62f677fccc0fcf78ae43e424cb8f856469a6
7
- data.tar.gz: 83c81ac9c0ef3ef658ae32c6de1026ec9aa5bea89f6f4e7bd2e0b5e7bcd6052562d93ab4d7f01db7b5bb4ab57e1eb1b00fe26a8121efeadf013cd2007a7e32e9
6
+ metadata.gz: 2cf22b22ca0e4c99e450e5805a58a841d462e86fd0b61f54c8ec62abb04d7cd875808f80fb078933490af9db7082b8bc6b88a4f3a1855e266c1aefbd76479516
7
+ data.tar.gz: b666bb26b1ffd36d48fd968c6eeb20a137d91abdf807013716b297c3a2ccb1a8166bf2b1968b4dd9a85dbf5a9114212d521f4235c050948c907b300227cc4444
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps-imis-api (0.6.3)
4
+ usps-imis-api (0.6.5)
5
5
  activesupport (~> 8.0)
6
6
 
7
7
  GEM
data/Readme.md CHANGED
@@ -236,13 +236,13 @@ end
236
236
  api.with(31092) do
237
237
  # These requests are identical:
238
238
 
239
- api.on('ABC_ASC_Individual_Demog') do
239
+ on('ABC_ASC_Individual_Demog') do
240
240
  get['Properties']['$values'].find { |hash| hash['Name'] == 'TotMMS' }['Value']['$value']
241
241
  end
242
242
 
243
- api.on('ABC_ASC_Individual_Demog') { get_field('TotMMS') }
243
+ on('ABC_ASC_Individual_Demog') { get_field('TotMMS') }
244
244
 
245
- api.on('ABC_ASC_Individual_Demog').get_field('TotMMS')
245
+ on('ABC_ASC_Individual_Demog').get_field('TotMMS')
246
246
  end
247
247
 
248
248
  # This request fetches the same data, but leaves the iMIS ID selected
@@ -59,6 +59,67 @@ 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
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 << {
118
+ '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
119
+ 'Name' => name,
120
+ 'Value' => value
121
+ }
122
+ end
62
123
  end
63
124
  end
64
125
  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
+ properties(data) do
17
+ property 'ID', api.imis_id
18
+ property 'Ordinal', { '$type' => 'System.Int32', '$value' => 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.strftime('%Y-%m-%dT%H:%I:%S')
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
108
29
  end
109
- # rubocop:enable Metrics/MethodLength
110
30
  end
111
31
  end
112
32
  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
+ properties(data) do
17
+ property 'ID', api.imis_id
18
+ property 'Ordinal', { '$type' => 'System.Int32', '$value' => 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', { '$type' => 'System.Int32', '$value' => data[:count] }
25
+ property 'Thru_Date', "#{data[:year]}-12-31T00:00:00"
26
+ property 'Transaction_Date', Time.now.strftime('%Y-%m-%dT%H:%M:%S')
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 = '0.6.3'
5
+ VERSION = '0.6.5'
6
6
  end
7
7
  end
@@ -29,4 +29,10 @@ 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
32
38
  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.3
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander