Class: VantivLite::Response

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/vantiv_lite/response.rb

Defined Under Namespace

Modules: Refinements

Constant Summary collapse

ServerError =
Class.new(StandardError)
ROOT_KEY =
'litleOnlineResponse'.freeze
Dig =
lambda do |obj, key, *next_keys|
  begin
    next_obj = obj[key]
    next_obj.nil? || next_keys.empty? ? next_obj : next_obj.dig(*next_keys)
  rescue NoMethodError
    raise TypeError, "#{next_obj.class.name} does not have #dig method"
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response, *dig_keys, parser:) ⇒ Response

Returns a new instance of Response.



37
38
39
40
# File 'lib/vantiv_lite/response.rb', line 37

def initialize(http_response, *dig_keys, parser:)
  http_ok?(http_response)
  @to_h = response_hash_with(parser.(http_response.body), dig_keys)
end

Instance Attribute Details

#to_hObject (readonly) Also known as: to_hash

Returns the value of attribute to_h.



34
35
36
# File 'lib/vantiv_lite/response.rb', line 34

def to_h
  @to_h
end

Instance Method Details

#[](key) ⇒ Object



42
43
44
# File 'lib/vantiv_lite/response.rb', line 42

def [](key)
  @to_h[key]
end

#dig(key, *next_keys) ⇒ Object



46
47
48
# File 'lib/vantiv_lite/response.rb', line 46

def dig(key, *next_keys)
  Dig.(@to_h, key, *next_keys)
end

#each(*args, &blk) ⇒ Object



50
51
52
# File 'lib/vantiv_lite/response.rb', line 50

def each(*args, &blk)
  @to_h.each(*args, &blk)
end