Class: Instamojo::Response
- Inherits:
-
Object
- Object
- Instamojo::Response
- Defined in:
- lib/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
Instance Method Summary collapse
-
#initialize(hash) ⇒ Response
constructor
A new instance of Response.
- #response_success? ⇒ Boolean
- #success? ⇒ Boolean
Constructor Details
#initialize(hash) ⇒ Response
Returns a new instance of Response.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/response.rb', line 5 def initialize(hash) @code = hash.status if hash.body begin @body = JSON.parse(hash.body) rescue JSON::ParserError @body = {:client_error => "Something went wrong", :original => hash.body.to_s} end @body.symbolize_keys! @status = @body[:success] end end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
3 4 5 |
# File 'lib/response.rb', line 3 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
3 4 5 |
# File 'lib/response.rb', line 3 def code @code end |
Instance Method Details
#response_success? ⇒ Boolean
18 19 20 |
# File 'lib/response.rb', line 18 def response_success? [200, 201, 202, 203, 204].include? @code end |
#success? ⇒ Boolean
22 23 24 |
# File 'lib/response.rb', line 22 def success? (@status && (@status.eql?(true) || @status.downcase == 'success')) || response_success? end |