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
# File 'lib/spark_api/response.rb', line 14

def initialize(d)
  begin
    hash = d["D"]
    if hash.nil? || hash.empty?
      raise InvalidResponse, "The server response could not be understood"
    end
    self.message    = hash["Message"]
    self.code       = hash["Code"]
    self.results    = Array(hash["Results"])
    self.success    = hash["Success"]
    self.pagination = hash["Pagination"]
    self.details    = hash["Details"] || []
    super(results)
  rescue Exception => e
    SparkApi.logger.error "Unable to understand the response! #{d}"
    raise
  end
end