Class: Homeflow::API::Response
- Inherits:
-
Object
- Object
- Homeflow::API::Response
- Defined in:
- lib/homeflow/api/response.rb
Constant Summary collapse
- COLLECTIONS_OBJECTS =
{ "password_reset" => Homeflow::API::PasswordReset, "properties" => Homeflow::API::Property, "search" => Homeflow::API::Search, "property" => Homeflow::API::Property, "county" => Homeflow::API::County, "location" => Homeflow::API::Location, "agency" => Homeflow::API::Agency, "agencies" => Homeflow::API::Agency, "locations" => Homeflow::API::Location, "counties" => Homeflow::API::County, "branch" => Homeflow::API::Branch, "branches" => Homeflow::API::Branch, "session" => Homeflow::API::Session, "portal" => Homeflow::API::Portal, 'user' => Homeflow::API::User, 'message' => Homeflow::API::Message, "lead" => Homeflow::API::Lead, "site_content_chunk" => Homeflow::API::SiteContentChunk, "site_content_chunks" => Homeflow::API::SiteContentChunk, "postcodes" => Homeflow::API::Postcode, "postcode" => Homeflow::API::Postcode, "site_page" => Homeflow::API::SitePage, "site_pages" => Homeflow::API::SitePage, "alternative_places" => { "locations" => Homeflow::API::Location, "counties" => Homeflow::API::County }, "favourite_properties" => Homeflow::API::FavouriteProperty }
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#query ⇒ Object
Returns the value of attribute query.
-
#response ⇒ Object
Returns the value of attribute response.
-
#result ⇒ Object
Returns the value of attribute result.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash) ⇒ Response
constructor
A new instance of Response.
- #method_missing(method, *args, &block) ⇒ Object
- #respond_to?(method, include_private = false) ⇒ Boolean
Constructor Details
#initialize(hash) ⇒ Response
Returns a new instance of Response.
50 51 52 53 54 55 56 57 58 |
# File 'lib/homeflow/api/response.rb', line 50 def initialize(hash) @built_result_objects = {} @query = Hashie::Mash.new(hash["query"]) @result = build_result_objects(hash["result"]) @response = Hashie::Mash.new(hash["response"]) @error = Hashie::Mash.new(hash["error"]) errors if error.type end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/homeflow/api/response.rb', line 60 def method_missing(method, *args, &block) if @built_result_objects.has_key?(method.to_s) @built_result_objects[method.to_s] else super end end |
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
16 17 18 |
# File 'lib/homeflow/api/response.rb', line 16 def error @error end |
#query ⇒ Object
Returns the value of attribute query.
16 17 18 |
# File 'lib/homeflow/api/response.rb', line 16 def query @query end |
#response ⇒ Object
Returns the value of attribute response.
16 17 18 |
# File 'lib/homeflow/api/response.rb', line 16 def response @response end |
#result ⇒ Object
Returns the value of attribute result.
16 17 18 |
# File 'lib/homeflow/api/response.rb', line 16 def result @result end |
Class Method Details
.new_from_json(json) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/homeflow/api/response.rb', line 6 def self.new_from_json(json) begin hash = MultiJson.load(json) rescue MultiJson::LoadError raise Homeflow::API::Exceptions::InvalidResponse end raise Homeflow::API::Exceptions::InvalidResponse unless hash.is_a?(Hash) self.new(hash) end |
Instance Method Details
#respond_to?(method, include_private = false) ⇒ Boolean
69 70 71 72 73 74 75 |
# File 'lib/homeflow/api/response.rb', line 69 def respond_to?(method, include_private = false) if @built_result_objects.has_key?(method.to_s) true else super end end |