usps-imis-api 0.11.35 → 0.11.36
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/Readme.md +2 -1
- data/lib/usps/imis/api.rb +6 -0
- data/lib/usps/imis/command_line/interface.rb +18 -3
- data/lib/usps/imis/command_line/options_parser.rb +3 -2
- data/lib/usps/imis/command_line/performers.rb +4 -3
- data/lib/usps/imis/config.rb +37 -1
- data/lib/usps/imis/logger.rb +9 -0
- data/lib/usps/imis/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 27d14e895f15b3dc94ab5d32f07f52855253b412d0f09e62925ae2833664269e
|
|
4
|
+
data.tar.gz: 3c2f8d03ae31e1b4372f5ae16047ad09c7401fee5831e62c3f72e2e5517761cd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0f67ef6dd5d2dc56a8fcb982498c7766eb6b6a7ea26e340f7fe358cb88d694e3d1a4c392da59660fd6ddb134bc09c1e9b3394609af7dcf8ba388d203fa33f51a
|
|
7
|
+
data.tar.gz: a6bf0462662992192b01cac14124b640dd3ccf7ad56637719cf2b71558cdf3198a89df6110b37e16fac56b4aecfd6d0ca4659fef0f598a28774e11bbaf2bd191
|
data/Readme.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
Run this command:
|
|
8
8
|
|
|
9
|
-
```
|
|
9
|
+
```sh
|
|
10
10
|
gem install usps-imis-api
|
|
11
11
|
```
|
|
12
12
|
|
|
@@ -36,6 +36,7 @@ Usps::Imis.configure do |config|
|
|
|
36
36
|
# These options will use these defaults
|
|
37
37
|
config.logger = ActiveSupport::TaggedLogging.new(Logger.new($stdout))
|
|
38
38
|
config.logger.level = :info
|
|
39
|
+
config.global_log_path = '/var/log/imis/imis.log'
|
|
39
40
|
end
|
|
40
41
|
```
|
|
41
42
|
|
data/lib/usps/imis/api.rb
CHANGED
|
@@ -12,6 +12,8 @@ module Usps
|
|
|
12
12
|
class Api
|
|
13
13
|
include Requests
|
|
14
14
|
|
|
15
|
+
NAME = 'USPS iMIS API - Ruby'
|
|
16
|
+
|
|
15
17
|
# Endpoint for (re-)authentication requests
|
|
16
18
|
#
|
|
17
19
|
AUTHENTICATION_PATH = 'Token'
|
|
@@ -244,6 +246,10 @@ module Usps
|
|
|
244
246
|
{ token: @token, token_expiration: @token_expiration }
|
|
245
247
|
end
|
|
246
248
|
|
|
249
|
+
# Name and version of the API
|
|
250
|
+
#
|
|
251
|
+
def version = "#{NAME} (v#{Imis::VERSION})"
|
|
252
|
+
|
|
247
253
|
# Ruby 3.5 instance variable filter
|
|
248
254
|
#
|
|
249
255
|
def instance_variables_to_inspect = %i[@token_expiration @imis_id]
|
|
@@ -10,8 +10,6 @@ module Usps
|
|
|
10
10
|
class Interface
|
|
11
11
|
include Performers
|
|
12
12
|
|
|
13
|
-
NAME = 'USPS iMIS API - Ruby'
|
|
14
|
-
|
|
15
13
|
# Prioritized list of config file paths to automatically check if not provided
|
|
16
14
|
#
|
|
17
15
|
CONFIG_PATHS = {
|
|
@@ -157,7 +155,9 @@ module Usps
|
|
|
157
155
|
config_data = YAML.safe_load_file(config_path)
|
|
158
156
|
|
|
159
157
|
Usps::Imis.configure do |config|
|
|
160
|
-
|
|
158
|
+
global_log!(config)
|
|
159
|
+
|
|
160
|
+
config_data&.each do |key, value|
|
|
161
161
|
config.public_send("#{key}=", value)
|
|
162
162
|
end
|
|
163
163
|
end
|
|
@@ -186,6 +186,21 @@ module Usps
|
|
|
186
186
|
end
|
|
187
187
|
end
|
|
188
188
|
|
|
189
|
+
def global_log!(config)
|
|
190
|
+
# :nocov:
|
|
191
|
+
return if ENV['TESTING']
|
|
192
|
+
|
|
193
|
+
time = DateTime.now
|
|
194
|
+
log_path = [
|
|
195
|
+
time.year,
|
|
196
|
+
time.month,
|
|
197
|
+
time.day,
|
|
198
|
+
time.strftime('%Y-%m-%dT%H-%M-%S%z')
|
|
199
|
+
].join('/')
|
|
200
|
+
config.global_log_path = "/var/log/imis/cli/#{log_path}.log"
|
|
201
|
+
# :nocov:
|
|
202
|
+
end
|
|
203
|
+
|
|
189
204
|
def default_options? = options[:log_level] == 'info' && options.except(:log_level).values.none?
|
|
190
205
|
end
|
|
191
206
|
end
|
|
@@ -29,7 +29,7 @@ module Usps
|
|
|
29
29
|
ordinal: ['Ordinal ID within a Panel', { type: :integer }],
|
|
30
30
|
field: ['Specific field to return or update', { type: :string }],
|
|
31
31
|
fields: ['Specific field(s) to return', { type: :strings, short: :F }],
|
|
32
|
-
data: [
|
|
32
|
+
data: ["JSON string input -- #{'STDIN'.red} takes priority", { type: :string }],
|
|
33
33
|
|
|
34
34
|
# Iteractions for supporting other language wrappers
|
|
35
35
|
auth_token: ['Return an auth token for other language wrappers', { short: :T }],
|
|
@@ -46,6 +46,7 @@ module Usps
|
|
|
46
46
|
'If no option is provided, the first matching preset option will be automatically used.',
|
|
47
47
|
{ type: :string, short: :C }
|
|
48
48
|
],
|
|
49
|
+
show_config: ['Return the active config file path', { short: :X }],
|
|
49
50
|
raw: ['Return raw JSON output, rather than simplified data', { short: :R }],
|
|
50
51
|
include_ids: ["Include any #{'iMIS ID'.yellow} and #{'Ordinal'.yellow} properties in returned data"],
|
|
51
52
|
jsonl: ['Format array output as JSONL', { short: :j }],
|
|
@@ -57,7 +58,7 @@ module Usps
|
|
|
57
58
|
CONFLICTING_OPTION_GROUPS = [
|
|
58
59
|
%i[certificate id uuid],
|
|
59
60
|
%i[record_id uuid],
|
|
60
|
-
%i[on panel query mapper map business_objects auth_token],
|
|
61
|
+
%i[on panel query mapper map business_objects auth_token show_config],
|
|
61
62
|
%i[field fields map query],
|
|
62
63
|
%i[raw include_ids],
|
|
63
64
|
%i[quiet log_level],
|
|
@@ -19,7 +19,8 @@ module Usps
|
|
|
19
19
|
in business_objects: true then api.business_objects
|
|
20
20
|
in auth_token: true then api.auth_token
|
|
21
21
|
in certificate: then api.imis_id
|
|
22
|
-
in
|
|
22
|
+
in show_config: then config_path
|
|
23
|
+
in version: true then api.version
|
|
23
24
|
end
|
|
24
25
|
rescue NoMatchingPatternError => e
|
|
25
26
|
raise Errors::CommandLineError, "Unable to match pattern from options: #{e.message}"
|
|
@@ -36,8 +37,8 @@ module Usps
|
|
|
36
37
|
# Nothing to convert
|
|
37
38
|
end
|
|
38
39
|
|
|
39
|
-
# Remove
|
|
40
|
-
converted.delete(
|
|
40
|
+
# Remove flags when false
|
|
41
|
+
%i[mapper show_config].each { converted.delete(it) unless converted[it] }
|
|
41
42
|
end
|
|
42
43
|
end
|
|
43
44
|
|
data/lib/usps/imis/config.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
|
|
3
5
|
require_relative 'logger'
|
|
4
6
|
require_relative 'logger_formatter'
|
|
5
7
|
require_relative 'logger_helpers'
|
|
@@ -45,6 +47,23 @@ module Usps
|
|
|
45
47
|
@logger = ActiveSupport::TaggedLogging.new(@base_logger)
|
|
46
48
|
end
|
|
47
49
|
|
|
50
|
+
def global_logger
|
|
51
|
+
return @global_logger if @global_logger
|
|
52
|
+
|
|
53
|
+
global_log_path
|
|
54
|
+
@global_logger
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def global_log_path
|
|
58
|
+
@global_log_path || self.global_log_path = '/var/log/imis/imis.log'
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def global_log_path=(path)
|
|
62
|
+
@global_log_path = path
|
|
63
|
+
@global_logger = build_global_logger
|
|
64
|
+
global_log_path
|
|
65
|
+
end
|
|
66
|
+
|
|
48
67
|
def silence!
|
|
49
68
|
self.logger = Logger.new(nil)
|
|
50
69
|
end
|
|
@@ -62,7 +81,7 @@ module Usps
|
|
|
62
81
|
|
|
63
82
|
# Ruby 3.5 instance variable filter
|
|
64
83
|
#
|
|
65
|
-
def instance_variables_to_inspect = instance_variables - %i[@password @base_logger @logger]
|
|
84
|
+
def instance_variables_to_inspect = instance_variables - %i[@password @base_logger @logger @global_logger]
|
|
66
85
|
|
|
67
86
|
# Parameters to filter out of logging
|
|
68
87
|
#
|
|
@@ -82,6 +101,23 @@ module Usps
|
|
|
82
101
|
|
|
83
102
|
ActiveSupport::StringInquirer.new(ENV.fetch('IMIS_ENVIRONMENT', 'development'))
|
|
84
103
|
end
|
|
104
|
+
|
|
105
|
+
def build_global_logger
|
|
106
|
+
writable =
|
|
107
|
+
begin
|
|
108
|
+
FileUtils.mkdir_p(File.dirname(global_log_path))
|
|
109
|
+
File.writable?(global_log_path) || File.writable?(File.dirname(global_log_path))
|
|
110
|
+
rescue StandardError
|
|
111
|
+
false
|
|
112
|
+
end
|
|
113
|
+
return ActiveSupport::TaggedLogging.new(::Logger.new(nil)) unless writable
|
|
114
|
+
|
|
115
|
+
ActiveSupport::TaggedLogging.new(
|
|
116
|
+
::Logger
|
|
117
|
+
.new(File.open(global_log_path, 'a'), level: :debug)
|
|
118
|
+
.tap { it.formatter = LoggerFormatter.new }
|
|
119
|
+
)
|
|
120
|
+
end
|
|
85
121
|
end
|
|
86
122
|
end
|
|
87
123
|
end
|
data/lib/usps/imis/logger.rb
CHANGED
|
@@ -14,6 +14,15 @@ module Usps
|
|
|
14
14
|
super
|
|
15
15
|
self.formatter = LoggerFormatter.new
|
|
16
16
|
end
|
|
17
|
+
|
|
18
|
+
# Also send logger methods to the global logger
|
|
19
|
+
#
|
|
20
|
+
%w[debug info warn error fatal unknown].each do |method|
|
|
21
|
+
define_method(method) do |message|
|
|
22
|
+
super(message)
|
|
23
|
+
Usps::Imis.config.global_logger.tagged(formatter.current_tags).public_send(method, message)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
17
26
|
end
|
|
18
27
|
end
|
|
19
28
|
end
|
data/lib/usps/imis/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.11.36
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Julian Fiander
|
|
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
133
133
|
- !ruby/object:Gem::Version
|
|
134
134
|
version: '0'
|
|
135
135
|
requirements: []
|
|
136
|
-
rubygems_version: 4.0.
|
|
136
|
+
rubygems_version: 4.0.9
|
|
137
137
|
specification_version: 4
|
|
138
138
|
summary: iMIS API Wrapper
|
|
139
139
|
test_files: []
|