Class: Improvmx::Response
- Inherits:
-
Object
- Object
- Improvmx::Response
- Defined in:
- lib/improvmx/response.rb
Overview
Ruby representation of ImprovMX response
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#code ⇒ Object
Returns the value of attribute code.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Instance Method Summary collapse
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #ok? ⇒ Boolean
-
#to_h ⇒ Hash
Return response as Ruby Hash.
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
6 7 8 9 |
# File 'lib/improvmx/response.rb', line 6 def initialize(response) @body = response.body @code = response.code end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
4 5 6 |
# File 'lib/improvmx/response.rb', line 4 def body @body end |
#code ⇒ Object
Returns the value of attribute code.
4 5 6 |
# File 'lib/improvmx/response.rb', line 4 def code @code end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
20 21 22 |
# File 'lib/improvmx/response.rb', line 20 def headers @headers end |
Instance Method Details
#ok? ⇒ Boolean
22 23 24 |
# File 'lib/improvmx/response.rb', line 22 def ok? @code == 200 end |
#to_h ⇒ Hash
Return response as Ruby Hash
14 15 16 17 18 |
# File 'lib/improvmx/response.rb', line 14 def to_h JSON.parse(@body) rescue StandardError => e raise ParseError.new(e), e end |