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

Methods included from Utils

autoload_dir, translate

Methods included from JustimmoInterface

cache_key, with_cache

Methods included from API

#api, #interface, #model, #representer, #request, #versioned_api

Methods included from Logging

default_logger, #logger, rails_logger

Methods included from Caching

#cache, default_cache

Class Method Details

.categories(options = {}) ⇒ Array<RealtyCategory>

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :all (Boolean) — default: false

Returns:



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(options = {})
  with_cache cache_key("realty/categories", options),
    on_hit: ->(cached) do
      representer(:realty_category, :json).for_collection.new([]).from_json(cached)
    end,
    on_miss: -> do
      xml_response = request(:realty).categories(options)
      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>

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :all (Boolean) — default: false

Returns:



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(options = {})
  with_cache cache_key("realty/countries", options),
    on_hit: ->(cached) do
      representer(:country, :json).for_collection.new([]).from_json(cached)
    end,
    on_miss: -> do
      xml_response = request(:realty).countries(options)
      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.

Parameters:

  • id (Integer)
  • lang (Symbol, String) (defaults to: nil)

Returns:

  • (Realty, nil)

    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.

Returns:

  • (Array<Realty>)

    An array of detailed realty objects, or an empty array on error.

See Also:



99
100
101
# File 'lib/justimmo_client/api/v1/interfaces/realty_interface.rb', line 99

def details(options = {})
  ids(options).map { |id| detail(id) }
end

.federal_states(options = {}) ⇒ Array<FederalState>

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :all (Boolean) — default: false
  • :country (Integer) — default: nil

Returns:



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(options = {})
  with_cache cache_key("realty/federal_states", options),
    on_hit: ->(cached) do
      representer(:federal_states, :json).for_collection.new([]).from_json(cached)
    end,
    on_miss: -> do
      xml_response = request(:realty).federal_states(options)
      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.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :limit (Integer) — default: 10
  • :offset (Integer) — default: 0
  • :lang (Symbol, String) — default: :de
  • :orderby (Symbol, String)
  • :ordertype (Symbol, String) — default: :asc
  • :picturesize (Symbol, String) — default: :small
  • :with_projects (Boolean) — default: false
  • :price_min (Float)
  • :price_max (Float)
  • :price_per_sqm_min (Float)
  • :price_per_sqm_max (Float)
  • :type_id (Integer)
  • :type (Symbol, String, Array<Symbol, String>)
  • :sub_type_id (Integer)
  • :tag (Symbol, String)
  • :zip_code (String, Integer)
  • :zip_code_min (String, Integer)
  • :zip_code_max (String, Integer)
  • :rooms_min (Integer)
  • :rooms_max (Integer)
  • :number (Integer)
  • :number_min (Integer)
  • :number_max (Integer)
  • :area_min (Float)
  • :area_max (Float)
  • :living_area_min (Float)
  • :living_area_max (Float)
  • :floor_area_min (Float)
  • :floor_area_max (Float)
  • :surface_area_min (Float)
  • :surface_area_max (Float)
  • :keyword (Symbol, String)
  • :country_id (Integer)
  • :federal_state_id (Integer)
  • :status_id (Integer)
  • :rent (Boolean)
  • :purcase (Boolean)
  • :owner_id (Integer)
  • :project_id (Integer)
  • :system_type (String)
  • :parent_id (Integer)
  • :updated_at_min (DateTime)
  • :updated_at_max (DateTime)
  • :location (String)

Returns:

  • (Array<Integer>)

    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(options = {})
  with_cache cache_key("realty/ids", options),
    on_hit: ->(cached) { ::JSON.parse(cached) },
    on_miss: -> do
      json_response = request(:realty).ids(options)
      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.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :limit (Integer) — default: 10
  • :offset (Integer) — default: 0
  • :lang (Symbol, String) — default: :de
  • :orderby (Symbol, String)
  • :ordertype (Symbol, String) — default: :asc
  • :picturesize (Symbol, String) — default: :small
  • :with_projects (Boolean) — default: false
  • :price_min (Float)
  • :price_max (Float)
  • :price_per_sqm_min (Float)
  • :price_per_sqm_max (Float)
  • :type_id (Integer)
  • :type (Symbol, String, Array<Symbol, String>)
  • :sub_type_id (Integer)
  • :tag (Symbol, String)
  • :zip_code (String, Integer)
  • :zip_code_min (String, Integer)
  • :zip_code_max (String, Integer)
  • :rooms_min (Integer)
  • :rooms_max (Integer)
  • :number (Integer)
  • :number_min (Integer)
  • :number_max (Integer)
  • :area_min (Float)
  • :area_max (Float)
  • :living_area_min (Float)
  • :living_area_max (Float)
  • :floor_area_min (Float)
  • :floor_area_max (Float)
  • :surface_area_min (Float)
  • :surface_area_max (Float)
  • :keyword (Symbol, String)
  • :country_id (Integer)
  • :federal_state_id (Integer)
  • :status_id (Integer)
  • :rent (Boolean)
  • :purcase (Boolean)
  • :owner_id (Integer)
  • :project_id (Integer)
  • :system_type (String)
  • :parent_id (Integer)
  • :updated_at_min (DateTime)
  • :updated_at_max (DateTime)
  • :location (String)

Returns:

  • (Array<Realty>)

    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(options = {})
  with_cache cache_key("realty/list", options),
    on_hit: ->(cached) do
      representer(:realty, :json).for_collection.new([]).from_json(cached)
    end,
    on_miss: -> do
      doc = Nokogiri::XML(request(:realty).list(options))
      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>

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :all (Boolean) — default: false
  • :country (Integer) — default: nil
  • :federal_state (Integer) — default: nil

Returns:



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(options = {})
  with_cache cache_key("realty/regions", options),
    on_hit: ->(cached) do
      representer(:region, :json).for_collection.new([]).from_json(cached)
    end,
    on_miss: -> do
      xml_response = request(:realty).regions(options)
      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>

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :all (Boolean) — default: false

Returns:



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(options = {})
  with_cache cache_key("realty/types", options),
    on_hit: ->(cached) do
      representer(:realty_type, :json).for_collection.new([]).from_json(cached)
    end,
    on_miss: -> do
      xml_response = request(:realty).types(options)
      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>

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :all (Boolean) — default: false
  • :country (Integer) — default: nil
  • :federal_state (Integer) — default: nil

Returns:



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(options = {})
  with_cache cache_key("realty/cities", options),
    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(options)
      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