Class: Atum::Core::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/atum/core/response.rb

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



4
5
6
# File 'lib/atum/core/response.rb', line 4

def initialize(response)
  @response = response
end

Instance Method Details

#bodyObject



8
9
10
# File 'lib/atum/core/response.rb', line 8

def body
  json? ? handle_json : handle_raw
end

#error?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/atum/core/response.rb', line 18

def error?
  @response.status >= 400
end

#json?Boolean

Returns:

  • (Boolean)


12
13
14
15
16
# File 'lib/atum/core/response.rb', line 12

def json?
  content_type = @response.headers['Content-Type'] ||
                 @response.headers['content-type'] || ''
  content_type.include?('application/json')
end

#limitObject



30
31
32
# File 'lib/atum/core/response.rb', line 30

def limit
  meta.fetch('limit', nil)
end

#metaObject



22
23
24
25
26
27
28
# File 'lib/atum/core/response.rb', line 22

def meta
  unless json?
    raise ResponseError, 'Cannot fetch meta for non JSON response'
  end

  json_body.fetch('meta', {})
end