Class: Buzz::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ Response

Returns a new instance of Response.



9
10
11
12
13
14
# File 'lib/buzz/response.rb', line 9

def initialize(http_response)
  @status = http_response.code.to_i
  @headers = http_response.to_hash
  @body = http_response.body
  @data = parse_body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/buzz/response.rb', line 7

def body
  @body
end

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'lib/buzz/response.rb', line 7

def data
  @data
end

#headersObject (readonly)

Returns the value of attribute headers.



7
8
9
# File 'lib/buzz/response.rb', line 7

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



7
8
9
# File 'lib/buzz/response.rb', line 7

def status
  @status
end

Instance Method Details

#countObject



24
25
26
# File 'lib/buzz/response.rb', line 24

def count
  data["count"] if data.is_a?(Hash)
end

#next_urlObject



28
29
30
# File 'lib/buzz/response.rb', line 28

def next_url
  data["next"] if data.is_a?(Hash)
end

#previous_urlObject



32
33
34
# File 'lib/buzz/response.rb', line 32

def previous_url
  data["previous"] if data.is_a?(Hash)
end

#resultsObject



20
21
22
# File 'lib/buzz/response.rb', line 20

def results
  data["results"] if data.is_a?(Hash)
end

#success?Boolean

Returns:

  • (Boolean)


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

def success?
  status >= 200 && status < 300
end