Class: Analysand::Response

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
ResponseHeaders, StatusCodePredicates
Defined in:
lib/analysand/response.rb

Overview

The response object is a wrapper around Net::HTTPResponse that provides a few amenities:

  1. A #success? method, which checks if 200 <= response code <= 299.

  2. A #conflict method, which checks if response code == 409.

  3. Automatic JSON deserialization of all response bodies.

  4. Delegates the [] property accessor to the body.

Direct Known Subclasses

BulkResponse, SessionResponse, ViewResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from StatusCodePredicates

#code, #conflict?, #not_found?, #success?, #unauthorized?

Methods included from ResponseHeaders

#cookies, #etag, #session_cookie

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



25
26
27
28
29
30
31
# File 'lib/analysand/response.rb', line 25

def initialize(response)
  @response = response

  if !@response.body.nil? && !@response.body.empty?
    @body = JSON.parse(@response.body)
  end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



21
22
23
# File 'lib/analysand/response.rb', line 21

def body
  @body
end

#responseObject (readonly)

Returns the value of attribute response.



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

def response
  @response
end