usps-imis-api 0.6.2 → 0.6.4

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: a7e57bee906686721fa8b760f9fa322e04b289087e9295713283a2f6fcd5d3e6
4
- data.tar.gz: 6fe2a0b3405ddf20825ae24bb8986bf4e941a5fb46e37944988047faa5eb54e4
3
+ metadata.gz: ec6fd6190ca25775a69fca08cc8d16ba0177b6e34cd3643da1d07143720d607d
4
+ data.tar.gz: e73a5bf6dbc6f1d0daeab108bcd5a9ea86e925348562e25c76347a8e4c8a6b08
5
5
  SHA512:
6
- metadata.gz: e635a0d05fb1ce0139b422be14d01de9118bc2fa7474ee63eb802c5671a793e4628eea5d320ca93c59c41807419089243e6f1bd3bbc87dbda6c1baee2f06d28c
7
- data.tar.gz: a098bb43500c8db276cf03dd8b5f09954431b4a6011c6672656f061d05ca600972e70bab15ddd90877b62cedabb24f73d33575ea4ef5c6ef21d72e133f837cf7
6
+ metadata.gz: 6eb831bd549f3f9b95d4cb731974c2232f2defa762014f2471f9fb88de6386f350c1e2b09a3398e29b2c103c079666df5eca835a7c57f716c2263d794f0c7176
7
+ data.tar.gz: c84a91ef84235ea7f472824626ef59d946b35e04fee52c34375cd1e002c52ed4a75b08d76a3bc40576a349cd6960fec1a6a4124465e1e1061d2c40cb832d9147
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps-imis-api (0.6.2)
4
+ usps-imis-api (0.6.4)
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.1'
16
+ gem 'usps-imis-api', '~> 0.6.3'
17
17
  ```
18
18
 
19
19
  ## Setup
@@ -87,6 +87,16 @@ api.imis_id = 31092
87
87
  data = api.on('ABC_ASC_Individual_Demog').get
88
88
  ```
89
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
+
90
100
  ### PUT Fields
91
101
 
92
102
  To update member data, run e.g.:
@@ -204,7 +214,7 @@ previous value.
204
214
 
205
215
  ```ruby
206
216
  api.with(31092) do
207
- # These four requests are identical:
217
+ # These requests are identical:
208
218
 
209
219
  on('ABC_ASC_Individual_Demog') { put('TotMMS' => 15) }
210
220
 
@@ -222,6 +232,23 @@ api.with(6374) do
222
232
  end
223
233
  ```
224
234
 
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
247
+
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
+ ```
251
+
225
252
  ## Exception Handling
226
253
 
227
254
  All internal exceptions inherit from `Usps::Imis::ApiError`.
@@ -59,6 +59,43 @@ module Usps
59
59
  def payload(_data)
60
60
  raise Error::ApiError, "#{self.class.name} must implement #payload(data)"
61
61
  end
62
+
63
+ # rubocop:disable Metrics/MethodLength
64
+ def payload_header(data)
65
+ identity_type =
66
+ 'System.Collections.ObjectModel.Collection`1[[System.String, mscorlib]], mscorlib'
67
+
68
+ {
69
+ '$type' => 'Asi.Soa.Core.DataContracts.GenericEntityData, Asi.Contracts',
70
+ 'EntityTypeName' => business_object,
71
+ 'PrimaryParentEntityTypeName' => 'Party',
72
+ 'Identity' => {
73
+ '$type' => 'Asi.Soa.Core.DataContracts.IdentityData, Asi.Contracts',
74
+ 'EntityTypeName' => business_object,
75
+ 'IdentityElements' => {
76
+ '$type' => identity_type,
77
+ '$values' => [api.imis_id, data[:ordinal]&.to_s].compact
78
+ }
79
+ },
80
+ 'PrimaryParentIdentity' => {
81
+ '$type' => 'Asi.Soa.Core.DataContracts.IdentityData, Asi.Contracts',
82
+ 'EntityTypeName' => 'Party',
83
+ 'IdentityElements' => {
84
+ '$type' => identity_type,
85
+ '$values' => [api.imis_id]
86
+ }
87
+ }
88
+ }
89
+ end
90
+ # rubocop:enable Metrics/MethodLength
91
+
92
+ def property(name, value)
93
+ {
94
+ '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
95
+ 'Name' => name,
96
+ 'Value' => value
97
+ }
98
+ end
62
99
  end
63
100
  end
64
101
  end
@@ -14,97 +14,24 @@ module Usps
14
14
 
15
15
  # rubocop:disable Metrics/MethodLength
16
16
  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
- },
17
+ payload_header(data).merge(
40
18
  'Properties' => {
41
19
  '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyDataCollection, Asi.Contracts',
42
20
  '$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
- }
21
+ property('ID', api.imis_id),
22
+ (property('Ordinal', { '$type' => 'System.Int32', '$value' => data[:ordinal] }) if data[:ordinal]),
23
+ property('ABC_EDUC_THRU_DATE', data[:thru_date] || '0001-01-01T00:00:00'),
24
+ property('ABC_ECertificate', data[:certificate]),
25
+ property('ABC_Educ_Description', data[:description]),
26
+ property('ABC_Educ_Effective_Date', data[:effective_date]),
27
+ property('ABC_Educ_Source_System', data[:source]),
28
+ property('ABC_Educ_Transaction_Date', Time.now.strftime('%Y-%m-%dT%H:%I:%S')),
29
+ property('ABC_Other_Code', data[:code]),
30
+ property('ABC_Product_Code', data[:type_code]),
31
+ property('ABC_TYPE', data[:abc_type_code] || 'EDUC')
105
32
  ].compact
106
33
  }
107
- }
34
+ )
108
35
  end
109
36
  # rubocop:enable Metrics/MethodLength
110
37
  end
@@ -14,95 +14,23 @@ module Usps
14
14
 
15
15
  # rubocop:disable Metrics/MethodLength
16
16
  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
- },
17
+ payload_header(data).merge(
40
18
  'Properties' => {
41
19
  '$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyDataCollection, Asi.Contracts',
42
20
  '$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
- }
21
+ property('ID', api.imis_id),
22
+ (property('Ordinal', { '$type' => 'System.Int32', '$value' => data[:ordinal] }) if data[:ordinal]),
23
+ property('Source_System', 'Manual ITCom Entry'),
24
+ property('ABC_ECertificate', data[:certificate]),
25
+ property('Activity_Type', 'VSC'),
26
+ property('Description', 'Vessel Safety Checks'),
27
+ property('Effective_Date', "#{data[:year]}-12-01T00:00:00"),
28
+ property('Quantity', { '$type' => 'System.Int32', '$value' => data[:count] }),
29
+ property('Thru_Date', "#{data[:year]}-12-31T00:00:00"),
30
+ property('Transaction_Date', Time.now.strftime('%Y-%m-%dT%H:%M:%S'))
103
31
  ].compact
104
32
  }
105
- }
33
+ )
106
34
  end
107
35
  # rubocop:enable Metrics/MethodLength
108
36
  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.2'
5
+ VERSION = '0.6.4'
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)
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.2
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander