usps-imis-api 0.11.6 → 0.11.8
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/command_line/interface.rb +20 -8
- data/lib/usps/imis/command_line/options_parser.rb +28 -26
- data/lib/usps/imis/query.rb +8 -3
- data/lib/usps/imis/version.rb +1 -1
- data/lib/usps/imis.rb +1 -0
- 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: 5cb250d5dd836f5ca8b2382bcc45e788d57307dc47800337d59ff2976b4c52dd
|
|
4
|
+
data.tar.gz: 65c492cb9bec04a98be6aa8c5821cda5f3bf28304b91fb9202c13c95ab21ae67
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 764a6555ba593dc6e7b6b159aa741d9866f9981278fc1d4b7820d3a83efaa0ff5ddfff8eb93c7f2d09868853251db89163471582ed4a8f0086809c824823703d
|
|
7
|
+
data.tar.gz: 949e90aa4c506455184fd162cc75fb6b8a45c8c98b4e3561e3656d2445ca32b5174c6bd14164d51108fb5c69d7275a30a8cb06eda04ee480290eacb77524a6bd
|
|
@@ -65,9 +65,9 @@ module Usps
|
|
|
65
65
|
# rubocop:disable Metrics
|
|
66
66
|
def perform!
|
|
67
67
|
case convert(options)
|
|
68
|
-
in mapper
|
|
69
|
-
in mapper
|
|
70
|
-
in mapper
|
|
68
|
+
in mapper:, field:, data: then mapper.put_field(field.to_sym, data)
|
|
69
|
+
in mapper:, field: then mapper.fetch(field.to_sym)
|
|
70
|
+
in mapper:, data: then mapper.update(data)
|
|
71
71
|
|
|
72
72
|
in on:, delete: true then on.delete
|
|
73
73
|
in on:, post: true, data: then on.post(data)
|
|
@@ -96,21 +96,31 @@ module Usps
|
|
|
96
96
|
def convert(options)
|
|
97
97
|
options.dup.tap do |converted|
|
|
98
98
|
case converted
|
|
99
|
-
in map: then converted.merge!(mapper:
|
|
99
|
+
in map: then converted.merge!(mapper: api.mapper, field: map)
|
|
100
|
+
in mapper: true then converted[:mapper] = api.mapper
|
|
100
101
|
in on: then converted[:on] = api.on(on)
|
|
101
102
|
in panel: then converted[:panel] = api.panels.public_send(panel)
|
|
102
103
|
else
|
|
103
104
|
# Nothing to convert
|
|
104
105
|
end
|
|
106
|
+
|
|
107
|
+
# Remove mapper flag when false
|
|
108
|
+
converted.delete(:mapper) unless converted[:mapper]
|
|
105
109
|
end
|
|
106
110
|
end
|
|
107
111
|
|
|
108
112
|
def simplify(data)
|
|
109
113
|
return data.to_a if data.is_a?(Query)
|
|
110
114
|
return data if options[:raw]
|
|
111
|
-
return data unless data.is_a?(Hash) # Includes Usps::Imis::Data
|
|
112
115
|
|
|
113
|
-
|
|
116
|
+
# Hash includes Usps::Imis::Data
|
|
117
|
+
if data.is_a?(Hash)
|
|
118
|
+
data.properties(include_ids: options[:include_ids])
|
|
119
|
+
elsif data.is_a?(Array) && data.all? { it.is_a?(Hash) }
|
|
120
|
+
data.map { it.properties(include_ids: options[:include_ids]) }
|
|
121
|
+
else
|
|
122
|
+
data
|
|
123
|
+
end
|
|
114
124
|
end
|
|
115
125
|
|
|
116
126
|
# :nocov:
|
|
@@ -121,11 +131,13 @@ module Usps
|
|
|
121
131
|
end
|
|
122
132
|
# :nocov:
|
|
123
133
|
|
|
134
|
+
# Supports YAML or JSON config data
|
|
135
|
+
#
|
|
124
136
|
def configure!
|
|
125
|
-
|
|
137
|
+
config_data = YAML.safe_load_file(options[:config])
|
|
126
138
|
|
|
127
139
|
Usps::Imis.configure do |config|
|
|
128
|
-
|
|
140
|
+
config_data.each do |key, value|
|
|
129
141
|
config.public_send("#{key}=", value)
|
|
130
142
|
end
|
|
131
143
|
end
|
|
@@ -13,25 +13,42 @@ module Usps
|
|
|
13
13
|
panel: ['Panel name', { type: :string }],
|
|
14
14
|
ordinal: ['Ordinal ID within a Panel', { type: :integer }],
|
|
15
15
|
query: ['IQA Query or Business Object name to query', { type: :string, short: :Q }],
|
|
16
|
+
mapper: ['Interact with mapped fields', { short: :M }],
|
|
17
|
+
map: ["Shorthand for accessing a single mapped field\n Equivalent to #{'-Mf'.green}", { type: :string }],
|
|
16
18
|
post: ["Send a #{'POST'.cyan} request", { short: :P }],
|
|
17
19
|
delete: ["Send a #{'DELETE'.cyan} request", { short: :D }],
|
|
18
20
|
field: ['Specific field to return or update', { type: :string }],
|
|
19
21
|
fields: ['Specific field(s) to return', { type: :strings, short: :F }],
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
data: ['JSON string input', { type: :string }],
|
|
23
|
-
config: ['Path to the JSON config file to use', { type: :string, short: :C }],
|
|
22
|
+
data: ["JSON string input\n When present, sets the default HTTP verb to #{'PUT'.cyan}", { type: :string }],
|
|
23
|
+
config: ['Path to the JSON/YAML config file to use', { type: :string, short: :C }],
|
|
24
24
|
raw: ['Return raw JSON output, rather than simplified data', { short: :R }],
|
|
25
|
-
include_ids: [
|
|
26
|
-
quiet: [
|
|
27
|
-
log: [
|
|
25
|
+
include_ids: ["Include #{'iMIS ID'.yellow} and #{'Ordinal'.yellow} properties in returned data, if present"],
|
|
26
|
+
quiet: ["Suppress logging to #{'STDERR'.red}"],
|
|
27
|
+
log: ["Redirect logging to #{'STDOUT'.red}"],
|
|
28
28
|
log_level: ['Set the logging level', { type: :string, default: 'info', short: :L }]
|
|
29
29
|
}.freeze
|
|
30
30
|
|
|
31
31
|
CONFLICTING_OPTION_GROUPS = [
|
|
32
32
|
%i[certificate id],
|
|
33
33
|
%i[on panel query map],
|
|
34
|
-
%i[field fields map query]
|
|
34
|
+
%i[field fields map query],
|
|
35
|
+
%i[raw include_ids],
|
|
36
|
+
%i[quiet log_level],
|
|
37
|
+
%i[quiet log],
|
|
38
|
+
|
|
39
|
+
%i[post delete],
|
|
40
|
+
|
|
41
|
+
%i[post mapper],
|
|
42
|
+
%i[post query],
|
|
43
|
+
%i[post map],
|
|
44
|
+
|
|
45
|
+
%i[delete mapper],
|
|
46
|
+
%i[delete query],
|
|
47
|
+
%i[delete map]
|
|
48
|
+
].freeze
|
|
49
|
+
|
|
50
|
+
DEPENDENT_OPTION_PAIRS = [
|
|
51
|
+
%i[ordinal panel]
|
|
35
52
|
].freeze
|
|
36
53
|
|
|
37
54
|
attr_reader :arguments, :options
|
|
@@ -56,25 +73,9 @@ module Usps
|
|
|
56
73
|
|
|
57
74
|
#{'Configuration'.underline}
|
|
58
75
|
|
|
59
|
-
API configuration
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
With #{'--config'.green}/#{'-C'.green} given the path to a JSON file, e.g.:
|
|
63
|
-
|
|
64
|
-
{
|
|
65
|
-
"imis_id_query_name": "#{'$/IQA_QUERY_NAME'.yellow}",
|
|
66
|
-
"environment": "#{'development'.yellow}",
|
|
67
|
-
"username": "#{'USERNAME'.yellow}",
|
|
68
|
-
"password": "#{'PASSWORD'.yellow}"
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
By setting the following environment variables:
|
|
76
|
+
For an explanation of how to provide API configuration, please refer to the wiki:
|
|
73
77
|
|
|
74
|
-
#
|
|
75
|
-
#{'IMIS_ENVIRONMENT'.yellow}
|
|
76
|
-
#{'IMIS_USERNAME'.yellow}
|
|
77
|
-
#{'IMIS_PASSWORD'.yellow}
|
|
78
|
+
https://github.com/unitedstatespowersquadrons/imis-api-ruby/wiki/Usage#command-line-interface
|
|
78
79
|
|
|
79
80
|
|
|
80
81
|
#{'Options'.underline}
|
|
@@ -103,6 +104,7 @@ module Usps
|
|
|
103
104
|
|
|
104
105
|
OPTIONS.each { |option, data| opt(option, *data) }
|
|
105
106
|
CONFLICTING_OPTION_GROUPS.each { |group| conflicts(*group) }
|
|
107
|
+
DEPENDENT_OPTION_PAIRS.each { |pair| depends(*pair) }
|
|
106
108
|
|
|
107
109
|
educate_on_error
|
|
108
110
|
end
|
data/lib/usps/imis/query.rb
CHANGED
|
@@ -52,7 +52,6 @@ module Usps
|
|
|
52
52
|
@api = api
|
|
53
53
|
@query_name = query_name
|
|
54
54
|
@query_params = query_params
|
|
55
|
-
@query_params.merge!(QueryName: query_name) if iqa?
|
|
56
55
|
@page_size = page_size
|
|
57
56
|
@offset = offset
|
|
58
57
|
@count = 0
|
|
@@ -137,10 +136,16 @@ module Usps
|
|
|
137
136
|
def iqa? = query_name.match?(/^\$/)
|
|
138
137
|
def query_type = iqa? ? :IQA : :'Business Object'
|
|
139
138
|
def path_params = query_params.merge({ Offset: offset, Limit: page_size }.compact)
|
|
140
|
-
def endpoint = iqa? ? IQA_PATH : "#{Imis::BusinessObject::API_PATH}/#{query_name}"
|
|
141
|
-
def path = "#{endpoint}?#{path_params.to_query}"
|
|
142
139
|
def uri = URI(File.join(Imis.configuration.hostname, path))
|
|
143
140
|
|
|
141
|
+
def path
|
|
142
|
+
if iqa?
|
|
143
|
+
"#{IQA_PATH}?#{path_params.merge(QueryName: query_name).to_query}"
|
|
144
|
+
else
|
|
145
|
+
"#{Imis::BusinessObject::API_PATH}/#{query_name}?#{path_params.to_query}"
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
144
149
|
def logger = Imis.logger("#{query_type} Query")
|
|
145
150
|
end
|
|
146
151
|
end
|
data/lib/usps/imis/version.rb
CHANGED
data/lib/usps/imis.rb
CHANGED