lib/todoable_api/http_requestable.rb
# Parses response from server
# If 200..300 response, we will return either a Hash object otherwise the body of the response
# 422 will raise an error but with the errors returned by the server
Parses response from server
If 200..300 response, we will return either a Hash object otherwise the body of the response
422 will raise an error but with the errors returned by the server
Parses response from server If 200 .. 300 response we will return either a Hash object otherwise the body of the response 422 will raise an error but with the errors returned by the server
def handle_api_response(response)
      case response.code.to_i
      when 204
        true
      when 200..300
        begin
          JSON.parse(response.body)
        rescue JSON::ParserError
          response.body
        end
      when 401
        raise TodoableApi::Unauthorized
      when 404
        raise TodoableApi::NotFound
      when 422
        raise TodoableApi::UnprocessableEntity, JSON.parse(response.body)
      when 500
        raise TodoableApi::InternalServerError
      end
    end
def handle_api_response ( response ) case response . code . to_i when 204 true when 200 .. 300 begin JSON . parse ( response . body ) rescue JSON :: ParserError response . body end when 401 raise TodoableApi :: Unauthorized when 404 raise TodoableApi :: NotFound when 422 raise TodoableApi :: UnprocessableEntity , JSON . parse ( response . body ) when 500 raise TodoableApi :: InternalServerError end end
Parses response from server
If 200..300 response, we will return either a Hash object otherwise the body of the response
422 will raise an error but with the errors returned by the server
Parses response from server If 200 .. 300 response we will return either a Hash object otherwise the body of the response 422 will raise an error but with the errors returned by the server
response