Class: Buckaruby::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/buckaruby/response.rb

Overview

Base class for any response.

Direct Known Subclasses

ApiResponse, PushResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, config) ⇒ Response

Returns a new instance of Response.



13
14
15
16
17
18
# File 'lib/buckaruby/response.rb', line 13

def initialize(body, config)
  @response = parse_response(body)

  logger = config.logger
  logger.debug("[response] params: #{params.inspect}")
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



11
12
13
# File 'lib/buckaruby/response.rb', line 11

def response
  @response
end

Instance Method Details

#additionalObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 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

#customObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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

#paramsObject



20
21
22
# File 'lib/buckaruby/response.rb', line 20

def params
  @params ||= Support::CaseInsensitiveHash.new(response)
end

#statusObject



24
25
26
# File 'lib/buckaruby/response.rb', line 24

def status
  TransactionStatus.parse(params[:brq_statuscode])
end

#timestampObject



28
29
30
# File 'lib/buckaruby/response.rb', line 28

def timestamp
  parse_time(params[:brq_timestamp])
end