Class: Deliverhq::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server_response) ⇒ Response

Returns a new instance of Response.



6
7
8
9
10
11
12
13
14
# File 'lib/deliverhq/response.rb', line 6

def initialize(server_response)
  if server_response.status == 200
    @body = server_response.body.strip.length > 0 ? JSON.parse(server_response.body) : server_response.body
  else
    raise RequestError, "Server responded with #{server_response.status}: #{server_response.body}"
  end
rescue JSON::ParserError
  @body = server_response.body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



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

def body
  @body
end