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 collapse
- MAGIC_D =
'D'
- MESSAGE =
'Message'
- CODE =
'Code'
- RESULTS =
'Results'
- SUCCESS =
'Success'
- PAGINATION =
'Pagination'
- DETAILS =
'Details'
- ERRORS =
'Errors'
- SPARKQL_ERRORS =
'SparkQLErrors'
Constants included from Response
Instance Method Summary collapse
-
#initialize(d, request_id = nil) ⇒ ApiResponse
constructor
A new instance of ApiResponse.
Methods included from Response
Constructor Details
#initialize(d, request_id = nil) ⇒ ApiResponse
Returns a new instance of ApiResponse.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# 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. = 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 |