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? ? json_body : raw_body
end

#error?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/atum/core/response.rb', line 26

def error?
  @response.status >= 400
end

#headersObject



16
17
18
# File 'lib/atum/core/response.rb', line 16

def headers
  @response.headers
end

#json?Boolean

Returns:

  • (Boolean)


20
21
22
23
24
# 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

#limitObject



38
39
40
# File 'lib/atum/core/response.rb', line 38

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

#metaObject



30
31
32
33
34
35
36
# 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

#statusObject



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

def status
  @response.status
end