class Grac::Response

Public Class Methods

new(typhoeus_response) click to toggle source
# File lib/grac/response.rb, line 15
def initialize(typhoeus_response)
  @response    = typhoeus_response
end

Public Instance Methods

content_type() click to toggle source
# File lib/grac/response.rb, line 19
def content_type
  @response.headers["Content-Type"]
end
json_content?() click to toggle source
# File lib/grac/response.rb, line 23
def json_content?
  !content_type.nil? && content_type.match('application/json')
end
parsed_json() click to toggle source
# File lib/grac/response.rb, line 27
def parsed_json
  Oj.load(body)
rescue Oj::ParseError, EncodingError
  raise Exception::InvalidContent.new(body, 'json')
end
parsed_or_raw_body() click to toggle source
# File lib/grac/response.rb, line 33
def parsed_or_raw_body
  return body unless json_content?

  begin
    parsed_json
  rescue Exception::InvalidContent
    body
  end
end