usps-imis-api 0.9.2 → 0.9.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: 1e410751cbd3ff6de46be231c0003cd5b23ffdfa891233f70025e493fa8e8057
4
- data.tar.gz: 993830af54fb76c8361b589b797b6c8fe600d485704087bf8020a17c20c5ca8e
3
+ metadata.gz: f53d9f4d8fc199b09d71f6b5e566c91d7e1052005e511d3921412d569900f584
4
+ data.tar.gz: 1843a632acc1c9c3e5db431c443e8b8d150ab8efa4834f0c80ee76e842161a86
5
5
  SHA512:
6
- metadata.gz: 481e7d0d83547f00cb77dbdec9ecb7b1d678d467fb8aacf0e35883bcdfa6700a9e926e6f1f73fb783bcdaed96fbda3a765ce854cf5d12f64e1c9aa3162ae3bed
7
- data.tar.gz: 1712c9f3e1ad4cf2ab7b6567861c6c1537b69fae0601829eafabacc80a22ae300681edb67d3ef6ab02e5c07e2ac0a999eab1e51142a21a101f262511a9115cf2
6
+ metadata.gz: 19d6a858ab56b41eff03cc80f499779fe28500b6c5664916f3c08dc8506f170d3b0aa6ffdcc7cf79801a912a020239685b7142029109a4118e896bead1953c62
7
+ data.tar.gz: aac564fc27bbfd9afd0b6e0db552e808b14e8be9fdd6e7e29c4fb5f5c95c6fa4c7225e16821dc43dd97c2c0d412ab6a9401169149093a7846d2662e9da937455
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps-imis-api (0.9.2)
4
+ usps-imis-api (0.9.4)
5
5
  activesupport (~> 8.0)
6
6
 
7
7
  GEM
data/lib/usps/imis/api.rb CHANGED
@@ -147,10 +147,12 @@ module Usps
147
147
 
148
148
  private
149
149
 
150
+ def logger = Imis.logger('Api')
151
+
150
152
  # Authenticate to the iMIS API, and store the access token and expiration time
151
153
  #
152
154
  def authenticate
153
- Imis.logger.debug 'Authenticating with iMIS'
155
+ logger.debug 'Authenticating with iMIS'
154
156
 
155
157
  uri = URI(File.join(Imis.configuration.hostname, AUTHENTICATION_PATH))
156
158
  req = Net::HTTP::Post.new(uri)
@@ -102,11 +102,17 @@ module Usps
102
102
  def delete = submit(uri, authorize(Net::HTTP::Delete.new(uri))).body == '' # rubocop:disable Naming/PredicateMethod
103
103
  alias destroy delete
104
104
 
105
+ # Ruby 3.5 instance variable filter
106
+ #
107
+ def instance_variables_to_inspect = instance_variables - %i[@api]
108
+
105
109
  private
106
110
 
107
111
  def token = api.token
108
112
  def token_expiration = api.token_expiration
109
113
 
114
+ def logger = Imis.logger('BusinessObject')
115
+
110
116
  # Construct a business object API endpoint address
111
117
  #
112
118
  def uri(id: nil)
@@ -160,7 +166,7 @@ module Usps
160
166
  request = Net::HTTP::Get.new(uri)
161
167
  result = submit(uri, authorize(request))
162
168
  result = Data.from_json(result.body)
163
- JSON.pretty_generate(result).split("\n").each { Imis.logger.debug " -> #{it}" }
169
+ JSON.pretty_generate(result).split("\n").each { logger.debug " -> #{it}" }
164
170
  result
165
171
  end
166
172
 
@@ -170,7 +176,7 @@ module Usps
170
176
  request.body = JSON.dump(body)
171
177
  result = submit(uri, authorize(request))
172
178
  result = Data.from_json(result.body)
173
- JSON.pretty_generate(result).split("\n").each { Imis.logger.debug " -> #{it}" }
179
+ JSON.pretty_generate(result).split("\n").each { logger.debug " -> #{it}" }
174
180
  result
175
181
  end
176
182
  end
@@ -8,15 +8,15 @@ module Usps
8
8
  IMIS_ROOT_URL_PROD = 'https://portal.americasboatingclub.org'
9
9
  IMIS_ROOT_URL_DEV = 'https://abcdev.imiscloud.com'
10
10
 
11
- attr_accessor :imis_id_query_name, :username, :password, :logger
12
- attr_reader :environment, :logger_level
11
+ attr_accessor :imis_id_query_name, :username, :password
12
+ attr_reader :environment, :logger, :logger_level
13
13
 
14
14
  def initialize
15
15
  @environment = defined?(Rails) ? Rails.env : ActiveSupport::StringInquirer.new('development')
16
16
  @imis_id_query_name = ENV.fetch('IMIS_ID_QUERY_NAME', nil)
17
17
  @username = ENV.fetch('IMIS_USERNAME', nil)
18
18
  @password = ENV.fetch('IMIS_PASSWORD', nil)
19
- @logger = Logger.new($stdout, level: :info)
19
+ @logger = ActiveSupport::TaggedLogging.new(Logger.new($stdout, level: :info))
20
20
 
21
21
  yield self if block_given?
22
22
 
@@ -27,6 +27,10 @@ module Usps
27
27
  @environment = ActiveSupport::StringInquirer.new(env.to_s)
28
28
  end
29
29
 
30
+ def logger=(logger)
31
+ @logger = ActiveSupport::TaggedLogging.new(logger)
32
+ end
33
+
30
34
  # Environment-specific API endpoint hostname
31
35
  #
32
36
  # @return The API hostname for the current environment
@@ -51,8 +51,14 @@ module Usps
51
51
  end
52
52
  end
53
53
 
54
+ # Ruby 3.5 instance variable filter
55
+ #
56
+ def instance_variables_to_inspect = instance_variables - %i[@api]
57
+
54
58
  private
55
59
 
60
+ def logger = Imis.logger('Mapper')
61
+
56
62
  def map_update(field_name)
57
63
  missing_mapping!(field_name) unless FIELD_MAPPING.key?(field_name.to_sym)
58
64
 
@@ -87,8 +87,14 @@ module Usps
87
87
  def delete(ordinal) = api.on(business_object, ordinal:).delete
88
88
  alias destroy delete
89
89
 
90
+ # Ruby 3.5 instance variable filter
91
+ #
92
+ def instance_variables_to_inspect = instance_variables - %i[@api]
93
+
90
94
  private
91
95
 
96
+ def logger = Imis.logger('Panel')
97
+
92
98
  def business_object
93
99
  raise Errors::PanelUnimplementedError.from(self.class.name, 'business_object')
94
100
  end
@@ -43,7 +43,7 @@ module Usps
43
43
  # Iterate through all results from the query
44
44
  #
45
45
  def each(&)
46
- Imis.logger.info 'Running IQA Query on iMIS'
46
+ logger.info 'Running IQA Query on iMIS'
47
47
 
48
48
  items = []
49
49
  find_each { items << it }
@@ -57,14 +57,14 @@ module Usps
57
57
  count = 0
58
58
 
59
59
  while result['HasNext']
60
- Imis.logger.info 'Fetching IQA Query page'
60
+ logger.info 'Fetching IQA Query page'
61
61
 
62
62
  result = fetch
63
63
 
64
64
  count += result['Count'] || 0
65
- Imis.logger.info " -> #{count} / #{result['TotalCount']} #{'item'.pluralize(count)}"
66
- Imis.logger.debug ' -> Query page data:'
67
- JSON.pretty_generate(result).split("\n").each { Imis.logger.debug " -> #{it}" }
65
+ logger.info " -> #{count} / #{result['TotalCount']} #{'item'.pluralize(count)}"
66
+ logger.debug ' -> Query page data:'
67
+ JSON.pretty_generate(result).split("\n").each { logger.debug " -> #{it}" }
68
68
 
69
69
  items = result['Items']['$values'].map { it.except('$type') }
70
70
  @offset = result['NextOffset']
@@ -75,6 +75,10 @@ module Usps
75
75
  nil
76
76
  end
77
77
 
78
+ # Ruby 3.5 instance variable filter
79
+ #
80
+ def instance_variables_to_inspect = instance_variables - %i[@api]
81
+
78
82
  private
79
83
 
80
84
  def token = api.token
@@ -83,6 +87,8 @@ module Usps
83
87
  def path = "#{QUERY_PATH}?#{query_params.merge(QueryName: query_name, Offset: offset).to_query}"
84
88
  def uri = URI(File.join(Imis.configuration.hostname, path))
85
89
  def fetch = JSON.parse(submit(uri, authorize(Net::HTTP::Get.new(uri))).body)
90
+
91
+ def logger = Imis.logger('Query')
86
92
  end
87
93
  end
88
94
  end
@@ -7,6 +7,8 @@ module Usps
7
7
  module Requests
8
8
  private
9
9
 
10
+ def logger = Imis.logger
11
+
10
12
  def client(uri)
11
13
  Net::HTTP.new(uri.host, uri.port).tap do |http|
12
14
  http.use_ssl = true
@@ -20,20 +22,20 @@ module Usps
20
22
  #
21
23
  def authorize(request)
22
24
  if token_expiration < Time.now
23
- Imis.logger.debug 'Token expired: re-authenticating with iMIS'
25
+ logger.debug 'Token expired: re-authenticating with iMIS'
24
26
  authenticate
25
27
  end
26
28
  request.tap { it.add_field('Authorization', "Bearer #{token}") }
27
29
  end
28
30
 
29
31
  def submit(uri, request)
30
- Imis.logger.info 'Submitting request to iMIS'
31
- Imis.logger.debug " -> #{request.class.name.demodulize.upcase} #{uri}"
32
- sanitized_request_body(request).split("\n").each { Imis.logger.debug " -> #{it}" }
32
+ logger.info 'Submitting request to iMIS'
33
+ logger.debug " -> #{request.class.name.demodulize.upcase} #{uri}"
34
+ sanitized_request_body(request).split("\n").each { logger.debug " -> #{it}" }
33
35
  client(uri).request(request).tap do |result|
34
36
  raise Errors::ResponseError.from(result) unless result.is_a?(Net::HTTPSuccess)
35
37
 
36
- Imis.logger.info 'Request succeeded'
38
+ logger.info 'Request succeeded'
37
39
  end
38
40
  end
39
41
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Imis
5
- VERSION = '0.9.2'
5
+ VERSION = '0.9.4'
6
6
  end
7
7
  end
data/lib/usps/imis.rb CHANGED
@@ -11,6 +11,8 @@ require 'active_support/core_ext/object/to_query'
11
11
  require 'active_support/core_ext/enumerable'
12
12
  require 'active_support/string_inquirer'
13
13
  require 'logger'
14
+ require 'active_support/isolated_execution_state' # Fix costant loading issue with TaggedLogging
15
+ require 'active_support/tagged_logging'
14
16
 
15
17
  # Internal requires
16
18
  require_relative 'imis/config'
@@ -43,9 +45,9 @@ module Usps
43
45
  configuration
44
46
  end
45
47
 
46
- # Logger instance to write to
48
+ # Logger (with optional nested tags) to write to
47
49
  #
48
- def logger = configuration.logger
50
+ def logger(*tags) = configuration.logger.tagged('iMIS', *tags)
49
51
  end
50
52
  end
51
53
  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.9.2
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander