Class: Ondotori::WebAPI::Api::Response
- Inherits:
-
Object
- Object
- Ondotori::WebAPI::Api::Response
- Defined in:
- lib/ondotori/webapi/api/response.rb
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #validate ⇒ Object
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
9 10 11 12 13 |
# File 'lib/ondotori/webapi/api/response.rb', line 9 def initialize(response) @response = response validate @result = JSON.parse(@response.body) end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
7 8 9 |
# File 'lib/ondotori/webapi/api/response.rb', line 7 def result @result end |
Instance Method Details
#validate ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ondotori/webapi/api/response.rb', line 15 def validate unless @response.code == "200" result = JSON.parse(@response.body) if result.key?("error") code = result["error"]["code"] = result["error"]["message"] raise Ondotori::WebAPI::Api::Errors::ResponseError.new(, code) end # unknown error... raise Ondotori::WebAPI::Api::Errors::Error.new("Server response code [#{@response.code}]", 9996) end end |