Class: Datacentred::Response

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

Overview

A response from the API server.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server_response) ⇒ Response

A response from the API server, initialized with A Faraday HTTP Response.

Parameters:

  • server_response (Faraday::Response)

    A response object returned from Faraday.

Raises:

  • (Errors::Error)

    Raised if response isn't a 2xx status code.



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

def initialize(server_response)
  @body = JSON.parse server_response.body rescue nil
  @status = server_response.status
  Errors.raise_unless_successful(status, @body)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body



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

def body
  @body
end

#statusObject (readonly)

Returns the value of attribute status



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

def status
  @status
end