Class: SparkApi::ApiResponse

Inherits:
Array
  • Object
show all
Includes:
Response
Defined in:
lib/spark_api/response.rb

Overview

Nice and handy class wrapper for the api response hash

Constant Summary

Constants included from Response

Response::ATTRIBUTES

Instance Method Summary collapse

Methods included from Response

#success?

Constructor Details

#initialize(d) ⇒ ApiResponse

Returns a new instance of ApiResponse.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/spark_api/response.rb', line 14

def initialize(d)
  begin
    self.d = d["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['SparkQLErrors']
    super(results)
  rescue Exception => e
    SparkApi.logger.error "Unable to understand the response! #{d}"
    raise
  end
end