usps-imis-api 0.11.33 → 0.11.35
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4f2d6d71152c72004f40542113b03d5f4f064a9f65ed7dd233d2edbf15051b6f
|
|
4
|
+
data.tar.gz: 94223bd8ea659905b2bc031d066b2e54f4e7944114c8d57de9682265f1eddf11
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8b35d80cf5601afba8902cb4a337fea33e5b39ed85dcee157372aab50456a413beae2586b5c773120551d0ebc6de1a3b4e1c85af4fa25896a470708c85db369e
|
|
7
|
+
data.tar.gz: 043b2029ab1c8d72033dfa67d4a4f7b988accc745315c30bb62285fd1746482fa626923c821bcfd4029d58a2006aa4631167bff0b749f9ed83e1500bb5fb5f4f
|
|
@@ -12,6 +12,17 @@ module Usps
|
|
|
12
12
|
|
|
13
13
|
NAME = 'USPS iMIS API - Ruby'
|
|
14
14
|
|
|
15
|
+
# Prioritized list of config file paths to automatically check if not provided
|
|
16
|
+
#
|
|
17
|
+
CONFIG_PATHS = {
|
|
18
|
+
local_dot: File.join(Dir.pwd, '.imis.yml'),
|
|
19
|
+
local: File.join(Dir.pwd, 'imis.yml'),
|
|
20
|
+
local_dot_config: File.join(Dir.pwd, '.config', 'imis.yml'),
|
|
21
|
+
local_config: File.join(Dir.pwd, 'config', 'imis.yml'),
|
|
22
|
+
user: "#{Dir.home}/.config/imis.yml",
|
|
23
|
+
system: '/usr/local/imis/config.yml'
|
|
24
|
+
}.freeze
|
|
25
|
+
|
|
15
26
|
# CLI options that indicate the response is a raw Hash rather than a Data object,
|
|
16
27
|
# and should not be simplified
|
|
17
28
|
#
|
|
@@ -39,7 +50,7 @@ module Usps
|
|
|
39
50
|
@options = input_options.merge(**)
|
|
40
51
|
options[:version] = true if default_options?
|
|
41
52
|
|
|
42
|
-
configure!
|
|
53
|
+
configure!
|
|
43
54
|
logging!
|
|
44
55
|
@logger ||= Imis.logger('CommandLine')
|
|
45
56
|
end
|
|
@@ -111,7 +122,7 @@ module Usps
|
|
|
111
122
|
# Hash includes Usps::Imis::Data
|
|
112
123
|
logger.debug 'Returning simplified Data#properties'
|
|
113
124
|
data.properties(include_ids: options[:include_ids])
|
|
114
|
-
elsif data.is_a?(Array) && data.all?
|
|
125
|
+
elsif data.is_a?(Array) && data.all?(Hash)
|
|
115
126
|
logger.debug 'Returning simplified Array<Data#properties>'
|
|
116
127
|
data.map { it.properties(include_ids: options[:include_ids]) }
|
|
117
128
|
else
|
|
@@ -126,14 +137,24 @@ module Usps
|
|
|
126
137
|
return
|
|
127
138
|
end
|
|
128
139
|
|
|
129
|
-
|
|
140
|
+
return unless block_given?
|
|
141
|
+
|
|
142
|
+
value = yield
|
|
143
|
+
|
|
144
|
+
if value.is_a?(Array) && @options[:jsonl]
|
|
145
|
+
puts(value.map { JSON.dump(it) })
|
|
146
|
+
else
|
|
147
|
+
puts JSON.dump(value)
|
|
148
|
+
end
|
|
130
149
|
end
|
|
131
150
|
# :nocov:
|
|
132
151
|
|
|
133
152
|
# Supports YAML or JSON config data
|
|
134
153
|
#
|
|
135
154
|
def configure!
|
|
136
|
-
|
|
155
|
+
return if config_path.nil?
|
|
156
|
+
|
|
157
|
+
config_data = YAML.safe_load_file(config_path)
|
|
137
158
|
|
|
138
159
|
Usps::Imis.configure do |config|
|
|
139
160
|
config_data.each do |key, value|
|
|
@@ -142,6 +163,13 @@ module Usps
|
|
|
142
163
|
end
|
|
143
164
|
end
|
|
144
165
|
|
|
166
|
+
def config_path
|
|
167
|
+
return @config_path if @config_path
|
|
168
|
+
return @config_path = CONFIG_PATHS.values.find { File.exist?(it) } if options[:config].nil?
|
|
169
|
+
|
|
170
|
+
@config_path = CONFIG_PATHS[options[:config].to_sym] || options[:config]
|
|
171
|
+
end
|
|
172
|
+
|
|
145
173
|
def logging!
|
|
146
174
|
Usps::Imis.configure do |config|
|
|
147
175
|
# :nocov:
|
|
@@ -36,9 +36,19 @@ module Usps
|
|
|
36
36
|
token: ['Provide an existing auth token', { type: :string }],
|
|
37
37
|
|
|
38
38
|
# General config
|
|
39
|
-
config: [
|
|
39
|
+
config: [
|
|
40
|
+
'Path to the JSON/YAML config file to use, or one of the following preset options: ' \
|
|
41
|
+
"`#{'local'.yellow}`, " \
|
|
42
|
+
"`#{'local_dot_config'.yellow}`, " \
|
|
43
|
+
"`#{'local_config'.yellow}`, " \
|
|
44
|
+
"`#{'user'.yellow}`, " \
|
|
45
|
+
"`#{'system'.yellow}`. " \
|
|
46
|
+
'If no option is provided, the first matching preset option will be automatically used.',
|
|
47
|
+
{ type: :string, short: :C }
|
|
48
|
+
],
|
|
40
49
|
raw: ['Return raw JSON output, rather than simplified data', { short: :R }],
|
|
41
50
|
include_ids: ["Include any #{'iMIS ID'.yellow} and #{'Ordinal'.yellow} properties in returned data"],
|
|
51
|
+
jsonl: ['Format array output as JSONL', { short: :j }],
|
|
42
52
|
quiet: ["Suppress logging to #{'STDERR'.red}"],
|
|
43
53
|
log: ["Redirect logging to #{'STDOUT'.red}"],
|
|
44
54
|
log_level: ['Set the logging level', { type: :string, default: 'info', short: :L }]
|
data/lib/usps/imis/party_data.rb
CHANGED
|
@@ -81,7 +81,7 @@ module Usps
|
|
|
81
81
|
|
|
82
82
|
if %w[Addresses AlternateIds CommunicationPreferences Emails Salutations].include?(key)
|
|
83
83
|
hash[key] = value.map { format_extracted(it.to_h) }
|
|
84
|
-
elsif value.all?
|
|
84
|
+
elsif value.all?(String)
|
|
85
85
|
# Do nothing
|
|
86
86
|
else
|
|
87
87
|
hash[key] = format_extracted(value.to_h)
|
data/lib/usps/imis/version.rb
CHANGED