class VantivLite::Response
Constants
- Dig
- ROOT_KEY
- ServerError
Attributes
to_h[R]
to_hash[R]
Public Class Methods
new(http_response, *dig_keys, parser:)
click to toggle source
# 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
Public Instance Methods
[](key)
click to toggle source
# File lib/vantiv_lite/response.rb, line 42 def [](key) @to_h[key] end
dig(key, *next_keys)
click to toggle source
# File lib/vantiv_lite/response.rb, line 46 def dig(key, *next_keys) Dig.(@to_h, key, *next_keys) end
each(*args, &blk)
click to toggle source
# File lib/vantiv_lite/response.rb, line 50 def each(*args, &blk) @to_h.each(*args, &blk) end
Private Instance Methods
http_ok?(http_response)
click to toggle source
# File lib/vantiv_lite/response.rb, line 56 def http_ok?(http_response) raise ServerError, "server responded with #{http_response.code} instead of 200" unless http_response.code == '200' end
response_hash_with(response_hash, dig_keys)
click to toggle source
# File lib/vantiv_lite/response.rb, line 61 def response_hash_with(response_hash, dig_keys) raise ServerError, "missing root :#{ROOT_KEY}" unless (root_hash = response_hash[ROOT_KEY]) raise ServerError, root_hash['message'] unless root_hash['response'] == '0' dig_keys.any? ? root_hash.dig(*dig_keys) : root_hash end