Sha256: 15142d890a4e192a9818e6a9580c3126633b04cc3fa04750f8dd0e87ae3bb3be
Contents?: true
Size: 951 Bytes
Versions: 29
Compression:
Stored size: 951 Bytes
Contents
module SparkApi # API Response interface module Response ATTRIBUTES = [:code, :message, :results, :success, :pagination, :details] attr_accessor *ATTRIBUTES def success? @success end end # Nice and handy class wrapper for the api response hash class ApiResponse < ::Array include SparkApi::Response 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 end end
Version data entries
29 entries across 29 versions & 1 rubygems