usps-imis-api 0.11.27 → 0.11.29

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: 0c955b3a9fbb3332402a055df4c362098cdfb48ccdab24b68d12a11b5400e04d
4
- data.tar.gz: f5bf791f4fcc5c69f65bdef290f2342537d2b4d0afec5ba9a5a02366dde68d4e
3
+ metadata.gz: ff08376f763d16ba1615aea1d4d072f25c31faf5586a255cbf500d920d5d0de0
4
+ data.tar.gz: fdb80613eaf2d4448e9e7731001b276f3513a86de9c9e2b85718cd99df4aa738
5
5
  SHA512:
6
- metadata.gz: 58459a3b0ecfd22e76e14499767e6fa056eed31a1bbc95c2c84dc97936feb62791df4e4f43b5ac395ec0bfb1f639d51db69e1d3fe439a58c819d661704ac4588
7
- data.tar.gz: ea91b6a28f59ca29b28a4676367b0b65288e2f4903ab2833a24aa0135f1e90fe305ffab8fe3ba6cd918d1338235ced2d49da4f3a478e9f2cd5511bec9484e676
6
+ metadata.gz: 9ea444e537b5f978c3017045faf126474f8f53d885c6a8c802d5f81051b738f5474a43fe4de2baad28a68b5365b5e929e73717ba08cb2183cbe8e020c88873aa
7
+ data.tar.gz: ac58fcaef0547ae18db0170ca5ffb1370df2965b6f8563104d9d20ff986c892ad41fffd0bcf6764a80d8ebbf96ec8bbd33bb8354acadf6227384a8e4fcbe08bd
data/lib/usps/imis/api.rb CHANGED
@@ -53,8 +53,9 @@ module Usps
53
53
  #
54
54
  # @param imis_id [Integer, String] iMIS ID to select immediately on initialization
55
55
  #
56
- def initialize(imis_id: nil)
56
+ def initialize(imis_id: nil, record_id: nil)
57
57
  self.imis_id = imis_id if imis_id
58
+ self.record_id = record_id if record_id
58
59
  @logger ||= Imis.logger('Api')
59
60
  Imis.config.validate!
60
61
  end
@@ -71,6 +72,26 @@ module Usps
71
72
  @imis_id = id&.to_i
72
73
  end
73
74
 
75
+ # Manually set the current record ID
76
+ #
77
+ # @param id [Integer, String] Record ID to select for future requests
78
+ #
79
+ # @return [Integer] Record ID
80
+ #
81
+ def record_id=(id)
82
+ return if id.nil?
83
+
84
+ raise Errors::LockedIdError if lock_imis_id
85
+
86
+ @record_id = id.to_i
87
+ end
88
+
89
+ # Currently selected Record ID for API requests
90
+ #
91
+ # Defaults to the iMIS ID
92
+ #
93
+ def record_id = @record_id || imis_id
94
+
74
95
  # Convert a member's certificate number into an iMIS ID number
75
96
  #
76
97
  # @param certificate [String] Certificate number to lookup the corresponding iMIS ID for
@@ -101,6 +122,7 @@ module Usps
101
122
  #
102
123
  # @param id [Integer, String] iMIS ID to select for requests within the block
103
124
  # @param certificate [String] Certificate number to convert to iMIS ID and select for requests within the block
125
+ # @param record_id [Integer] Record ID to select for requests within the block
104
126
  #
105
127
  # @example
106
128
  # with(12345) do
@@ -109,12 +131,14 @@ module Usps
109
131
  #
110
132
  # @return [Usps::Imis::Api]
111
133
  #
112
- def with(id = nil, certificate: nil, &)
134
+ def with(id = nil, certificate: nil, record_id: nil, &)
113
135
  raise ArgumentError, 'Must provide id or certificate' unless id || certificate
114
136
 
115
137
  old_id = imis_id
138
+ old_record_id = @record_id
116
139
 
117
140
  id.nil? ? imis_id_for(certificate) : self.imis_id = id
141
+ self.record_id = record_id
118
142
  return self unless block_given?
119
143
 
120
144
  @lock_imis_id = true
@@ -123,6 +147,7 @@ module Usps
123
147
  if block_given?
124
148
  @lock_imis_id = false
125
149
  self.imis_id = old_id
150
+ self.record_id = old_record_id
126
151
  end
127
152
  end
128
153
 
@@ -23,6 +23,12 @@ module Usps
23
23
  end
24
24
  alias id imis_id
25
25
 
26
+ # Access the Record ID property
27
+ #
28
+ def record_id
29
+ raise Errors::ApiError, "#{self.class} must implement #record_id"
30
+ end
31
+
26
32
  # Access an individual property value by name
27
33
  #
28
34
  def [](_property_name)
@@ -20,7 +20,7 @@ module Usps
20
20
 
21
21
  # Build a blank object for the current iMIS ID
22
22
  #
23
- def build(&) = payload_header.merge(Properties.build(parent.api.imis_id.to_s, @ordinal.to_s, &))
23
+ def build(&) = payload_header.merge(Properties.build(parent.api.record_id.to_s, @ordinal&.to_s, &))
24
24
 
25
25
  private
26
26
 
@@ -42,7 +42,7 @@ module Usps
42
42
  'EntityTypeName' => parent.business_object_name,
43
43
  'IdentityElements' => {
44
44
  '$type' => identity_type,
45
- '$values' => [parent.api.imis_id.to_s, @ordinal&.to_s].compact
45
+ '$values' => [parent.api.record_id.to_s, @ordinal&.to_s].compact
46
46
  }
47
47
  }
48
48
  end
@@ -48,12 +48,12 @@ module Usps
48
48
 
49
49
  # Support passthrough for Api#with
50
50
  #
51
- def with(imis_id, &)
51
+ def with(*, **, &)
52
52
  # Bring into local scope
53
53
  wrapper_business_object_name = business_object_name
54
54
  wrapper_ordinal = ordinal
55
55
 
56
- api.with(imis_id) do
56
+ api.with(*, **) do
57
57
  on(wrapper_business_object_name, ordinal: wrapper_ordinal, &)
58
58
  end
59
59
  end
@@ -163,9 +163,9 @@ module Usps
163
163
  #
164
164
  def id_for_uri(id = nil)
165
165
  return CGI.escape(id) unless id.nil?
166
- return CGI.escape("~#{api.imis_id}|#{ordinal}") if ordinal
166
+ return CGI.escape("~#{api.record_id}|#{ordinal}") if ordinal
167
167
 
168
- api.imis_id.to_s
168
+ api.record_id.to_s
169
169
  end
170
170
 
171
171
  # Manually assemble the matching data structure, with fields in the correct order
@@ -93,7 +93,10 @@ module Usps
93
93
  # Query
94
94
  end
95
95
 
96
+ api.record_id = options[:record_id] if options[:record_id]
97
+
96
98
  logger.debug "iMIS ID: #{api.imis_id}" if api.imis_id
99
+ logger.debug "Record ID: #{api.record_id}" if api.record_id
97
100
  end
98
101
 
99
102
  def simplify(data)
@@ -10,6 +10,7 @@ module Usps
10
10
  # IDs
11
11
  certificate: ['Member certificate number', { type: :string }],
12
12
  id: ['Member iMIS ID', { type: :integer }],
13
+ record_id: ['Specific Record ID', { type: :integer, short: :I }],
13
14
 
14
15
  # Primary interactions
15
16
  on: ['Business Object name', { type: :string }],
@@ -14,11 +14,15 @@ module Usps
14
14
  #
15
15
  def entity = raw['EntityTypeName']
16
16
 
17
- # Access the iMIS ID property
17
+ # Access the iMIS ID (i.e. Party ID) property
18
18
  #
19
- def imis_id = self['ID'].to_i
19
+ def imis_id = raw['PrimaryParentIdentity']['IdentityElements']['$values'].first.to_i
20
20
  alias id imis_id
21
21
 
22
+ # Access the Record ID property
23
+ #
24
+ def record_id = raw['Identity']['IdentityElements']['$values'].first.to_i
25
+
22
26
  # Access the Ordinal identifier property (if present)
23
27
  #
24
28
  def ordinal = self['Ordinal']&.to_i
@@ -47,7 +51,7 @@ module Usps
47
51
  private
48
52
 
49
53
  def pretty_print_data
50
- { entity:, imis_id:, ordinal: }.compact
54
+ { entity:, imis_id:, record_id: (record_id unless record_id == imis_id), ordinal: }.compact
51
55
  end
52
56
 
53
57
  def property_values = raw['Properties']['$values']
@@ -18,7 +18,7 @@ module Usps
18
18
  super(message)
19
19
  @metadata = metadata
20
20
 
21
- Imis.logger(self.class.name).error self
21
+ Imis.logger(self.class.name).multiline(self.message, level: :error)
22
22
  end
23
23
 
24
24
  # Additional metadata to include in Bugsnag reports
@@ -3,12 +3,12 @@
3
3
  module Usps
4
4
  module Imis
5
5
  module Errors
6
- # Exception raised when attempting to change the iMIS ID while it is locked
6
+ # Exception raised when attempting to change the iMIS ID or Record ID while it is locked
7
7
  #
8
8
  class LockedIdError < Error
9
9
  def initialize = super(message)
10
10
 
11
- def message = 'Cannot change iMIS ID while locked'
11
+ def message = 'Cannot change iMIS or Record ID while locked'
12
12
  end
13
13
  end
14
14
  end
@@ -49,8 +49,8 @@ module Usps
49
49
  #
50
50
  def message
51
51
  [
52
- "#{self.class.name}: [#{status.to_s.upcase}] The iMIS API returned an error.",
53
- (metadata.inspect if metadata != {}),
52
+ "[#{status.to_s.upcase}] The iMIS API returned an error.",
53
+ (metadata.inspect if metadata?),
54
54
  body
55
55
  ].compact.join("\n")
56
56
  end
@@ -61,6 +61,8 @@ module Usps
61
61
  { api: { status:, body: } }
62
62
  end
63
63
 
64
+ def metadata? = metadata != {} && !metadata.nil?
65
+
64
66
  def status
65
67
  @status ||=
66
68
  case response.code
@@ -93,7 +95,7 @@ module Usps
93
95
  response_body['error_description']
94
96
  else
95
97
  # Unknown error type: just use the raw response
96
- response.body
98
+ JSON.pretty_generate(response.body)
97
99
  end
98
100
  end
99
101
  end
@@ -5,12 +5,15 @@ module Usps
5
5
  # Formatted logger helpers
6
6
  #
7
7
  module LoggerHelpers
8
- def multiline(string)
9
- string.split("\n").each { |line| debug(line) }
8
+ def multiline(string, level: :debug)
9
+ string.split("\n").each { public_send(level, it) }
10
10
  end
11
11
 
12
12
  def json(data)
13
- tagged('JSON') { multiline(JSON.pretty_generate(data)) }
13
+ hash = data.is_a?(String) ? JSON.parse(data) : data
14
+ tagged('JSON') { multiline(JSON.pretty_generate(hash)) }
15
+ rescue StandardError
16
+ multiline(data)
14
17
  end
15
18
  end
16
19
  end
@@ -14,9 +14,10 @@ module Usps
14
14
  #
15
15
  attr_reader :logger
16
16
 
17
- def initialize(api = nil, imis_id: nil)
17
+ def initialize(api = nil, imis_id: nil, record_id: nil)
18
18
  @api = api || Api.new
19
19
  @api.imis_id = imis_id if imis_id
20
+ @api.record_id = record_id if record_id
20
21
  @logger ||= Imis.logger('Panel')
21
22
  end
22
23
 
@@ -41,7 +41,7 @@ module Usps
41
41
  logger.info 'Submitting request to iMIS'
42
42
  logger.tagged('Request') do
43
43
  logger.debug "#{request.class.name.demodulize.upcase} #{uri}"
44
- logger.multiline sanitized_request_body(request)
44
+ logger.json sanitized_request_body(request)
45
45
 
46
46
  client(uri).request(request).tap do |result|
47
47
  raise Errors::ResponseError.from(result) unless result.is_a?(Net::HTTPSuccess)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Imis
5
- VERSION = '0.11.27'
5
+ VERSION = '0.11.29'
6
6
  end
7
7
  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.11.27
4
+ version: 0.11.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander