Class: VantivLite::Response
- Inherits:
-
Object
- Object
- VantivLite::Response
- 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
-
#to_h ⇒ Object
(also: #to_hash)
readonly
Returns the value of attribute to_h.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #dig(key, *next_keys) ⇒ Object
- #each(*args, &blk) ⇒ Object
-
#initialize(http_response, *dig_keys, parser:) ⇒ Response
constructor
A new instance of Response.
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_h ⇒ Object (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 |