class Buckaruby::Response
Base class for any response.
Attributes
params[R]
Public Class Methods
new(body, config)
click to toggle source
# File lib/buckaruby/response.rb, line 13 def initialize(body, config) @logger = config.logger @response = parse_response(body) @params = Support::CaseInsensitiveHash.new(@response) @logger.debug("[response] params: #{params.inspect}") verify_signature!(@response, config) end
Public Instance Methods
additional()
click to toggle source
# File lib/buckaruby/response.rb, line 47 def additional @additional ||= begin additional = Support::CaseInsensitiveHash.new params.each do |key, value| next unless key.upcase.start_with?("ADD_") new_key = key.to_s[4..-1] additional[new_key] = value end additional end end
custom()
click to toggle source
# File lib/buckaruby/response.rb, line 32 def custom @custom ||= begin custom = Support::CaseInsensitiveHash.new params.each do |key, value| next unless key.upcase.start_with?("CUST_") new_key = key.to_s[5..-1] custom[new_key] = value end custom end end
status()
click to toggle source
# File lib/buckaruby/response.rb, line 24 def status TransactionStatus.parse(params[:brq_statuscode]) end
timestamp()
click to toggle source
# File lib/buckaruby/response.rb, line 28 def timestamp parse_time(params[:brq_timestamp]) end
Private Instance Methods
parse_response(body)
click to toggle source
# File lib/buckaruby/response.rb, line 64 def parse_response(body) if body.is_a?(Hash) response = body else response = CGI.parse(body) response.each { |key, value| response[key] = value.first } end response end
parse_time(time)
click to toggle source
# File lib/buckaruby/response.rb, line 86 def parse_time(time) time ? Time.strptime(time, '%Y-%m-%d %H:%M:%S') : nil end
verify_signature!(response, config)
click to toggle source
# File lib/buckaruby/response.rb, line 75 def verify_signature!(response, config) if params[:brq_apiresult].nil? || params[:brq_apiresult].casecmp("fail") != 0 sent_signature = params[:brq_signature] generated_signature = Signature.generate_signature(response, config) if sent_signature != generated_signature raise SignatureException.new(sent_signature, generated_signature) end end end