Class: Atomsphere::Api::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, response) ⇒ Response

Returns a new instance of Response.



8
9
10
11
12
13
# File 'lib/atomsphere/api/response.rb', line 8

def initialize(request, response)
  @request  = request
  @response = response
  @code     = response.nil? ? nil : response.code.to_i
  @message  = response.nil? ? nil : response.message
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



6
7
8
# File 'lib/atomsphere/api/response.rb', line 6

def code
  @code
end

#messageObject (readonly)

Returns the value of attribute message.



6
7
8
# File 'lib/atomsphere/api/response.rb', line 6

def message
  @message
end

#requestObject (readonly)

Returns the value of attribute request.



6
7
8
# File 'lib/atomsphere/api/response.rb', line 6

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'lib/atomsphere/api/response.rb', line 6

def response
  @response
end

Instance Method Details

#to_hashObject



15
16
17
18
19
20
21
# File 'lib/atomsphere/api/response.rb', line 15

def to_hash
  begin
    JSON.parse @response.body
  rescue JSON::ParserError
    @response.body
  end if @response
end