Class: Improvmx::Response

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

Overview

Ruby representation of ImprovMX response

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



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

def initialize(response)
  @body = response.body
  @code = response.code
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



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

def body
  @body
end

#codeObject

Returns the value of attribute code.



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

def code
  @code
end

#headersObject (readonly)

Returns the value of attribute headers.



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

def headers
  @headers
end

Instance Method Details

#ok?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/improvmx/response.rb', line 22

def ok?
  @code == 200
end

#to_hHash

Return response as Ruby Hash

Returns:

  • (Hash)

    A standard Ruby Hash containing the HTTP result.



14
15
16
17
18
# File 'lib/improvmx/response.rb', line 14

def to_h
  JSON.parse(@body)
rescue StandardError => e
  raise ParseError.new(e), e
end