class Mailgun::Response

A Mailgun::Response object is instantiated for each response generated by the Client request. The Response object supports deserialization of the JSON result. Or, if you prefer JSON or YAML formatting, call the method for conversion.

See the Github documentation for full examples.

Attributes

body[RW]

All responses have a payload and a code corresponding to http, though

slightly different
code[RW]

All responses have a payload and a code corresponding to http, though

slightly different

Public Class Methods

from_hash(h) click to toggle source
# File lib/mailgun/response.rb, line 15
def self.from_hash(h)
  # Create a "fake" response object with the data passed from h
  self.new OpenStruct.new(h)
end
new(response) click to toggle source
# File lib/mailgun/response.rb, line 20
def initialize(response)
  @body = response.body
  @code = response.code
end

Public Instance Methods

to_h() click to toggle source

Return response as Ruby Hash

@return [Hash] A standard Ruby Hash containing the HTTP result.

# File lib/mailgun/response.rb, line 29
def to_h
  JSON.parse(@body)
rescue => err
  raise ParseError.new(err), err
end
to_h!() click to toggle source

Replace @body with Ruby Hash

@return [Hash] A standard Ruby Hash containing the HTTP result.

# File lib/mailgun/response.rb, line 38
def to_h!
  @body = JSON.parse(@body)
rescue => err
  raise ParseError.new(err), err
end
to_yaml() click to toggle source

Return response as Yaml

@return [String] A string containing response as YAML

# File lib/mailgun/response.rb, line 47
def to_yaml
  YAML.dump(to_h)
rescue => err
  raise ParseError.new(err), err
end
to_yaml!() click to toggle source

Replace @body with YAML

@return [String] A string containing response as YAML

# File lib/mailgun/response.rb, line 56
def to_yaml!
  @body = YAML.dump(to_h)
rescue => err
  raise ParseError.new(err), err
end