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.
173 174 175 176 |
# File 'lib/mailgun.rb', line 173 def initialize(response) @body = response.body @code = response.code end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
170 171 172 |
# File 'lib/mailgun.rb', line 170 def body @body end |
#code ⇒ Object
Returns the value of attribute code.
171 172 173 |
# File 'lib/mailgun.rb', line 171 def code @code end |
Instance Method Details
#to_h ⇒ Hash
Return response as Ruby Hash
182 183 184 185 186 187 188 |
# File 'lib/mailgun.rb', line 182 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
194 195 196 197 198 199 200 |
# File 'lib/mailgun.rb', line 194 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
206 207 208 209 210 211 212 |
# File 'lib/mailgun.rb', line 206 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
218 219 220 221 222 223 224 |
# File 'lib/mailgun.rb', line 218 def to_yaml! begin @body = YAML::dump(JSON.parse(@body)) rescue Exception => e raise ParseError.new(e), e end end |