usps-imis-api 0.11.18 → 0.11.20
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/lib/usps/imis/api.rb +20 -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/config.rb +8 -0
- 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: 1b704d2eaa3bdb496f4e575b19fff48a0a8d61bb14033ac92ee56910772e72fc
|
|
4
|
+
data.tar.gz: f2772a7590150c7f342530e2d008d773680abac4372625f226b512bd3357c8c1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ea13f8318a6f0424158973f42eff29903b556764f4fb94e85d415f68109a09593f19acd6e9f9db9350b6a6c25f2f6bfb7ae12848501b32048a8063ce47fc0678
|
|
7
|
+
data.tar.gz: 20f05f14c38428f0c33d055df86bbb47263e7aebef7478b13eee5e6ad5f93c949b46921bf5f34792e9dd4add55f5ec43783ad4b941f83d73015bbc9989453cf0
|
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
|
|
@@ -45,6 +56,7 @@ module Usps
|
|
|
45
56
|
def initialize(imis_id: nil)
|
|
46
57
|
self.imis_id = imis_id if imis_id
|
|
47
58
|
@logger ||= Imis.logger('Api')
|
|
59
|
+
Imis.config.validate!
|
|
48
60
|
end
|
|
49
61
|
|
|
50
62
|
# Manually set the current ID, if you already have it for a given member
|
|
@@ -190,6 +202,14 @@ module Usps
|
|
|
190
202
|
@panels ||= Panels.all(self)
|
|
191
203
|
end
|
|
192
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
|
+
|
|
193
213
|
# Ruby 3.5 instance variable filter
|
|
194
214
|
#
|
|
195
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
|
data/lib/usps/imis/config.rb
CHANGED
|
@@ -11,6 +11,7 @@ module Usps
|
|
|
11
11
|
class Config
|
|
12
12
|
IMIS_ROOT_URL_PROD = 'https://portal.americasboatingclub.org'
|
|
13
13
|
IMIS_ROOT_URL_DEV = 'https://abcdev.imiscloud.com'
|
|
14
|
+
REQUIRED_CONFIGS = %w[imis_id_query_name username password].freeze
|
|
14
15
|
|
|
15
16
|
attr_accessor :imis_id_query_name, :username, :password
|
|
16
17
|
attr_reader :environment, :logger, :logger_level
|
|
@@ -61,6 +62,13 @@ module Usps
|
|
|
61
62
|
#
|
|
62
63
|
def filtered_parameters = %i[password]
|
|
63
64
|
|
|
65
|
+
def validate!
|
|
66
|
+
missing_config = REQUIRED_CONFIGS.filter_map { it if public_send(it).nil? }
|
|
67
|
+
return if missing_config.empty?
|
|
68
|
+
|
|
69
|
+
raise Errors::ConfigError, "Missing required configuration: #{missing_config.join(', ')}"
|
|
70
|
+
end
|
|
71
|
+
|
|
64
72
|
private
|
|
65
73
|
|
|
66
74
|
def default_environment
|
data/lib/usps/imis/version.rb
CHANGED