usps-imis-api 0.11.19 → 0.11.21
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 +4 -2
- data/lib/usps/imis/api.rb +19 -0
- data/lib/usps/imis/command_line/interface.rb +19 -5
- data/lib/usps/imis/command_line/options_parser.rb +5 -7
- data/lib/usps/imis/logger_formatter.rb +3 -1
- data/lib/usps/imis/version.rb +1 -1
- 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: 35b16ade1f6397b66b62731eb83a514ef1fa4a1e4ef656f639a153ecb1bbc8a5
|
|
4
|
+
data.tar.gz: b0b191774bd37dcea2342ff8fa5349a06bfb62de69cb1835316bc522367bbda9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7604ac9a7672a37fa47cd6d5585d54e54f2a5bcf8853fb4200ceb54c20db0c24e16b5036f94ced091fa9523cf2157934bb840c6f171ec4b567113f50f1423ea3
|
|
7
|
+
data.tar.gz: cc021585df733a3dc596cbd54486655b297290665128b1f4fa362976e9274d2b4b572ae88417f3fd17f9cd33a3352e62a64726e9c9357e1801629be93c150b94
|
data/Readme.md
CHANGED
|
@@ -82,5 +82,7 @@ file to [rubygems.org](https://rubygems.org).
|
|
|
82
82
|
|
|
83
83
|
## PHP
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
[available for PHP](https://github.com/unitedstatespowersquadrons/imis-api).
|
|
85
|
+
A wrapper for the CLI from this API is
|
|
86
|
+
[available for PHP](https://github.com/unitedstatespowersquadrons/imis-api-php).
|
|
87
|
+
|
|
88
|
+
You can also view the [original PHP API](https://github.com/unitedstatespowersquadrons/imis-api).
|
data/lib/usps/imis/api.rb
CHANGED
|
@@ -38,6 +38,17 @@ module Usps
|
|
|
38
38
|
#
|
|
39
39
|
attr_reader :logger
|
|
40
40
|
|
|
41
|
+
# Create a new instance of +Api+ and provide an existing auth token
|
|
42
|
+
#
|
|
43
|
+
# @param token [String] Auth token
|
|
44
|
+
#
|
|
45
|
+
def self.with_token(token)
|
|
46
|
+
new.tap do |api|
|
|
47
|
+
api.instance_variable_set(:@token, token)
|
|
48
|
+
api.instance_variable_set(:@token_expiration, Time.now + 3600) # Greater than the actual lifetime of the token
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
41
52
|
# A new instance of +Api+
|
|
42
53
|
#
|
|
43
54
|
# @param imis_id [Integer, String] iMIS ID to select immediately on initialization
|
|
@@ -191,6 +202,14 @@ module Usps
|
|
|
191
202
|
@panels ||= Panels.all(self)
|
|
192
203
|
end
|
|
193
204
|
|
|
205
|
+
# Used by the PHP Wrapper to reduce authentication requests
|
|
206
|
+
#
|
|
207
|
+
def auth_token
|
|
208
|
+
authenticate
|
|
209
|
+
|
|
210
|
+
{ token: @token, token_expiration: @token_expiration }
|
|
211
|
+
end
|
|
212
|
+
|
|
194
213
|
# Ruby 3.5 instance variable filter
|
|
195
214
|
#
|
|
196
215
|
def instance_variables_to_inspect = %i[@token_expiration @imis_id]
|
|
@@ -8,6 +8,11 @@ module Usps
|
|
|
8
8
|
class Interface
|
|
9
9
|
NAME = 'USPS iMIS API - Ruby'
|
|
10
10
|
|
|
11
|
+
# CLI options that indicate the response is a raw Hash rather than a Data object,
|
|
12
|
+
# and should not be simplified
|
|
13
|
+
#
|
|
14
|
+
RAW_HASH_RESPONSE_OPTIONS = %i[business_objects auth_token].freeze
|
|
15
|
+
|
|
11
16
|
# Options passed in from the command line
|
|
12
17
|
#
|
|
13
18
|
attr_reader :options
|
|
@@ -29,7 +34,7 @@ module Usps
|
|
|
29
34
|
def run
|
|
30
35
|
logger.info 'Running'
|
|
31
36
|
logger.debug 'CLI Options:'
|
|
32
|
-
logger.json
|
|
37
|
+
logger.json(options.dup.tap { it[:token] = '[FILTERED]' if it[:token] })
|
|
33
38
|
|
|
34
39
|
set_member
|
|
35
40
|
|
|
@@ -61,7 +66,12 @@ module Usps
|
|
|
61
66
|
# :nocov:
|
|
62
67
|
|
|
63
68
|
def api
|
|
64
|
-
@api ||=
|
|
69
|
+
@api ||=
|
|
70
|
+
if options[:token]
|
|
71
|
+
Usps::Imis::Api.with_token(options[:token])
|
|
72
|
+
else
|
|
73
|
+
Usps::Imis::Api.new
|
|
74
|
+
end
|
|
65
75
|
end
|
|
66
76
|
|
|
67
77
|
def set_member
|
|
@@ -72,7 +82,7 @@ module Usps
|
|
|
72
82
|
# Query
|
|
73
83
|
end
|
|
74
84
|
|
|
75
|
-
logger.debug "iMIS ID: #{api.imis_id}"
|
|
85
|
+
logger.debug "iMIS ID: #{api.imis_id}" if api.imis_id
|
|
76
86
|
end
|
|
77
87
|
|
|
78
88
|
# rubocop:disable Metrics
|
|
@@ -103,6 +113,10 @@ module Usps
|
|
|
103
113
|
in query: then api.query(query)
|
|
104
114
|
|
|
105
115
|
in business_objects: true then api.business_objects
|
|
116
|
+
|
|
117
|
+
in auth_token: true then api.auth_token
|
|
118
|
+
|
|
119
|
+
in certificate: then api.imis_id
|
|
106
120
|
end
|
|
107
121
|
rescue NoMatchingPatternError => e
|
|
108
122
|
raise Errors::CommandLineError, "Unable to match pattern from options: #{e.message}"
|
|
@@ -127,10 +141,10 @@ module Usps
|
|
|
127
141
|
|
|
128
142
|
def simplify(data)
|
|
129
143
|
return data.to_a if data.is_a?(Query)
|
|
130
|
-
return data if options[:raw]
|
|
144
|
+
return data if options[:raw] || RAW_HASH_RESPONSE_OPTIONS.any? { options[it] }
|
|
131
145
|
|
|
132
146
|
# Hash includes Usps::Imis::Data
|
|
133
|
-
if data.is_a?(Hash)
|
|
147
|
+
if data.is_a?(Hash)
|
|
134
148
|
logger.debug 'Returning simplified Data#properties'
|
|
135
149
|
data.properties(include_ids: options[:include_ids])
|
|
136
150
|
elsif data.is_a?(Array) && data.all? { it.is_a?(Hash) }
|
|
@@ -29,6 +29,10 @@ module Usps
|
|
|
29
29
|
fields: ['Specific field(s) to return', { type: :strings, short: :F }],
|
|
30
30
|
data: ['JSON string input', { type: :string }],
|
|
31
31
|
|
|
32
|
+
# Iteractions for supporting other language wrappers
|
|
33
|
+
auth_token: ['Return an auth token for other language wrappers', { short: :T }],
|
|
34
|
+
token: ['Provide an existing auth token', { type: :string }],
|
|
35
|
+
|
|
32
36
|
# General config
|
|
33
37
|
config: ['Path to the JSON/YAML config file to use', { type: :string, short: :C }],
|
|
34
38
|
raw: ['Return raw JSON output, rather than simplified data', { short: :R }],
|
|
@@ -40,7 +44,7 @@ module Usps
|
|
|
40
44
|
|
|
41
45
|
CONFLICTING_OPTION_GROUPS = [
|
|
42
46
|
%i[certificate id],
|
|
43
|
-
%i[on panel query mapper map business_objects],
|
|
47
|
+
%i[on panel query mapper map business_objects auth_token],
|
|
44
48
|
%i[field fields map query],
|
|
45
49
|
%i[raw include_ids],
|
|
46
50
|
%i[quiet log_level],
|
|
@@ -63,11 +67,6 @@ module Usps
|
|
|
63
67
|
%i[delete raw]
|
|
64
68
|
].freeze
|
|
65
69
|
|
|
66
|
-
DEPENDENT_OPTION_PAIRS = [
|
|
67
|
-
%i[ordinal panel],
|
|
68
|
-
%i[create data]
|
|
69
|
-
].freeze
|
|
70
|
-
|
|
71
70
|
attr_reader :arguments, :options
|
|
72
71
|
|
|
73
72
|
def self.banner_header(version)
|
|
@@ -118,7 +117,6 @@ module Usps
|
|
|
118
117
|
|
|
119
118
|
OPTIONS.each { |option, data| opt(option, *data) }
|
|
120
119
|
CONFLICTING_OPTION_GROUPS.each { |group| conflicts(*group) }
|
|
121
|
-
DEPENDENT_OPTION_PAIRS.each { |pair| depends(*pair) }
|
|
122
120
|
|
|
123
121
|
educate_on_error
|
|
124
122
|
end
|
|
@@ -5,6 +5,8 @@ module Usps
|
|
|
5
5
|
# Formats log statements
|
|
6
6
|
#
|
|
7
7
|
class LoggerFormatter < ::Logger::Formatter
|
|
8
|
+
include ::ActiveSupport::TaggedLogging::Formatter
|
|
9
|
+
|
|
8
10
|
def call(severity, time, _progname, message)
|
|
9
11
|
log_chunks = [
|
|
10
12
|
format('%-5s', severity.to_s),
|
|
@@ -14,7 +16,7 @@ module Usps
|
|
|
14
16
|
'|',
|
|
15
17
|
formatted_tags,
|
|
16
18
|
'|',
|
|
17
|
-
message.sub(/^#{Regexp.escape(tags_text)}/, '')
|
|
19
|
+
message.to_s.sub(/^#{Regexp.escape(tags_text)}/, '')
|
|
18
20
|
]
|
|
19
21
|
"#{log_chunks.join(' ')}\n"
|
|
20
22
|
end
|
data/lib/usps/imis/version.rb
CHANGED