jamm 1.2.2 → 1.4.0
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/Gemfile.lock +1 -1
- data/lib/jamm/api/api/customer_api.rb +82 -52
- data/lib/jamm/api/api/healthcheck_api.rb +18 -15
- data/lib/jamm/api/api/payment_api.rb +113 -62
- data/lib/jamm/api/api/webhook_service_api.rb +91 -19
- data/lib/jamm/api/api_client.rb +74 -66
- data/lib/jamm/api/api_error.rb +16 -16
- data/lib/jamm/api/configuration.rb +42 -34
- data/lib/jamm/api/models/apiv1_error.rb +238 -0
- data/lib/jamm/api/models/apiv1_status.rb +57 -47
- data/lib/jamm/api/models/customer_service_update_customer_body.rb +107 -69
- data/lib/jamm/api/models/googlerpc_status.rb +61 -45
- data/lib/jamm/api/models/protobuf_any.rb +42 -35
- data/lib/jamm/api/models/v1_add_charge_request.rb +59 -44
- data/lib/jamm/api/models/v1_add_charge_response.rb +59 -44
- data/lib/jamm/api/models/v1_bank.rb +350 -0
- data/lib/jamm/api/models/v1_bank_assets.rb +244 -0
- data/lib/jamm/api/models/v1_bank_branch.rb +259 -0
- data/lib/jamm/api/models/v1_bank_information.rb +71 -51
- data/lib/jamm/api/models/v1_bank_quota.rb +278 -0
- data/lib/jamm/api/models/v1_bank_scheduled_maintenance_period.rb +250 -0
- data/lib/jamm/api/models/v1_buyer.rb +104 -76
- data/lib/jamm/api/models/v1_charge.rb +67 -52
- data/lib/jamm/api/models/v1_charge_message.rb +151 -93
- data/lib/jamm/api/models/v1_charge_message_status.rb +17 -18
- data/lib/jamm/api/models/v1_charge_result.rb +152 -93
- data/lib/jamm/api/models/v1_contract.rb +64 -52
- data/lib/jamm/api/models/v1_contract_message.rb +67 -48
- data/lib/jamm/api/models/v1_contract_status.rb +20 -21
- data/lib/jamm/api/models/v1_create_contract_with_charge_request.rb +59 -44
- data/lib/jamm/api/models/v1_create_contract_with_charge_response.rb +67 -48
- data/lib/jamm/api/models/v1_create_contract_without_charge_request.rb +51 -40
- data/lib/jamm/api/models/v1_create_contract_without_charge_response.rb +59 -44
- data/lib/jamm/api/models/v1_create_customer_request.rb +42 -35
- data/lib/jamm/api/models/v1_create_customer_response.rb +42 -35
- data/lib/jamm/api/models/v1_customer.rb +91 -60
- data/lib/jamm/api/models/v1_delete_customer_response.rb +42 -35
- data/lib/jamm/api/models/v1_deposit_type.rb +14 -15
- data/lib/jamm/api/models/v1_error_detail.rb +233 -0
- data/lib/jamm/api/models/v1_error_response.rb +238 -0
- data/lib/jamm/api/models/v1_error_type.rb +57 -0
- data/lib/jamm/api/models/v1_event_type.rb +20 -21
- data/lib/jamm/api/models/{v1_error.rb → v1_get_bank_response.rb} +45 -48
- data/lib/jamm/api/models/v1_get_branch_response.rb +214 -0
- data/lib/jamm/api/models/v1_get_branches_response.rb +216 -0
- data/lib/jamm/api/models/v1_get_charge_response.rb +51 -40
- data/lib/jamm/api/models/v1_get_charges_response.rb +60 -45
- data/lib/jamm/api/models/v1_get_contract_response.rb +51 -40
- data/lib/jamm/api/models/v1_get_customer_response.rb +42 -35
- data/lib/jamm/api/models/v1_get_major_banks_response.rb +232 -0
- data/lib/jamm/api/models/v1_initial_charge.rb +61 -48
- data/lib/jamm/api/models/v1_kyc_status.rb +16 -17
- data/lib/jamm/api/models/v1_merchant.rb +51 -40
- data/lib/jamm/api/models/v1_merchant_customer.rb +51 -40
- data/lib/jamm/api/models/v1_merchant_webhook_message.rb +75 -57
- data/lib/jamm/api/models/v1_message_response.rb +67 -48
- data/lib/jamm/api/models/v1_off_session_payment_request.rb +51 -40
- data/lib/jamm/api/models/v1_off_session_payment_response.rb +51 -40
- data/lib/jamm/api/models/v1_on_session_payment_data.rb +67 -48
- data/lib/jamm/api/models/v1_on_session_payment_error.rb +55 -45
- data/lib/jamm/api/models/v1_on_session_payment_error_code.rb +21 -22
- data/lib/jamm/api/models/v1_on_session_payment_request.rb +67 -48
- data/lib/jamm/api/models/v1_on_session_payment_response.rb +59 -44
- data/lib/jamm/api/models/v1_pagination.rb +51 -40
- data/lib/jamm/api/models/v1_payment_authorization_status.rb +14 -15
- data/lib/jamm/api/models/v1_payment_link.rb +57 -44
- data/lib/jamm/api/models/v1_ping_response.rb +42 -35
- data/lib/jamm/api/models/v1_search_banks_response.rb +216 -0
- data/lib/jamm/api/models/v1_search_branches_response.rb +216 -0
- data/lib/jamm/api/models/v1_update_customer_response.rb +42 -35
- data/lib/jamm/api/models/v1_url.rb +48 -39
- data/lib/jamm/api/models/v1_user_account_message.rb +67 -48
- data/lib/jamm/api/models/v1_withdraw_request.rb +51 -40
- data/lib/jamm/api/models/v1_withdraw_response.rb +51 -40
- data/lib/jamm/api/version.rb +11 -11
- data/lib/jamm/api.rb +25 -11
- data/lib/jamm/charge.rb +12 -0
- data/lib/jamm/deprecation.rb +13 -0
- data/lib/jamm/errors.rb +27 -1
- data/lib/jamm/payment.rb +61 -0
- data/lib/jamm/version.rb +1 -1
- data/lib/jamm.rb +2 -0
- metadata +19 -3
data/lib/jamm/api/api_client.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
=begin
|
2
|
+
#Jamm API
|
3
|
+
|
4
|
+
#No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 1.0
|
7
|
+
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
Generator version: 7.9.0
|
10
|
+
|
11
|
+
=end
|
12
12
|
|
13
13
|
require 'date'
|
14
14
|
require 'json'
|
@@ -17,6 +17,7 @@ require 'tempfile'
|
|
17
17
|
require 'time'
|
18
18
|
require 'typhoeus'
|
19
19
|
|
20
|
+
|
20
21
|
module Api
|
21
22
|
class ApiClient
|
22
23
|
# The Configuration object holding settings to be used in the API client.
|
@@ -51,29 +52,33 @@ module Api
|
|
51
52
|
tempfile = download_file(request) if opts[:return_type] == 'File'
|
52
53
|
response = request.run
|
53
54
|
|
54
|
-
|
55
|
+
if @config.debugging
|
56
|
+
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
57
|
+
end
|
55
58
|
|
56
59
|
unless response.success?
|
57
60
|
if response.timed_out?
|
58
|
-
|
59
|
-
elsif response.code
|
61
|
+
fail ApiError.new('Connection timed out')
|
62
|
+
elsif response.code == 0
|
60
63
|
# Errors from libcurl will be made visible here
|
61
|
-
|
62
|
-
|
64
|
+
fail ApiError.new(:code => 0,
|
65
|
+
:message => response.return_message)
|
63
66
|
else
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
67
|
+
fail ApiError.new(:code => response.code,
|
68
|
+
:response_headers => response.headers,
|
69
|
+
:response_body => response.body),
|
70
|
+
response.status_message
|
68
71
|
end
|
69
72
|
end
|
70
73
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
if opts[:return_type] == 'File'
|
75
|
+
data = tempfile
|
76
|
+
elsif opts[:return_type]
|
77
|
+
data = deserialize(response, opts[:return_type])
|
78
|
+
else
|
79
|
+
data = nil
|
80
|
+
end
|
81
|
+
return data, response.code, response.headers
|
77
82
|
end
|
78
83
|
|
79
84
|
# Builds the HTTP request
|
@@ -94,6 +99,7 @@ module Api
|
|
94
99
|
form_params = opts[:form_params] || {}
|
95
100
|
follow_location = opts[:follow_location] || true
|
96
101
|
|
102
|
+
|
97
103
|
# set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
|
98
104
|
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0
|
99
105
|
|
@@ -114,10 +120,12 @@ module Api
|
|
114
120
|
# set custom cert, if provided
|
115
121
|
req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
|
116
122
|
|
117
|
-
if
|
123
|
+
if [:post, :patch, :put, :delete].include?(http_method)
|
118
124
|
req_body = build_request_body(header_params, form_params, opts[:body])
|
119
125
|
req_opts.update :body => req_body
|
120
|
-
|
126
|
+
if @config.debugging
|
127
|
+
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
128
|
+
end
|
121
129
|
end
|
122
130
|
|
123
131
|
Typhoeus::Request.new(url, req_opts)
|
@@ -132,16 +140,16 @@ module Api
|
|
132
140
|
def build_request_body(header_params, form_params, body)
|
133
141
|
# http form
|
134
142
|
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
135
|
-
|
143
|
+
header_params['Content-Type'] == 'multipart/form-data'
|
136
144
|
data = {}
|
137
145
|
form_params.each do |key, value|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
146
|
+
case value
|
147
|
+
when ::File, ::Array, nil
|
148
|
+
# let typhoeus handle File, Array and nil parameters
|
149
|
+
data[key] = value
|
150
|
+
else
|
151
|
+
data[key] = value.to_s
|
152
|
+
end
|
145
153
|
end
|
146
154
|
elsif body
|
147
155
|
data = body.is_a?(String) ? body : body.to_json
|
@@ -171,7 +179,7 @@ module Api
|
|
171
179
|
else
|
172
180
|
prefix = 'download-'
|
173
181
|
end
|
174
|
-
prefix
|
182
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
175
183
|
encoding = response.body.encoding
|
176
184
|
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
177
185
|
end
|
@@ -181,13 +189,15 @@ module Api
|
|
181
189
|
end
|
182
190
|
# run the request to ensure the tempfile is created successfully before returning it
|
183
191
|
request.run
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
192
|
+
if tempfile
|
193
|
+
tempfile.close
|
194
|
+
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
195
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
196
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
197
|
+
"explicitly with `tempfile.delete`"
|
198
|
+
else
|
199
|
+
fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
|
200
|
+
end
|
191
201
|
|
192
202
|
tempfile
|
193
203
|
end
|
@@ -201,7 +211,7 @@ module Api
|
|
201
211
|
# @param [String] mime MIME
|
202
212
|
# @return [Boolean] True if the MIME is application/json
|
203
213
|
def json_mime?(mime)
|
204
|
-
(mime == '*/*') || !(mime =~
|
214
|
+
(mime == '*/*') || !(mime =~ /^Application\/.*json(?!p)(;.*)?/i).nil?
|
205
215
|
end
|
206
216
|
|
207
217
|
# Deserialize the response to the given return type.
|
@@ -218,14 +228,16 @@ module Api
|
|
218
228
|
# ensuring a default content type
|
219
229
|
content_type = response.headers['Content-Type'] || 'application/json'
|
220
230
|
|
221
|
-
|
231
|
+
fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
222
232
|
|
223
233
|
begin
|
224
234
|
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
225
235
|
rescue JSON::ParserError => e
|
226
|
-
|
227
|
-
|
228
|
-
|
236
|
+
if %w(String Date Time).include?(return_type)
|
237
|
+
data = body
|
238
|
+
else
|
239
|
+
raise e
|
240
|
+
end
|
229
241
|
end
|
230
242
|
|
231
243
|
convert_to_type data, return_type
|
@@ -237,7 +249,6 @@ module Api
|
|
237
249
|
# @return [Mixed] Data in a particular type
|
238
250
|
def convert_to_type(data, return_type)
|
239
251
|
return nil if data.nil?
|
240
|
-
|
241
252
|
case return_type
|
242
253
|
when 'String'
|
243
254
|
data.to_s
|
@@ -258,11 +269,11 @@ module Api
|
|
258
269
|
data
|
259
270
|
when /\AArray<(.+)>\z/
|
260
271
|
# e.g. Array<Pet>
|
261
|
-
sub_type =
|
272
|
+
sub_type = $1
|
262
273
|
data.map { |item| convert_to_type(item, sub_type) }
|
263
|
-
when /\AHash
|
274
|
+
when /\AHash\<String, (.+)\>\z/
|
264
275
|
# e.g. Hash<String, Integer>
|
265
|
-
sub_type =
|
276
|
+
sub_type = $1
|
266
277
|
{}.tap do |hash|
|
267
278
|
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
268
279
|
end
|
@@ -279,12 +290,12 @@ module Api
|
|
279
290
|
# @param [String] filename the filename to be sanitized
|
280
291
|
# @return [String] the sanitized filename
|
281
292
|
def sanitize_filename(filename)
|
282
|
-
filename.split(
|
293
|
+
filename.split(/[\/\\]/).last
|
283
294
|
end
|
284
295
|
|
285
296
|
def build_request_url(path, opts = {})
|
286
297
|
# Add leading and trailing slashes to path
|
287
|
-
path = "/#{path}".gsub(
|
298
|
+
path = "/#{path}".gsub(/\/+/, '/')
|
288
299
|
@config.base_url(opts[:operation]) + path
|
289
300
|
end
|
290
301
|
|
@@ -297,11 +308,10 @@ module Api
|
|
297
308
|
Array(auth_names).each do |auth_name|
|
298
309
|
auth_setting = @config.auth_settings[auth_name]
|
299
310
|
next unless auth_setting
|
300
|
-
|
301
311
|
case auth_setting[:in]
|
302
312
|
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
303
313
|
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
304
|
-
else
|
314
|
+
else fail ArgumentError, 'Authentication token must be in `query` or `header`'
|
305
315
|
end
|
306
316
|
end
|
307
317
|
end
|
@@ -319,7 +329,6 @@ module Api
|
|
319
329
|
# @return [String] the Accept header (e.g. application/json)
|
320
330
|
def select_header_accept(accepts)
|
321
331
|
return nil if accepts.nil? || accepts.empty?
|
322
|
-
|
323
332
|
# use JSON when present, otherwise use all of the provided
|
324
333
|
json_accept = accepts.find { |s| json_mime?(s) }
|
325
334
|
json_accept || accepts.join(',')
|
@@ -331,7 +340,6 @@ module Api
|
|
331
340
|
def select_header_content_type(content_types)
|
332
341
|
# return nil by default
|
333
342
|
return if content_types.nil? || content_types.empty?
|
334
|
-
|
335
343
|
# use JSON when present, otherwise use the first one
|
336
344
|
json_content_type = content_types.find { |s| json_mime?(s) }
|
337
345
|
json_content_type || content_types.first
|
@@ -342,12 +350,12 @@ module Api
|
|
342
350
|
# @return [String] JSON string representation of the object
|
343
351
|
def object_to_http_body(model)
|
344
352
|
return model if model.nil? || model.is_a?(String)
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
353
|
+
local_body = nil
|
354
|
+
if model.is_a?(Array)
|
355
|
+
local_body = model.map { |m| object_to_hash(m) }
|
356
|
+
else
|
357
|
+
local_body = object_to_hash(model)
|
358
|
+
end
|
351
359
|
local_body.to_json
|
352
360
|
end
|
353
361
|
|
@@ -378,7 +386,7 @@ module Api
|
|
378
386
|
# return the array directly as typhoeus will handle it as expected
|
379
387
|
param
|
380
388
|
else
|
381
|
-
|
389
|
+
fail "unknown collection format: #{collection_format.inspect}"
|
382
390
|
end
|
383
391
|
end
|
384
392
|
end
|
data/lib/jamm/api/api_error.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
=begin
|
2
|
+
#Jamm API
|
3
|
+
|
4
|
+
#No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 1.0
|
7
|
+
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
Generator version: 7.9.0
|
10
|
+
|
11
|
+
=end
|
12
12
|
|
13
13
|
module Api
|
14
14
|
class ApiError < StandardError
|
@@ -42,11 +42,11 @@ module Api
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def message
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
if @message.nil?
|
46
|
+
msg = "Error message: the server returns an error"
|
47
|
+
else
|
48
|
+
msg = @message
|
49
|
+
end
|
50
50
|
|
51
51
|
msg += "\nHTTP status code: #{code}" if code
|
52
52
|
msg += "\nResponse headers: #{response_headers}" if response_headers
|
@@ -1,14 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
=begin
|
2
|
+
#Jamm API
|
3
|
+
|
4
|
+
#No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 1.0
|
7
|
+
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
Generator version: 7.9.0
|
10
|
+
|
11
|
+
=end
|
12
12
|
|
13
13
|
module Api
|
14
14
|
class Configuration
|
@@ -151,7 +151,10 @@ module Api
|
|
151
151
|
# https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
|
152
152
|
attr_accessor :params_encoding
|
153
153
|
|
154
|
-
|
154
|
+
|
155
|
+
attr_accessor :inject_format
|
156
|
+
|
157
|
+
attr_accessor :force_ending_format
|
155
158
|
|
156
159
|
def initialize
|
157
160
|
@scheme = 'http'
|
@@ -174,7 +177,7 @@ module Api
|
|
174
177
|
@ignore_operation_servers = false
|
175
178
|
@inject_format = false
|
176
179
|
@force_ending_format = false
|
177
|
-
@logger = defined?(Rails) ? Rails.logger : Logger.new(
|
180
|
+
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
178
181
|
|
179
182
|
yield(self) if block_given?
|
180
183
|
end
|
@@ -190,29 +193,28 @@ module Api
|
|
190
193
|
|
191
194
|
def scheme=(scheme)
|
192
195
|
# remove :// from scheme
|
193
|
-
@scheme = scheme.sub(
|
196
|
+
@scheme = scheme.sub(/:\/\//, '')
|
194
197
|
end
|
195
198
|
|
196
199
|
def host=(host)
|
197
200
|
# remove http(s):// and anything after a slash
|
198
|
-
@host = host.sub(
|
201
|
+
@host = host.sub(/https?:\/\//, '').split('/').first
|
199
202
|
end
|
200
203
|
|
201
204
|
def base_path=(base_path)
|
202
205
|
# Add leading and trailing slashes to base_path
|
203
|
-
@base_path = "/#{base_path}".gsub(
|
206
|
+
@base_path = "/#{base_path}".gsub(/\/+/, '/')
|
204
207
|
@base_path = '' if @base_path == '/'
|
205
208
|
end
|
206
209
|
|
207
210
|
# Returns base URL for specified operation based on server settings
|
208
211
|
def base_url(operation = nil)
|
209
|
-
return "#{scheme}://#{[host, base_path].join('/').gsub(
|
210
|
-
|
211
|
-
if operation_server_settings.key?(operation)
|
212
|
+
return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if ignore_operation_servers
|
213
|
+
if operation_server_settings.key?(operation) then
|
212
214
|
index = server_operation_index.fetch(operation, server_index)
|
213
215
|
server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
|
214
216
|
else
|
215
|
-
server_index.nil? ? "#{scheme}://#{[host, base_path].join('/').gsub(
|
217
|
+
server_index.nil? ? "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') : server_url(server_index, server_variables, nil)
|
216
218
|
end
|
217
219
|
end
|
218
220
|
|
@@ -231,32 +233,33 @@ module Api
|
|
231
233
|
# Gets access_token using access_token_getter or uses the static access_token
|
232
234
|
def access_token_with_refresh
|
233
235
|
return access_token if access_token_getter.nil?
|
234
|
-
|
235
236
|
access_token_getter.call
|
236
237
|
end
|
237
238
|
|
238
239
|
# Gets Basic Auth token string
|
239
240
|
def basic_auth_token
|
240
|
-
|
241
|
+
'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
|
241
242
|
end
|
242
243
|
|
243
244
|
# Returns Auth Settings hash for api client.
|
244
245
|
def auth_settings
|
245
|
-
{
|
246
|
+
{
|
247
|
+
}
|
246
248
|
end
|
247
249
|
|
248
250
|
# Returns an array of Server setting
|
249
251
|
def server_settings
|
250
252
|
[
|
251
253
|
{
|
252
|
-
url:
|
253
|
-
description:
|
254
|
+
url: "",
|
255
|
+
description: "No description provided",
|
254
256
|
}
|
255
257
|
]
|
256
258
|
end
|
257
259
|
|
258
260
|
def operation_server_settings
|
259
|
-
{
|
261
|
+
{
|
262
|
+
}
|
260
263
|
end
|
261
264
|
|
262
265
|
# Returns URL based on server settings
|
@@ -264,10 +267,12 @@ module Api
|
|
264
267
|
# @param index array index of the server settings
|
265
268
|
# @param variables hash of variable and the corresponding value
|
266
269
|
def server_url(index, variables = {}, servers = nil)
|
267
|
-
servers = server_settings if servers
|
270
|
+
servers = server_settings if servers == nil
|
268
271
|
|
269
272
|
# check array index out of bound
|
270
|
-
|
273
|
+
if (index.nil? || index < 0 || index >= servers.size)
|
274
|
+
fail ArgumentError, "Invalid index #{index} when selecting the server. Must not be nil and must be less than #{servers.size}"
|
275
|
+
end
|
271
276
|
|
272
277
|
server = servers[index]
|
273
278
|
url = server[:url]
|
@@ -275,19 +280,22 @@ module Api
|
|
275
280
|
return url unless server.key? :variables
|
276
281
|
|
277
282
|
# go through variable and assign a value
|
278
|
-
server[:variables].
|
283
|
+
server[:variables].each do |name, variable|
|
279
284
|
if variables.key?(name)
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
285
|
+
if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
|
286
|
+
url.gsub! "{" + name.to_s + "}", variables[name]
|
287
|
+
else
|
288
|
+
fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
|
289
|
+
end
|
284
290
|
else
|
285
291
|
# use default value
|
286
|
-
url.gsub! "{
|
292
|
+
url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
|
287
293
|
end
|
288
294
|
end
|
289
295
|
|
290
296
|
url
|
291
297
|
end
|
298
|
+
|
299
|
+
|
292
300
|
end
|
293
301
|
end
|