class Atum::Core::Response

Public Class Methods

new(response) click to toggle source
# File lib/atum/core/response.rb, line 4
def initialize(response)
  @response = response
end

Public Instance Methods

body() click to toggle source
# File lib/atum/core/response.rb, line 8
def body
  json? ? json_body : raw_body
end
error?() click to toggle source
# File lib/atum/core/response.rb, line 26
def error?
  @response.status >= 400
end
headers() click to toggle source
# File lib/atum/core/response.rb, line 16
def headers
  @response.headers
end
json?() click to toggle source
# File lib/atum/core/response.rb, line 20
def json?
  content_type = @response.headers['Content-Type'] ||
                 @response.headers['content-type'] || ''
  content_type.include?('application/json')
end
limit() click to toggle source
# File lib/atum/core/response.rb, line 38
def limit
  meta.fetch('limit', nil)
end
meta() click to toggle source
# File lib/atum/core/response.rb, line 30
def meta
  unless json?
    raise ResponseError, 'Cannot fetch meta for non JSON response'
  end

  json_body.fetch('meta', {})
end
status() click to toggle source
# File lib/atum/core/response.rb, line 12
def status
  @response.status
end

Private Instance Methods

json_body() click to toggle source
# File lib/atum/core/response.rb, line 44
def json_body
  @json_body ||= JSON.parse(@response.body).with_indifferent_access
end
raw_body() click to toggle source
# File lib/atum/core/response.rb, line 48
def raw_body
  @response.body
end