Class: Mailgun::Response
- Inherits:
-
Object
- Object
- Mailgun::Response
- Defined in:
- lib/mailgun.rb
Overview
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.
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#code ⇒ Object
Returns the value of attribute code.
Instance Method Summary collapse
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
-
#to_h ⇒ Hash
Return response as Ruby Hash.
-
#to_h! ⇒ Hash
Replace @body with Ruby Hash.
-
#to_yaml ⇒ String
Return response as Yaml.
-
#to_yaml! ⇒ String
Replace @body with YAML.
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
194 195 196 197 |
# File 'lib/mailgun.rb', line 194 def initialize(response) @body = response.body @code = response.code end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
191 192 193 |
# File 'lib/mailgun.rb', line 191 def body @body end |
#code ⇒ Object
Returns the value of attribute code.
192 193 194 |
# File 'lib/mailgun.rb', line 192 def code @code end |
Instance Method Details
#to_h ⇒ Hash
Return response as Ruby Hash
203 204 205 206 207 208 209 |
# 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! ⇒ Hash
Replace @body with Ruby Hash
215 216 217 218 219 220 221 |
# 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 ⇒ String
Return response as Yaml
227 228 229 230 231 232 233 |
# 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! ⇒ String
Replace @body with YAML
239 240 241 242 243 244 245 |
# 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 |