Class: OrbipayPaymentsapiClient::ApiClient::ApiClient
- Inherits:
-
Object
- Object
- OrbipayPaymentsapiClient::ApiClient::ApiClient
- Defined in:
- lib/orbipay_paymentsapi_client/api_client.rb
Overview
.
############################################################################################
## This class subject to change without prior notice, Please dont use this class directly.##
############################################################################################
Instance Attribute Summary collapse
-
#config ⇒ Object
The Configuration object holding settings to be used in the API client.
-
#default_headers ⇒ Hash
Defines the headers to be used in HTTP requests of all API calls by default.
Class Method Summary collapse
Instance Method Summary collapse
-
#build_collection_param(param, collection_format) ⇒ Object
Build parameter value according to the given collection format.
-
#build_request(http_method, path, opts = {}) ⇒ Typhoeus::Request
Builds the HTTP request.
-
#build_request_body(header_params, form_params, body) ⇒ String
Builds the HTTP request body.
- #build_request_url(path) ⇒ Object
-
#call_api(http_method, path, opts = {}) ⇒ Array<(Object, Fixnum, Hash)>
Call an API with given options.
- #compute_opay1_hmac_sha256_hash(path, method, query_params, header_params, form_params, body) ⇒ Object
- #compute_opay2_hmac_sha256_hash(client_key, api_key, secret, timestamp) ⇒ Object
-
#convert_to_type(data, return_type) ⇒ Mixed
Convert data to the given return type.
- #decrypt_encoded_data(secret, message) ⇒ Object
-
#deserialize(response, return_type) ⇒ Object
Deserialize the response to the given return type.
-
#download_file(request) ⇒ Object
Save response body into a file in (the defined) temporary folder, using the filename from the “Content-Disposition” header if provided, otherwise a random filename.
- #get_form_params_string(params) ⇒ Object
- #get_header_params_string(params) ⇒ Object
- #get_query_params_string(params) ⇒ Object
- #get_timeout_value ⇒ Object
-
#initialize(config = Configuration::Configuration.default) ⇒ ApiClient
constructor
Initializes the ApiClient.
- #is_valid_header(header) ⇒ Object
-
#json_mime?(mime) ⇒ Boolean
Check if the given MIME is a JSON MIME.
-
#object_to_hash(obj) ⇒ String
Convert object(non-array) to hash.
-
#object_to_http_body(model) ⇒ String
Convert object (array, hash, object, etc) to JSON string.
-
#sanitize_filename(filename) ⇒ String
Sanitize filename by removing path.
-
#select_header_accept(accepts) ⇒ String
Return Accept header based on an array of accepts provided.
-
#select_header_content_type(content_types) ⇒ String
Return Content-Type header based on an array of content types provided.
-
#update_params_for_auth!(header_params, query_params, auth_names) ⇒ Object
Update hearder and query params based on authentication settings.
-
#user_agent=(user_agent) ⇒ Object
Sets user agent in HTTP header.
Constructor Details
#initialize(config = Configuration::Configuration.default) ⇒ ApiClient
Initializes the ApiClient
34 35 36 37 38 39 40 41 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 34 def initialize(config = Configuration::Configuration.default) @config = config @user_agent = "orbipay-paymentsapi-client/1.10.0/Ruby" @default_headers = { 'Content-Type' => 'application/json', 'User-Agent' => @user_agent } end |
Instance Attribute Details
#config ⇒ Object
The Configuration object holding settings to be used in the API client.
25 26 27 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 25 def config @config end |
#default_headers ⇒ Hash
Defines the headers to be used in HTTP requests of all API calls by default.
30 31 32 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 30 def default_headers @default_headers end |
Class Method Details
Instance Method Details
#build_collection_param(param, collection_format) ⇒ Object
Build parameter value according to the given collection format.
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 435 def build_collection_param(param, collection_format) case collection_format when :csv param.join(',') when :ssv param.join(' ') when :tsv param.join("\t") when :pipes param.join('|') when :multi # return the array directly as typhoeus will handle it as expected param else fail "unknown collection format: #{collection_format.inspect}" end end |
#build_request(http_method, path, opts = {}) ⇒ Typhoeus::Request
Builds the HTTP request
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 132 def build_request(http_method, path, opts = {}) url = build_request_url(path) @config.logger.debug "HTTP Method: #{http_method}" if @config.logger.debug? http_method = http_method.to_sym.downcase @config.logger.debug "HTTP URL: #{url}" if @config.logger.debug? @config.logger.debug "Timeout: #{@config.timeout}" if @config.logger.debug? header_params = @default_headers.merge(opts[:header_params] || {}) @config.logger.debug "Request Headers: #{CommonUtil::CommonUtil.object_to_http_body(header_params)}" if @config.logger.debug? query_params = {} form_params = opts[:form_params] || {} unless form_params.nil? or form_params.empty? @config.logger.debug "Masked Form Params: #{self.get_form_params_string(CommonUtil::CommonUtil.get_masked_properties(form_params))}" if @config.logger.debug? end # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false) _verify_ssl_host = @config.verify_ssl_host ? 2 : 0 # Get proxy url if set in environment variable proxy_url = CommonUtil::CommonUtil.get_proxy_url unless proxy_url.nil? || proxy_url.strip == "" @config.logger.debug "Proxy URL: #{proxy_url.to_s}" if @config.logger.debug? end req_opts = { :method => http_method, :headers => header_params, :params => query_params, :params_encoding => @config.params_encoding, :timeout => @config.timeout, :ssl_verifypeer => @config.verify_ssl, :ssl_verifyhost => _verify_ssl_host, :sslcert => @config.cert_file, :sslkey => @config.key_file, :verbose => @config.debugging, :proxy => proxy_url } # set custom cert, if provided req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert query_param_string = self.get_query_params_string(opts[:query_params]) unless query_param_string.nil? or query_param_string == '' @config.logger.debug "Query Params: #{query_param_string}" if @config.logger.debug? url = url + '?' + query_param_string end if [:post, :patch, :put, :delete].include?(http_method) req_body = build_request_body(header_params, form_params, opts[:body]) req_opts.update :body => req_body if !req_body.nil? && CommonUtil::CommonUtil.is_valid_json(req_body) @config.logger.debug "Maked Request Body: #{CommonUtil::CommonUtil.object_to_http_body(CommonUtil::CommonUtil.get_masked_properties(JSON.parse(req_body)))}" if @config.logger.debug? end end request = Typhoeus::Request.new(url, req_opts) download_file(request) if opts[:return_type] == 'File' request end |
#build_request_body(header_params, form_params, body) ⇒ String
Builds the HTTP request body
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 339 def build_request_body(header_params, form_params, body) # http form if header_params['Content-Type'] == 'application/x-www-form-urlencoded' data = get_form_params_string(form_params) elsif header_params['Content-Type'] == 'multipart/form-data' data = {} form_params.each do |key, value| case value when ::File, ::Array, nil # let typhoeus handle File, Array and nil parameters data[key] = value else data[key] = value.to_s end end elsif body data = body.is_a?(String) ? body : body.to_json else data = nil end data end |
#build_request_url(path) ⇒ Object
327 328 329 330 331 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 327 def build_request_url(path) # Add leading and trailing slashes to path path = "/#{path}".gsub(/\/+/, '/') URI.encode(@config.base_url + path) end |
#call_api(http_method, path, opts = {}) ⇒ Array<(Object, Fixnum, Hash)>
Call an API with given options.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 58 def call_api(http_method, path, opts = {}) client_api_key = @config.client_api_key secret = @config.secret algorithm = @config.algorithm algorithm1 = "OPAY1-HMAC-SHA256" algorithm2 = "OPAY2-HMAC-SHA256" algorithm3 = "OPAY3-HMAC-SHA256" if client_api_key == nil || client_api_key == "" client_api_key = opts[:header_params]['client_key'].to_s end if algorithm.nil? || algorithm == "" || algorithm == algorithm1 client_hash, = self.compute_opay1_hmac_sha256_hash(path, http_method, opts[:query_params], opts[:header_params], opts[:form_params],opts[:body]) opts[:header_params]["Authorization"] = algorithm1 + " Credential=" + client_api_key + ",Signature=" + client_hash.to_s.strip elsif algorithm == algorithm2 client_hash = self.compute_opay2_hmac_sha256_hash(opts[:header_params]['client_key'].to_s, client_api_key, secret, opts[:header_params]['timestamp'].to_s) opts[:header_params]["Authorization"] = algorithm2 + " Credential=" + client_api_key + ",Signature=" + client_hash.to_s.strip elsif algorithm == algorithm3 opts[:header_params]["Authorization"] = algorithm3 + " Credential=" + client_api_key else @config.logger.error "Invalid auth_scheme received" fail ApiError.new(:message => "Invalid auth_scheme received",:code => 0) end @config.set_values(timeout: get_timeout_value) request = build_request(http_method, path, opts) @config.logger.info "Sending Request to Service" response = request.run @config.logger.info "Receive Response from Service : HTTP Status Code : #{response.code}" if response.headers.key?("request_uuid") @config.logger.info "Request UUID: #{response.headers["request_uuid"]}" end @config.logger.debug "HTTP Response Headers: #{CommonUtil::CommonUtil.object_to_http_body(response.headers)}" if @config.logger.debug? if CommonUtil::CommonUtil.is_valid_json(response.body) @config.logger.debug "Masked Response Body: #{CommonUtil::CommonUtil.get_masked_properties(JSON.parse(response.body)).to_json}" if @config.logger.debug? end unless response.success? if response.timed_out? @config.logger.warn "#{response.}" fail ApiError.new(:message => response., :timed_out => true ) elsif response.code == 0 # Errors from libcurl will be made visible here fail ApiError.new(:code => 0, :message => response., :masked_authorization_string => , :request_headers => opts[:header_params], :request_body => opts[:body]) else fail ApiError.new(:code => response.code, :response_headers => response.headers, :response_body => response.body, :masked_authorization_string => , :request_headers => opts[:header_params], :request_body => opts[:body]), response. end end if opts[:return_type] data = deserialize(response, opts[:return_type]) else data = nil end return data, response.code, response.headers end |
#compute_opay1_hmac_sha256_hash(path, method, query_params, header_params, form_params, body) ⇒ Object
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 454 def compute_opay1_hmac_sha256_hash(path, method, query_params, header_params, form_params, body) begin path = "/payments/v1" + path separator = ":" params = [] params.push((method.upcase.to_s.strip)) params.push(path.strip) params.push(self.get_query_params_string(query_params)) params.push(self.get_header_params_string(header_params)) masked_params = params.clone body_text = body.is_a?(String) ? body : body.to_json if (!form_params.empty?) params.push(self.get_form_params_string(form_params)) masked_params.push(self.get_form_params_string(CommonUtil::CommonUtil.get_masked_properties(form_params))) param_string = params.join(separator) masked_param_string = masked_params.join(separator) elsif !body_text.nil? and body_text != "null" params.push(body_text) masked_params.push(CommonUtil::CommonUtil.get_masked_properties(JSON.parse(body_text)).to_json) param_string = params.join(separator) masked_param_string = masked_params.join(separator) else param_string = params.join(separator)+separator masked_param_string = masked_params.join(separator)+separator end if @config.secret.nil? || @config.secret == "" @config.logger.error "Missing the required parameter secret when generating signature" fail ApiError.new(:message => "Missing the required parameter secret when generating signature",:code => 0) end hmac_sha_256_hash = self.decrypt_encoded_data(secret=@config.secret, =param_string) return hmac_sha_256_hash , masked_param_string rescue StandardError => e raise e end end |
#compute_opay2_hmac_sha256_hash(client_key, api_key, secret, timestamp) ⇒ Object
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 491 def compute_opay2_hmac_sha256_hash(client_key, api_key, secret, ) begin separator = ":" params = [] if secret.nil? || secret == "" @config.logger.error "Missing the required parameter secret when generating signature" fail ApiError.new(:message => "Missing the required parameter secret when generating signature",:code => 0) end if client_key.nil? || client_key == "" @config.logger.error "Missing the required parameter client_key when generating signature" fail ApiError.new(:message => "Missing the required parameter client_key when generating signature",:code => 0) end if api_key.nil? || api_key == "" @config.logger.error "Missing the required parameter api_key when generating signature" fail ApiError.new(:message => "Missing the required parameter api_key when generating signature",:code => 0) end params.push(client_key.strip) params.push(api_key.strip) params.push(secret.strip) params.push(.strip) param_string = params.join(separator) hmac_sha_256_hash = self.decrypt_encoded_data(secret=secret, =param_string) return hmac_sha_256_hash rescue StandardError => e raise e end end |
#convert_to_type(data, return_type) ⇒ Mixed
Convert data to the given return type.
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 244 def convert_to_type(data, return_type) return nil if data.nil? case return_type when 'String' data.to_s when 'Integer' data.to_i when 'Float' data.to_f when 'BOOLEAN' data == true when 'DateTime' # parse date time (expecting ISO 8601 format) DateTime.parse data when 'Date' # parse date time (expecting ISO 8601 format) Date.parse data when 'Object' # generic object (usually a Hash), return directly data when /\AArray<(.+)>\z/ # e.g. Array<Pet> sub_type = $1 data.map { |item| convert_to_type(item, sub_type) } when /\AHash\<String, (.+)\>\z/ # e.g. Hash<String, Integer> sub_type = $1 {}.tap do |hash| data.each { |k, v| hash[k] = convert_to_type(v, sub_type) } end else # models, e.g. Pet OrbipayPaymentsapiClient::OrbipayPaymentsapiClientModels.const_get(return_type).new.tap do |model| model.build_from_hash data end end end |
#decrypt_encoded_data(secret, message) ⇒ Object
669 670 671 672 673 674 675 676 677 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 669 def decrypt_encoded_data(secret, ) begin dig = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), secret, ) base64_encoded_data = Base64.encode64(dig) return base64_encoded_data rescue StandardError => e raise e end end |
#deserialize(response, return_type) ⇒ Object
Deserialize the response to the given return type.
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 210 def deserialize(response, return_type) body = response.body # handle file downloading - return the File instance processed in request callbacks # note that response body is empty when the file is written in chunks in request on_body callback return @tempfile if return_type == 'File' return nil if body.nil? || body.empty? # return response body directly for String return type return body if return_type == 'String' # ensuring a default content type content_type = response.headers['Content-Type'] || 'application/json' fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type) begin data = JSON.parse("[#{body}]", :symbolize_names => true)[0] rescue JSON::ParserError => e if %w(String Date DateTime).include?(return_type) data = body else raise e end end convert_to_type data, return_type end |
#download_file(request) ⇒ Object
Save response body into a file in (the defined) temporary folder, using the filename from the “Content-Disposition” header if provided, otherwise a random filename. The response body is written to the file in chunks in order to handle files which size is larger than maximum Ruby String or even larger than the maximum memory a Ruby process can use.
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 289 def download_file(request) tempfile = nil encoding = nil request.on_headers do |response| content_disposition = response.headers['Content-Disposition'] if content_disposition && content_disposition =~ /filename=/i filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1] prefix = sanitize_filename(filename) else prefix = 'download-' end prefix = prefix + '-' unless prefix.end_with?('-') encoding = response.body.encoding tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) @tempfile = tempfile end request.on_body do |chunk| chunk.force_encoding(encoding) tempfile.write(chunk) end request.on_complete do |response| tempfile.close @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ "will be deleted automatically with GC. It's also recommended to delete the temp file "\ "explicitly with `tempfile.delete`" end end |
#get_form_params_string(params) ⇒ Object
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 624 def get_form_params_string(params) param_string = "" begin filtered_params = {} for param in params if param != nil and param.length == 2 k = param[0] v = param[1] if !k.nil? and (k.is_a? String or k.is_a? Symbol) if !v.nil? and v.is_a? String unless filtered_params.key?(v) filtered_params[k] = [] end filtered_params[k].push(v) elsif (!v.nil? and (v.is_a?(Array))) unless filtered_params.key?(k) filtered_params[k] = [] end for value in v filtered_params[k].push(value) end elsif !v.nil? unless filtered_params.key?(k) filtered_params[k] = [] end filtered_params[k].push(v) end end end end filtered_params.keys.each do |key| value = filtered_params[key] for element in value param_string += key + "=" + element.to_s + "&" end end if param_string.end_with? "&" param_string = param_string[0..-2] end return param_string rescue StandardError => e raise e end end |
#get_header_params_string(params) ⇒ Object
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 571 def get_header_params_string(params) param_string = "" begin filtered_params = {} for param in params if param != nil and param.length == 2 k = param[0] v = param[1] if k.is_a? String or k.is_a? Symbol if is_valid_header(k) stripped_key = k.to_s.strip if stripped_key != "" if v.is_a? String stripped_value = v.to_s.strip if stripped_value != "" unless filtered_params.key?(stripped_key) filtered_params[stripped_key] = [] end filtered_params[stripped_key].push(stripped_value) end elsif v.is_a? Array unless filtered_params.key?(stripped_key) filtered_params[stripped_key] = [] end for value in v filtered_params[stripped_key].push(value) end elsif v != nil unless filtered_params.key?(stripped_key) filtered_params[stripped_key] = [] end filtered_params[stripped_key].push(v) end end end end end end filtered_params.keys.sort.each do |key| value = filtered_params[key] for element in value.sort param_string += key + "=" + element.to_s + "&" end end if param_string.end_with? "&" param_string = param_string[0..-2] end return param_string rescue StandardError => e raise e end end |
#get_query_params_string(params) ⇒ Object
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 520 def get_query_params_string(params) param_string = "" begin filtered_params = {} for param in params if param != nil and param.length == 2 k = param[0] v = param[1] if k.is_a? String or k.is_a? Symbol stripped_key = k.to_s.strip if stripped_key != "" if v.is_a? String stripped_value = v.to_s.strip if stripped_value != "" unless filtered_params.key?(stripped_key) filtered_params[stripped_key] = [] end filtered_params[stripped_key].push(stripped_value) end elsif v.is_a? Array unless filtered_params.key?(stripped_key) filtered_params[stripped_key] = [] end for value in v filtered_params[stripped_key].push(value) end elsif v != nil unless filtered_params.key?(stripped_key) filtered_params[stripped_key] = [] end filtered_params[stripped_key].push(v) end end end end end filtered_params.keys.sort.each do |key| value = filtered_params[key] for element in value.sort param_string += key + "=" + element.to_s + "&" end end if param_string.end_with? "&" param_string = param_string[0..-2] end return param_string rescue StandardError => e raise e end end |
#get_timeout_value ⇒ Object
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 679 def get_timeout_value timeout = DEFAULT_TIMEOUT_IN_SECONDS begin if ENV.key?(API_CLIENT_TIMEOUT) and !ENV[API_CLIENT_TIMEOUT].nil? time = ENV[API_CLIENT_TIMEOUT].to_s.to_i if time <= 0 @config.logger.warn("The environment variable ORBIPAY_PAYMENTS_API_TIMEOUT_SECONDS is not set or set to -ve. so, set to default value Timeout :: " + time.to_s) else timeout = time end end rescue Exception => e @config.logger.warn("problem in setting timeout from environment variable ORBIPAY_PAYMENTS_API_TIMEOUT_SECONDS. so, set to default value Timeout :: " + time.to_s) end return timeout end |
#is_valid_header(header) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 47 def is_valid_header(header) if ["product", "idempotent_request_key", "channel", "requestor", "client_key", "X-OPAY-Headers", "requestor_type", "timestamp", ].include? header.to_s return true end false end |
#json_mime?(mime) ⇒ Boolean
Check if the given MIME is a JSON MIME. JSON MIME examples:
application/json
application/json; charset=UTF8
APPLICATION/JSON
*/*
202 203 204 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 202 def json_mime?(mime) (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil? end |
#object_to_hash(obj) ⇒ String
Convert object(non-array) to hash.
425 426 427 428 429 430 431 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 425 def object_to_hash(obj) if obj.respond_to?(:to_hash) obj.to_hash else obj end end |
#object_to_http_body(model) ⇒ String
Convert object (array, hash, object, etc) to JSON string.
411 412 413 414 415 416 417 418 419 420 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 411 def object_to_http_body(model) return model if model.nil? || model.is_a?(String) local_body = nil if model.is_a?(Array) local_body = model.map { |m| object_to_hash(m) } else local_body = object_to_hash(model) end local_body.to_json end |
#sanitize_filename(filename) ⇒ String
Sanitize filename by removing path. e.g. ../../sun.gif becomes sun.gif
323 324 325 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 323 def sanitize_filename(filename) filename.gsub(/.*[\/\\]/, '') end |
#select_header_accept(accepts) ⇒ String
Return Accept header based on an array of accepts provided.
390 391 392 393 394 395 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 390 def select_header_accept(accepts) return nil if accepts.nil? || accepts.empty? # use JSON when present, otherwise use all of the provided json_accept = accepts.find { |s| json_mime?(s) } json_accept || accepts.join(',') end |
#select_header_content_type(content_types) ⇒ String
Return Content-Type header based on an array of content types provided.
400 401 402 403 404 405 406 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 400 def select_header_content_type(content_types) # use application/json by default return 'application/json' if content_types.nil? || content_types.empty? # use JSON when present, otherwise use the first one json_content_type = content_types.find { |s| json_mime?(s) } json_content_type || content_types.first end |
#update_params_for_auth!(header_params, query_params, auth_names) ⇒ Object
Update hearder and query params based on authentication settings.
367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 367 def update_params_for_auth!(header_params, query_params, auth_names) Array(auth_names).each do |auth_name| auth_setting = @config.auth_settings[auth_name] next unless auth_setting case auth_setting[:in] when 'header' then header_params[auth_setting[:key]] = auth_setting[:value] when 'query' then query_params[auth_setting[:key]] = auth_setting[:value] else fail ArgumentError, 'Authentication token must be in `query` of `header`' end end end |
#user_agent=(user_agent) ⇒ Object
Sets user agent in HTTP header
382 383 384 385 |
# File 'lib/orbipay_paymentsapi_client/api_client.rb', line 382 def user_agent=(user_agent) @user_agent = user_agent @default_headers['User-Agent'] = @user_agent end |