Class: FlexmlsApi::ApiResponse

Inherits:
Array
  • Object
show all
Includes:
Response
Defined in:
lib/flexmls_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.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/flexmls_api/response.rb', line 51

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
    FlexmlsApi.logger.error "Unable to understand the response! #{d}"
    raise
  end
end