Class: Castle::Response
- Inherits:
-
Object
- Object
- Castle::Response
- Defined in:
- lib/castle/response.rb
Overview
parses api response
Constant Summary collapse
- RESPONSE_ERRORS =
{ 400 => Castle::BadRequestError, 401 => Castle::, 403 => Castle::ForbiddenError, 404 => Castle::NotFoundError, 419 => Castle::, 422 => Castle::InvalidParametersError }.freeze
Instance Method Summary collapse
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #parse ⇒ Object
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
15 16 17 18 |
# File 'lib/castle/response.rb', line 15 def initialize(response) @response = response verify_response_code end |
Instance Method Details
#parse ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/castle/response.rb', line 20 def parse response_body = @response.body return {} if response_body.nil? || response_body.empty? begin JSON.parse(response_body, symbolize_names: true) rescue JSON::ParserError raise Castle::ApiError, 'Invalid response from Castle API' end end |