module JustimmoClient::V1::RealtyInterface

Public realty query interface

Glues all components together. Handles caching, parsing and converting XML and JSON into data models.

Public Instance Methods

categories(options = {}) click to toggle source

@option options [Boolean] :all (false) @return [Array<RealtyCategory>]

# 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 = {}) click to toggle source

@option options [Boolean] :all (false) @return [Array<Country>]

# 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) click to toggle source

@param [Integer] id @param [Symbol, String] lang @return [Realty, nil] A detailed realty object, or nil if it could not be found.

# 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 = {}) click to toggle source

@see list @return [Array<Realty>] An array of detailed realty objects, or an empty array on error.

# 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 = {}) click to toggle source

@option options [Boolean] :all (false) @option options [Integer] :country (nil) @return [Array<FederalState>]

# 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 = {}) click to toggle source

@option (see list) @return [Array<Integer>] An array of realty ids, empty array if no results.

# 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 = {}) click to toggle source

@option options [Integer] :limit (10) @option options [Integer] :offset (0) @option options [Symbol, String] :lang (:de) @option options [Symbol, String] :orderby @option options [Symbol, String] :ordertype (:asc) @option options [Symbol, String] :picturesize (:small) @option options [Boolean] :with_projects (false) @option options [Float] :price_min @option options [Float] :price_max @option options [Float] :price_per_sqm_min @option options [Float] :price_per_sqm_max @option options [Integer] :type_id @option options [Symbol, String, Array<Symbol, String>] :type @option options [Integer] :sub_type_id @option options [Symbol, String] :tag @option options [String, Integer] :zip_code @option options [String, Integer] :zip_code_min @option options [String, Integer] :zip_code_max @option options [Integer] :rooms_min @option options [Integer] :rooms_max @option options [Integer] :number @option options [Integer] :number_min @option options [Integer] :number_max @option options [Float] :area_min @option options [Float] :area_max @option options [Float] :living_area_min @option options [Float] :living_area_max @option options [Float] :floor_area_min @option options [Float] :floor_area_max @option options [Float] :surface_area_min @option options [Float] :surface_area_max @option options [Symbol, String] :keyword @option options [Integer] :country_id @option options [Integer] :federal_state_id @option options [Integer] :status_id @option options [Boolean] :rent @option options [Boolean] :purcase @option options [Integer] :owner_id @option options [Integer] :project_id @option options [String] :system_type @option options [Integer] :parent_id @option options [DateTime] :updated_at_min @option options [DateTime] :updated_at_max @option options [String] :location @return [Array<Realty>] An array of basic realty objects, or an empty array on error.

# 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 = {}) click to toggle source

@option options [Boolean] :all (false) @option options [Integer] :country (nil) @option options [Integer] :federal_state (nil) @return [Array<Region>]

# 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 = {}) click to toggle source

@option options [Boolean] :all (false) @return [Array<RealtyType>]

# 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 = {}) click to toggle source

@option options [Boolean] :all (false) @option options [Integer] :country (nil) @option options [Integer] :federal_state (nil) @return [Array<City>]

# 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