Class: Response
- Inherits:
-
Object
- Object
- Response
- Defined in:
- lib/repro/api/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Instance Method Summary collapse
- #code ⇒ Object
-
#initialize(res) ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(res) ⇒ Response
Returns a new instance of Response.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/repro/api/response.rb', line 7 def initialize(res) @code = res.code @message = res.is_a?(Net::HTTPSuccess) ? nil : res. @body = JSON.parse(res.body) @error = if @body['error'] && @body['error']['messages'] if @body['error']['messages'].is_a?(Array) @body['error']['messages'].join('. ') else @body['error']['messages'] end else @body['error'] end end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
5 6 7 |
# File 'lib/repro/api/response.rb', line 5 def body @body end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
5 6 7 |
# File 'lib/repro/api/response.rb', line 5 def error @error end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
5 6 7 |
# File 'lib/repro/api/response.rb', line 5 def @message end |
Instance Method Details
#code ⇒ Object
22 23 24 |
# File 'lib/repro/api/response.rb', line 22 def code @code.to_i end |