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.



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

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.



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

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



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

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