Class: SparkApi::ApiResponse
- Inherits:
-
Array
- Object
- Array
- SparkApi::ApiResponse
- 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
Instance Method Summary collapse
-
#initialize(d) ⇒ ApiResponse
constructor
A new instance of ApiResponse.
Methods included from Response
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. = 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 |