Module: JustimmoClient::V1::RealtyInterface
- Extended by:
- Utils, JustimmoInterface
- Defined in:
- lib/justimmo_client/api/v1/interfaces/realty_interface.rb
Overview
Public realty query interface
Glues all components together. Handles caching, parsing and converting XML and JSON into data models.
Class Method Summary collapse
- .categories(options = {}) ⇒ Array<RealtyCategory>
- .countries(options = {}) ⇒ Array<Country>
-
.detail(id, lang: nil) ⇒ Realty?
A detailed realty object, or nil if it could not be found.
-
.details(options = {}) ⇒ Array<Realty>
An array of detailed realty objects, or an empty array on error.
- .federal_states(options = {}) ⇒ Array<FederalState>
-
.ids(options = {}) ⇒ Array<Integer>
An array of realty ids, empty array if no results.
-
.list(options = {}) ⇒ Array<Realty>
An array of basic realty objects, or an empty array on error.
- .regions(options = {}) ⇒ Array<Region>
- .types(options = {}) ⇒ Array<RealtyType>
- .zip_codes_and_cities(options = {}) ⇒ Array<City>
Methods included from Utils
Methods included from JustimmoInterface
Methods included from API
#api, #interface, #model, #representer, #request, #versioned_api
Methods included from Logging
default_logger, #logger, rails_logger
Methods included from Caching
Class Method Details
.categories(options = {}) ⇒ Array<RealtyCategory>
119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/justimmo_client/api/v1/interfaces/realty_interface.rb', line 119 def categories( = {}) with_cache cache_key("realty/categories", ), on_hit: ->(cached) do representer(:realty_category, :json).for_collection.new([]).from_json(cached) end, on_miss: -> do xml_response = request(:realty).categories() represented = representer(:realty_category).for_collection.new([]).from_xml(xml_response) new_cache = representer(:realty_category, :json).for_collection.new(represented).to_json [represented, new_cache] end rescue JustimmoClient::RetrievalFailed [] end |
.countries(options = {}) ⇒ Array<Country>
153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/justimmo_client/api/v1/interfaces/realty_interface.rb', line 153 def countries( = {}) with_cache cache_key("realty/countries", ), on_hit: ->(cached) do representer(:country, :json).for_collection.new([]).from_json(cached) end, on_miss: -> do xml_response = request(:realty).countries() represented = representer(:country).for_collection.new([]).from_xml(xml_response) new_cache = representer(:country, :json).for_collection.new(represented).to_json [represented, new_cache] end rescue JustimmoClient::RetrievalFailed [] end |
.detail(id, lang: nil) ⇒ Realty?
Returns A detailed realty object, or nil if it could not be found.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/justimmo_client/api/v1/interfaces/realty_interface.rb', line 82 def detail(id, lang: nil) with_cache cache_key("realty/detail", id: id, lang: lang), on_hit: ->(cached) do representer(:realty, :json).new(model(:realty).new).from_json(cached) end, on_miss: -> do xml_response = request(:realty).detail(id, lang: lang) represented = representer(:realty).for_collection.new([]).from_xml(xml_response).first new_cache = representer(:realty, :json).new(represented).to_json [represented, new_cache] end rescue JustimmoClient::RetrievalFailed nil end |
.details(options = {}) ⇒ Array<Realty>
Returns An array of detailed realty objects, or an empty array on error.
99 100 101 |
# File 'lib/justimmo_client/api/v1/interfaces/realty_interface.rb', line 99 def details( = {}) ids().map { |id| detail(id) } end |
.federal_states(options = {}) ⇒ Array<FederalState>
171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/justimmo_client/api/v1/interfaces/realty_interface.rb', line 171 def federal_states( = {}) with_cache cache_key("realty/federal_states", ), on_hit: ->(cached) do representer(:federal_states, :json).for_collection.new([]).from_json(cached) end, on_miss: -> do xml_response = request(:realty).federal_states() represented = representer(:federal_state).for_collection.new([]).from_xml(xml_response) new_cache = representer(:federal_state, :json).for_collection.new(represented).to_json [represented, new_cache] end rescue JustimmoClient::RetrievalFailed [] end |
.ids(options = {}) ⇒ Array<Integer>
Returns An array of realty ids, empty array if no results.
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/justimmo_client/api/v1/interfaces/realty_interface.rb', line 105 def ids( = {}) with_cache cache_key("realty/ids", ), on_hit: ->(cached) { ::JSON.parse(cached) }, on_miss: -> do json_response = request(:realty).ids() json_parsed = ::JSON.parse(json_response).map(&:to_i) [json_parsed, ::JSON.generate(json_parsed)] end rescue JustimmoClient::RetrievalFailed [] end |
.list(options = {}) ⇒ Array<Realty>
Returns An array of basic realty objects, or an empty array on error.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/justimmo_client/api/v1/interfaces/realty_interface.rb', line 62 def list( = {}) with_cache cache_key("realty/list", ), on_hit: ->(cached) do representer(:realty, :json).for_collection.new([]).from_json(cached) end, on_miss: -> do doc = Nokogiri::XML(request(:realty).list()) doc.at_css("query-result").remove xml_response = doc.to_xml represented = representer(:realty).for_collection.new([]).from_xml(xml_response) new_cache = representer(:realty, :json).for_collection.new(represented).to_json [represented, new_cache] end rescue JustimmoClient::RetrievalFailed [] end |
.regions(options = {}) ⇒ Array<Region>
190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/justimmo_client/api/v1/interfaces/realty_interface.rb', line 190 def regions( = {}) with_cache cache_key("realty/regions", ), on_hit: ->(cached) do representer(:region, :json).for_collection.new([]).from_json(cached) end, on_miss: -> do xml_response = request(:realty).regions() represented = representer(:region).for_collection.new([]).from_xml(xml_response) new_cache = representer(:region, :json).for_collection.new(represented).to_json [represented, new_cache] end rescue JustimmoClient::RetrievalFailed [] end |
.types(options = {}) ⇒ Array<RealtyType>
136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/justimmo_client/api/v1/interfaces/realty_interface.rb', line 136 def types( = {}) with_cache cache_key("realty/types", ), on_hit: ->(cached) do representer(:realty_type, :json).for_collection.new([]).from_json(cached) end, on_miss: -> do xml_response = request(:realty).types() represented = representer(:realty_type).for_collection.new([]).from_xml(xml_response) new_cache = representer(:realty_type, :json).for_collection.new(represented).to_json [represented, new_cache] end rescue JustimmoClient::RetrievalFailed [] end |
.zip_codes_and_cities(options = {}) ⇒ Array<City>
209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/justimmo_client/api/v1/interfaces/realty_interface.rb', line 209 def zip_codes_and_cities( = {}) with_cache cache_key("realty/cities", ), on_hit: ->(cached) do representer(:city, :json).for_collection.new([]).from_json(cached) end, on_miss: -> do xml_response = request(:realty).zip_codes_and_cities() represented = representer(:city).for_collection.new([]).from_xml(xml_response) new_cache = representer(:city, :json).for_collection.new(represented).to_json [represented, new_cache] end rescue JustimmoClient::RetrievalFailed [] end |