usps-imis-api 0.12.4 → 0.12.6
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: 856bf739e0e0b82c34436be2f0bf897d442a8080513f12f387204f0a5a5e095d
|
|
4
|
+
data.tar.gz: 655004a782af3a21ae1224678c34dcd9936f71b943af1d657579a7bf4991bbf4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ba31e19e7a0fd96800c83f7727b000acbcea80066c8edcabcf03f4cf020066e65573127f20a07f6fe155b807b25b531c8179d11a0e1adc6082a3566186c57724
|
|
7
|
+
data.tar.gz: 5b9e6900ff14f31d1eab9d00ba559861790ae89b6f09b2a29df3a81de149bbd62f681df57a3b09e03725bfcf4e607a6c5a0d63102178f757eabd9be0fe33006f
|
|
@@ -46,24 +46,30 @@ module Usps
|
|
|
46
46
|
|
|
47
47
|
value = yield
|
|
48
48
|
|
|
49
|
+
puts format_output(value)
|
|
50
|
+
end
|
|
51
|
+
# :nocov:
|
|
52
|
+
|
|
53
|
+
def format_output(value)
|
|
49
54
|
if value.is_a?(Array) && @options[:jsonl] then jsonl(value)
|
|
50
55
|
elsif value.is_a?(Array) && @options[:csv] then csv(value)
|
|
51
|
-
else
|
|
56
|
+
else json(value)
|
|
52
57
|
end
|
|
53
58
|
end
|
|
54
59
|
|
|
55
|
-
def
|
|
60
|
+
def json(value) = JSON.dump(value)
|
|
56
61
|
|
|
57
|
-
def jsonl(value) =
|
|
62
|
+
def jsonl(value) = value.map { JSON.dump(it) }
|
|
58
63
|
|
|
59
64
|
def csv(value)
|
|
65
|
+
return '' if value.empty?
|
|
66
|
+
|
|
60
67
|
headers = value.first.keys if value.first.is_a?(Hash) || value.first.is_a?(BaseData)
|
|
61
68
|
|
|
62
|
-
|
|
69
|
+
CSV.generate(headers:, write_headers: !headers.nil?) do |csv|
|
|
63
70
|
headers ? value.each { csv << it } : csv << value
|
|
64
|
-
end
|
|
71
|
+
end
|
|
65
72
|
end
|
|
66
|
-
# :nocov:
|
|
67
73
|
end
|
|
68
74
|
end
|
|
69
75
|
end
|
|
@@ -110,7 +110,7 @@ include_ids:
|
|
|
110
110
|
- "Include any <%= 'iMIS ID'.yellow %> and <%= 'Ordinal'.yellow %> properties in returned data"
|
|
111
111
|
- short: N
|
|
112
112
|
|
|
113
|
-
#
|
|
113
|
+
# Interactions for supporting other language wrappers
|
|
114
114
|
auth_token:
|
|
115
115
|
- Return an auth token for other language wrappers
|
|
116
116
|
- short: T
|
|
@@ -105,8 +105,6 @@ module Usps
|
|
|
105
105
|
|
|
106
106
|
OptionsParser.options.each { |option, data| opt(option, *data) }
|
|
107
107
|
CONFLICTING_OPTION_GROUPS.each { |group| conflicts(*group) }
|
|
108
|
-
|
|
109
|
-
educate_on_error
|
|
110
108
|
end
|
|
111
109
|
end
|
|
112
110
|
|
|
@@ -116,10 +114,12 @@ module Usps
|
|
|
116
114
|
# :nocov:
|
|
117
115
|
|
|
118
116
|
def defaults?
|
|
119
|
-
options_with_defaults =
|
|
117
|
+
options_with_defaults = self.class.options.select { |_, data| data[1]&.key?(:default) }
|
|
118
|
+
|
|
119
|
+
default_options_not_given = options_with_defaults.none? { |option, _| @options[:"#{option}_given"] }
|
|
120
|
+
only_default_options_set = options.except(*options_with_defaults.keys).values.none?
|
|
120
121
|
|
|
121
|
-
|
|
122
|
-
options.except(*options_with_defaults.keys).values.none?
|
|
122
|
+
default_options_not_given && only_default_options_set
|
|
123
123
|
end
|
|
124
124
|
|
|
125
125
|
def pre_process_options!
|
|
@@ -129,6 +129,8 @@ module Usps
|
|
|
129
129
|
|
|
130
130
|
@options[:data] = JSON.parse(@options[:data]) if @options[:data]
|
|
131
131
|
|
|
132
|
+
validate_query_options!
|
|
133
|
+
|
|
132
134
|
raise Errors::CommandLineError, 'Maximum page size is 500' if @options[:page_size] > 500
|
|
133
135
|
|
|
134
136
|
@options[:offset] = (@options[:page] - 1) * @options[:page_size] if @options[:page]
|
|
@@ -136,8 +138,14 @@ module Usps
|
|
|
136
138
|
# Support shorthand for setting `certificate` param on queries
|
|
137
139
|
return unless @options[:query] && @options[:certificate]
|
|
138
140
|
|
|
139
|
-
@options[:data]
|
|
140
|
-
|
|
141
|
+
@options[:data] = { 'certificate' => @options.delete(:certificate) }
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def validate_query_options!
|
|
145
|
+
query_options = QUERY_FLAGS - [:query]
|
|
146
|
+
return unless !@options[:query] && query_options.any? { @options[:"#{it}_given"] }
|
|
147
|
+
|
|
148
|
+
Optimist.die(:query, "must be provided if any of --#{query_options.join(', --').gsub('_', '-')} are provided")
|
|
141
149
|
end
|
|
142
150
|
end
|
|
143
151
|
end
|
|
@@ -75,16 +75,11 @@ module Usps
|
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
def perform_query(query, **options)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
in page_size:, offset:, data: then api.query(query, page_size:, offset:, **data)
|
|
84
|
-
in page_size:, data: then api.query(query, page_size:, **data)
|
|
85
|
-
in data: then api.query(query, **data)
|
|
86
|
-
else api.query(query)
|
|
87
|
-
end
|
|
78
|
+
kwargs = options.slice(:page_size, :offset)
|
|
79
|
+
kwargs.merge!(options[:data]) if options[:data]
|
|
80
|
+
|
|
81
|
+
result = api.query(query, **kwargs)
|
|
82
|
+
options.key?(:page) ? result.page : result
|
|
88
83
|
end
|
|
89
84
|
end
|
|
90
85
|
end
|
data/lib/usps/imis/version.rb
CHANGED