class V2Intuity::Response

Attributes

errors[RW]
request[RW]
response[RW]

Public Class Methods

new(attributes = {}) click to toggle source
# File lib/v2_intuity/response.rb, line 5
def initialize(attributes = {})
  @request = attributes[:request]
  @response = attributes[:response]
  @errors = []
end

Public Instance Methods

add_errors(error) click to toggle source
# File lib/v2_intuity/response.rb, line 24
def add_errors(error)
  @errors.push(error)
end
body() click to toggle source
# File lib/v2_intuity/response.rb, line 20
def body
  !@response.nil? ? @response.body : nil
end
code() click to toggle source
# File lib/v2_intuity/response.rb, line 40
def code
  !@response.nil? ? @response.code : nil
end
define_response_and_json(response) click to toggle source
# File lib/v2_intuity/response.rb, line 11
def define_response_and_json(response)
  @response = response if @response.nil?
  g_json if @json.nil?
end
g_json() click to toggle source
# File lib/v2_intuity/response.rb, line 34
def g_json # store parsed response so we don't have to reparse
  return @json if @json

  json(parse_json(@response.body)) unless @response.to_s.nil?
end
headers() click to toggle source
# File lib/v2_intuity/response.rb, line 16
def headers
  !@response.nil? ? @response.headers : nil
end
message() click to toggle source
# File lib/v2_intuity/response.rb, line 44
def message
  !@response.nil? ? @response.message : nil
end
success?() click to toggle source
# File lib/v2_intuity/response.rb, line 28
def success?
  return nil if @response.nil?

  @errors.to_a.empty? ? true : false
end

Private Instance Methods

json(json) click to toggle source
# File lib/v2_intuity/response.rb, line 56
def json(json)
  @json = json
end
parse_json(body) click to toggle source
# File lib/v2_intuity/response.rb, line 50
def parse_json(body) # function that makes sure string
  JSON.parse(body)
rescue
  nil
end