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
api, autoload_dir, interface, model, representer, request, translate, versioned_api
Methods included from JustimmoInterface
Methods included from Logging
default_logger, #logger, rails_logger
Methods included from Caching
Class Method Details
.categories(options = {}) ⇒ Array<RealtyCategory>
118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/justimmo_client/api/v1/interfaces/realty_interface.rb', line 118 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>
152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/justimmo_client/api/v1/interfaces/realty_interface.rb', line 152 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.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/justimmo_client/api/v1/interfaces/realty_interface.rb', line 80 def detail(id, lang: nil) with_cache cache_key("realty/detail", 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) model = Struct.new(:realty).new represented = representer(:realty_detail).new(model).from_xml(xml_response).realty 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.
98 99 100 |
# File 'lib/justimmo_client/api/v1/interfaces/realty_interface.rb', line 98 def details( = {}) ids().map { |id| detail(id) } end |
.federal_states(options = {}) ⇒ Array<FederalState>
170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/justimmo_client/api/v1/interfaces/realty_interface.rb', line 170 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.
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/justimmo_client/api/v1/interfaces/realty_interface.rb', line 104 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.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/justimmo_client/api/v1/interfaces/realty_interface.rb', line 61 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 model = Struct.new(:realties).new xml_response = request(:realty).list() represented = representer(:realty_list).new(model).from_xml(xml_response).realties new_cache = representer(:realty, :json).for_collection.new(represented).to_json [represented, new_cache] end rescue JustimmoClient::RetrievalFailed [] end |
.regions(options = {}) ⇒ Array<Region>
189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/justimmo_client/api/v1/interfaces/realty_interface.rb', line 189 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>
135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/justimmo_client/api/v1/interfaces/realty_interface.rb', line 135 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>
208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/justimmo_client/api/v1/interfaces/realty_interface.rb', line 208 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 |