module Ebanx
Constants
- VERSION
Attributes
integration_key[RW]
parse_response[RW]
test_mode[RW]
Public Class Methods
base_uri()
click to toggle source
# File lib/ebanx.rb, line 54 def self.base_uri if @test_mode 'https://sandbox.ebanxpay.com/ws/' else 'https://api.ebanxpay.com/ws/' end end
Protected Class Methods
get_command_class(method)
click to toggle source
# File lib/ebanx.rb, line 114 def self.get_command_class(method) method = method.gsub /^do_/, '' class_name = 'Ebanx::Command::' + method.split('_').map { |w| w.capitalize }.join Object.const_get class_name end
merge_default_params(command, params)
click to toggle source
# File lib/ebanx.rb, line 75 def self.merge_default_params(command, params) return params if params.empty? params = params[0].merge integration_key: @integration_key if command.name =~ /Direct$/ params = params.merge! operation: 'request', mode: 'full' end params end
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/ebanx.rb, line 106 def self.method_missing(method, *args, &block) if method.to_s =~ /^do_[a-z]+/ run_command method.to_s, args else super end end
request(command)
click to toggle source
# File lib/ebanx.rb, line 86 def self.request(command) uri = Ebanx::base_uri + command.request_action begin case command.request_method when :post response = RestClient::Request.execute(:method => :post, content_type: command.response_type, :url => uri, :payload => command.params, :timeout => nil, :open_timeout => nil) when :get response = RestClient.get uri, params: command.params else raise ArgumentError "Request method #{command.request_method.to_s} is not supported." end rescue RestClient::ExceptionWithResponse => e message = (JSON.parse(e.response)['message'] rescue nil) || e.message raise EbanxApiException.new(message, e.response, e.http_code) end Ebanx::Response.new response, command.response_type end
run_command(method, params)
click to toggle source
# File lib/ebanx.rb, line 63 def self.run_command(method, params) klass = get_command_class method required_params = klass.instance_method(:initialize).parameters.size raise ArgumentError if (!params[0] || params[0].length == 0) && required_params != 0 command = required_params == 0 ? klass.new : klass.new(merge_default_params(klass, params)) command.valid? request command end