class ActiveDiigo::ResponseObject
Attributes
parsed_objects[R]
parsed_response[R]
raw_response[R]
Public Class Methods
new(http_response, receiver_klass)
click to toggle source
# File lib/active_diigo/response_object.rb, line 28 def initialize(http_response, receiver_klass) @raw_response, @receiver_klass = http_response, receiver_klass validate_response! @parsed_objects = build_objects end
Private Instance Methods
build_object(options)
click to toggle source
# File lib/active_diigo/response_object.rb, line 36 def build_object(options) @receiver_klass.new(options) end
build_objects()
click to toggle source
# File lib/active_diigo/response_object.rb, line 40 def build_objects parse! and @parsed_response.collect{|pr| build_object(pr) } end
parse!()
click to toggle source
# File lib/active_diigo/response_object.rb, line 44 def parse! @parsed_response = JSON.parse(@raw_response) rescue @raw_response.parsed_response end
validate_response!()
click to toggle source
# File lib/active_diigo/response_object.rb, line 48 def validate_response! case @raw_response.response.class.to_s when Net::HTTPUnauthorized.to_s then raise ActiveDiigo::Errors::NotAuthorizedError.new when Net::HTTPBadRequest.to_s then raise ActiveDiigo::Errors::BadRequestError.new when Net::HTTPForbidden.to_s then raise ActiveDiigo::Errors::ForbiddenError.new when Net::HTTPNotFound.to_s then raise ActiveDiigo::Errors::NotFoundError.new when Net::HTTPInternalServerError.to_s then raise ActiveDiigo::Errors::InternalServerError.new when Net::HTTPServiceUnavailable.to_s then raise ActiveDiigo::Errors::ServiceUnavailableError.new when Net::HTTPBadGateway.to_s then raise ActiveDiigo::Errors::BadGatewayError.new end end