class CybridApiId::Configuration
def self.default
def self.default @@default ||= Configuration.new end
def api_key_with_prefix(param_name, param_alias = nil)
-
param_name
(String
) -- the parameter name of API key auth
def api_key_with_prefix(param_name, param_alias = nil) key = @api_key[param_name] key = @api_key.fetch(param_alias, key) unless param_alias.nil? if @api_key_prefix[param_name] "#{@api_key_prefix[param_name]} #{key}" else key end end
def auth_settings
def auth_settings { 'BearerAuth' => { type: 'bearer', in: 'header', format: 'JWT', key: 'Authorization', value: "Bearer #{access_token}" }, 'oauth2' => { type: 'oauth2', in: 'header', key: 'Authorization', value: "Bearer #{access_token}" }, } end
def base_path=(base_path)
def base_path=(base_path) # Add leading and trailing slashes to base_path @base_path = "/#{base_path}".gsub(/\/+/, '/') @base_path = '' if @base_path == '/' end
def base_url(operation = nil)
def base_url(operation = nil) index = server_operation_index.fetch(operation, server_index) return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if index == nil server_url(index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation]) end
def basic_auth_token
def basic_auth_token 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n") end
def configure
def configure yield(self) if block_given? end
def host=(host)
def host=(host) # remove http(s):// and anything after a slash @host = host.sub(/https?:\/\//, '').split('/').first end
def initialize
def initialize @scheme = 'https' @host = 'id.sandbox.cybrid.app' @base_path = '' @server_index = 0 @server_operation_index = {} @server_variables = {} @server_operation_variables = {} @api_key = {} @api_key_prefix = {} @client_side_validation = true @verify_ssl = true @verify_ssl_host = true @cert_file = nil @key_file = nil @timeout = 0 @params_encoding = nil @debugging = false @inject_format = false @force_ending_format = false @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT) yield(self) if block_given? end
def operation_server_settings
def operation_server_settings { } end
def scheme=(scheme)
def scheme=(scheme) # remove :// from scheme @scheme = scheme.sub(/:\/\//, '') end
def server_settings
def server_settings [ { url: "https://id.sandbox.cybrid.app", description: "Sandbox environment is for public use and uses simulated money movement", }, { url: "https://id.production.cybrid.app", description: "Production environment is for public use and uses real money movement", } ] end
def server_url(index, variables = {}, servers = nil)
-
variables
() -- hash of variable and the corresponding value
-
index
() -- array index of the server settings
def server_url(index, variables = {}, servers = nil) servers = server_settings if servers == nil # check array index out of bound if (index < 0 || index >= servers.size) fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}" end server = servers[index] url = server[:url] return url unless server.key? :variables # go through variable and assign a value server[:variables].each do |name, variable| if variables.key?(name) if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name])) url.gsub! "{" + name.to_s + "}", variables[name] else fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}." end else # use default value url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value] end end url end