Sha256: 0c547132fdad3ab15d83c71405ccc4b46c19294d13ffe419b00106f181daf1b7
Contents?: true
Size: 930 Bytes
Versions: 1
Compression:
Stored size: 930 Bytes
Contents
require 'json' # ApiClient::Parser provides a method to parse the request response. module ApiClient::Parser # Parse the JSON response. # # @param [HTTP] response HTTP object for the request. # @return [Array] the code and the body parsed. def self.response(response) raise_exception(response.code) begin object = ::JSON.parse(response.body) rescue ::JSON::ParserError, TypeError object = {} end object end protected def self.raise_exception(code) case code.to_i when 401 then raise ApiClient::Exceptions::Unauthorized when 403 then raise ApiClient::Exceptions::Forbidden when 404 then raise ApiClient::Exceptions::NotFound when 500 then raise ApiClient::Exceptions::InternalServerError when 502 then raise ApiClient::Exceptions::BadGateway when 503 then raise ApiClient::Exceptions::ServiceUnavailable else return end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
api-client-1.8.2 | lib/api-client/parser.rb |