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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/usps/imis/api.rb +3 -1
- data/lib/usps/imis/business_object.rb +8 -2
- data/lib/usps/imis/config.rb +7 -3
- data/lib/usps/imis/mapper.rb +6 -0
- data/lib/usps/imis/panels/base_panel.rb +6 -0
- data/lib/usps/imis/query.rb +11 -5
- data/lib/usps/imis/requests.rb +7 -5
- data/lib/usps/imis/version.rb +1 -1
- data/lib/usps/imis.rb +4 -2
- 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: f53d9f4d8fc199b09d71f6b5e566c91d7e1052005e511d3921412d569900f584
|
|
4
|
+
data.tar.gz: 1843a632acc1c9c3e5db431c443e8b8d150ab8efa4834f0c80ee76e842161a86
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 19d6a858ab56b41eff03cc80f499779fe28500b6c5664916f3c08dc8506f170d3b0aa6ffdcc7cf79801a912a020239685b7142029109a4118e896bead1953c62
|
|
7
|
+
data.tar.gz: aac564fc27bbfd9afd0b6e0db552e808b14e8be9fdd6e7e29c4fb5f5c95c6fa4c7225e16821dc43dd97c2c0d412ab6a9401169149093a7846d2662e9da937455
|
data/Gemfile.lock
CHANGED
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
|
-
|
|
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 {
|
|
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 {
|
|
179
|
+
JSON.pretty_generate(result).split("\n").each { logger.debug " -> #{it}" }
|
|
174
180
|
result
|
|
175
181
|
end
|
|
176
182
|
end
|
data/lib/usps/imis/config.rb
CHANGED
|
@@ -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
|
|
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
|
data/lib/usps/imis/mapper.rb
CHANGED
|
@@ -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
|
data/lib/usps/imis/query.rb
CHANGED
|
@@ -43,7 +43,7 @@ module Usps
|
|
|
43
43
|
# Iterate through all results from the query
|
|
44
44
|
#
|
|
45
45
|
def each(&)
|
|
46
|
-
|
|
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
|
-
|
|
60
|
+
logger.info 'Fetching IQA Query page'
|
|
61
61
|
|
|
62
62
|
result = fetch
|
|
63
63
|
|
|
64
64
|
count += result['Count'] || 0
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
JSON.pretty_generate(result).split("\n").each {
|
|
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
|
data/lib/usps/imis/requests.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
sanitized_request_body(request).split("\n").each {
|
|
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
|
-
|
|
38
|
+
logger.info 'Request succeeded'
|
|
37
39
|
end
|
|
38
40
|
end
|
|
39
41
|
|
data/lib/usps/imis/version.rb
CHANGED
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
|
|
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
|