Class: Howitzer::MailgunApi::Response

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

Overview

A MailgunApi::Response object is instantiated for each response generated by the Client request. The Response object supports deserialization of the JSON result.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



11
12
13
14
# File 'lib/howitzer/mailgun_api/response.rb', line 11

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

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



9
10
11
# File 'lib/howitzer/mailgun_api/response.rb', line 9

def body
  @body
end

#codeObject

Returns the value of attribute code.



9
10
11
# File 'lib/howitzer/mailgun_api/response.rb', line 9

def code
  @code
end

Instance Method Details

#to_hHash

Return a response as a Ruby Hash

Returns:

  • (Hash)

    HTTP result as hash.

Raises:

  • (ParseError)

    in case of an json parsing error



20
21
22
23
24
# File 'lib/howitzer/mailgun_api/response.rb', line 20

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