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]
code[RW]
Public Class Methods
new(response)
click to toggle source
# File lib/mailgun.rb, line 194 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.rb, line 203 def to_h begin JSON.parse(@body) rescue Exception => e raise ParseError.new(e), e end 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.rb, line 215 def to_h! begin @body = JSON.parse(@body) rescue Exception => e raise ParseError.new(e), e end end
to_yaml()
click to toggle source
Return response as Yaml
@return [String] A string containing response as YAML
# File lib/mailgun.rb, line 227 def to_yaml begin YAML::dump(JSON.parse(@body)) rescue Exception => e raise ParseError.new(e), e end end
to_yaml!()
click to toggle source
Replace @body with YAML
@return [String] A string containing response as YAML
# File lib/mailgun.rb, line 239 def to_yaml! begin @body = YAML::dump(JSON.parse(@body)) rescue Exception => e raise ParseError.new(e), e end end