class SparkApi::ApiResponse

Nice and handy class wrapper for the api response hash

Constants

CODE
DETAILS
ERRORS
MAGIC_D
MESSAGE
PAGINATION
RESULTS
SPARKQL_ERRORS
SUCCESS

Public Class Methods

new(d, request_id=nil) click to toggle source
Calls superclass method
# File lib/spark_api/response.rb, line 23
def initialize d, request_id=nil
  begin
    self.d = d[MAGIC_D]
    if self.d.nil? || self.d.empty?
      raise InvalidResponse, "The server response could not be understood"
    end
    self.message    = self.d[MESSAGE]
    self.code       = self.d[CODE]
    self.results    = Array(self.d[RESULTS])
    self.success    = self.d[SUCCESS]
    self.pagination = self.d[PAGINATION]
    self.details    = self.d[DETAILS] || []
    self.errors     = self.d[ERRORS]
    self.sparkql_errors = self.d[SPARKQL_ERRORS]
    self.request_id = request_id
    super(results)
  rescue Exception => e
    SparkApi.logger.error "Unable to understand the response! #{d}"
    raise
  end
end