usps-imis-api 0.11.34 → 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: 898b26512f82544ff037e289bfe2466ac375bfa481a0c7ebf77d5d6c2d9ecf96
4
- data.tar.gz: 1a01816c119999a2ca2e8b01ae75c83df028a9d2cc1542b174b23a2e49f2877e
3
+ metadata.gz: 4f2d6d71152c72004f40542113b03d5f4f064a9f65ed7dd233d2edbf15051b6f
4
+ data.tar.gz: 94223bd8ea659905b2bc031d066b2e54f4e7944114c8d57de9682265f1eddf11
5
5
  SHA512:
6
- metadata.gz: 89ff926322610bc6eefaf4aa605d7ecc498d1240f577a39e8a3267ab923d744f6364c73da84afeb65eb8672114d315a043c7a5d3d492b10f788c5734f1be13b4
7
- data.tar.gz: 5858b73de1805cc9ee93527964b9220c2bd3c7b91075913103adff9a36994e018f8ac2c40404e80d8afeda314c3e7d4e6ab6e5ea4ba82c12022d67347c3a6bd3
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! if options[:config]
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? { it.is_a?(Hash) }
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
@@ -141,7 +152,9 @@ module Usps
141
152
  # Supports YAML or JSON config data
142
153
  #
143
154
  def configure!
144
- config_data = YAML.safe_load_file(options[:config])
155
+ return if config_path.nil?
156
+
157
+ config_data = YAML.safe_load_file(config_path)
145
158
 
146
159
  Usps::Imis.configure do |config|
147
160
  config_data.each do |key, value|
@@ -150,6 +163,13 @@ module Usps
150
163
  end
151
164
  end
152
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
+
153
173
  def logging!
154
174
  Usps::Imis.configure do |config|
155
175
  # :nocov:
@@ -36,7 +36,16 @@ module Usps
36
36
  token: ['Provide an existing auth token', { type: :string }],
37
37
 
38
38
  # General config
39
- config: ['Path to the JSON/YAML config file to use', { type: :string, short: :C }],
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"],
42
51
  jsonl: ['Format array output as JSONL', { short: :j }],
@@ -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? { it.is_a?(String) }
84
+ elsif value.all?(String)
85
85
  # Do nothing
86
86
  else
87
87
  hash[key] = format_extracted(value.to_h)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Imis
5
- VERSION = '0.11.34'
5
+ VERSION = '0.11.35'
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.34
4
+ version: 0.11.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander