module LittleBird::Response

Public Instance Methods

error(response) click to toggle source
# File lib/response.rb, line 3
def error(response)
  {
    authorization: AuthorizationError.new(response),
    internal: InternalError.new(response),
    parameter: ParameterError.new(response),
    rate_limit: RateLimitError.new(response)
  }[response["error_type"].to_sym]
end
interpret(response, cast_class) click to toggle source
# File lib/response.rb, line 16
def interpret(response, cast_class)
  raise error(response), response["error"] if response_is_an_error(response)
  if cast_class.class == Array
    return iterate(response, cast_class.first)
  else
    return respond_as_class(response, cast_class)
  end
end
iterate(response, cast_class) click to toggle source
# File lib/response.rb, line 25
def iterate(response, cast_class)
  response.map do |response_obj|
    respond_as_class(response_obj, cast_class)
  end
end
respond_as_class(response_obj, cast_class) click to toggle source
# File lib/response.rb, line 36
def respond_as_class(response_obj, cast_class)
  object = cast_class.new(response_obj)
  set_client(object)
  object
end
response_is_an_error(response) click to toggle source
# File lib/response.rb, line 12
def response_is_an_error(response)
  response.class == Hash && !response["error"].nil?
end
set_client(object) click to toggle source
# File lib/response.rb, line 31
def set_client(object)
  object.instance_eval { class << self; self end }.send(:attr_accessor, :client)
  object.client = self
end