Module: Justimmo::API::RealtyQuery

Extended by:
Query
Defined in:
lib/justimmo/api/v1/realty_query.rb

Overview

Get realty information from the API.

Class Method Summary collapse

Methods included from Query

log, mapper, module_name, parse_value, raw_request, url, with_error_handler

Class Method Details

.build_filter(filter = {}) ⇒ Hash

Translate a filter from internal to API format.

Options Hash (filter):

  • :price_min (Integer)
  • :price_max (Integer)
  • :price_per_sqm_min (Integer)
  • :price_per_sqm_max (Integer)
  • :realty_type_id (Integer, Array<Integer>)
  • :sub_realty_type_id (Integer, Array<Integer>)
  • :tag (String)
  • :zip_code (Integer)
  • :zip_code_min (Integer)
  • :zip_code_max (Integer)
  • :room_count_min (Integer)
  • :room_count_max (Integer)
  • :realty_number (Integer)
  • :realty_number_min (Integer)
  • :realty_number_max (Integer)
  • :area_min (Integer)
  • :area_max (Integer)
  • :living_area_min (Integer)
  • :living_area_max (Integer)
  • :floor_area_min (Integer)
  • :floor_area_max (Integer)
  • :surface_area_min (Integer)
  • :surface_area_max (Integer)
  • :keyword (String)
  • :country_id (Integer)
  • :federal_state_id (Integer)
  • :realty_status_id (Integer)
  • :rent (Boolean)
  • :purcase (Boolean)
  • :owner_id (Integer)
  • :project_id (Integer)
  • :realty_type (String)
  • :parent_id (Integer)
  • :updated_at_min (DateTime)
  • :updated_at_max (DateTime)

159
160
161
162
163
# File 'lib/justimmo/api/v1/realty_query.rb', line 159

def build_filter(filter = {})
  filter.reduce({}) do |acc, (key, value)|
    acc.update(mapper[key, map: :filter] => value)
  end
end

.build_params(params = {}) ⇒ Hash

Translate internal search parameters to API ones.


110
111
112
113
114
115
116
117
118
119
# File 'lib/justimmo/api/v1/realty_query.rb', line 110

def build_params(params = {})
  params.reduce({}) do |acc, (key, value)|
    map = { map: :params }
    case key
    when :orderby then acc.update(key => mapper[value, reverse: true])
    when :filter  then acc.update(key => build_filter(value))
    else          acc.update(mapper[key, map] => parse_value(value))
    end
  end
end

.detail(params = {}) ⇒ Hash

Get detailed information about a single realty.

Options Hash (params):

  • :realty_id (Integer)
  • :language (String)

44
45
46
# File 'lib/justimmo/api/v1/realty_query.rb', line 44

def detail(params = {})
  request('objekt/detail', params)
end

.expose(params = {}) {|tmpfile| ... } ⇒ Tempfile

Return the content of the expose PDF file as stream.

Options Hash (params):

  • :realty_id (Integer)
  • :expose (String)
  • :language (String)

Yields:

  • (tmpfile)

54
55
56
57
58
59
60
# File 'lib/justimmo/api/v1/realty_query.rb', line 54

def expose(params = {})
  tmpfile = Tempfile.open(['justimmo-expose', '.pdf'])
  response = request('objekt/expose', params)
  tmpfile.write(response)
  yield(tmpfile) if block_given?
  tmpfile
end

.ids(params = {}) ⇒ Array<Integer>

List of ids for realties matching the filters.

See Also:


86
87
88
89
90
91
92
# File 'lib/justimmo/api/v1/realty_query.rb', line 86

def ids(params = {})
  response = request('objekt/ids', params)
  JSON.parse(response).map(&:to_i)
rescue JSON::ParserError => e
  log.error(e)
  []
end

.inquiry(params = {}) ⇒ nil

TODO:

Implement this!

Create an inquiry.

Options Hash (params):

  • :realty_id (Integer)
  • :salutation_id (Integer)
  • :title (String)
  • :first_name (String)
  • :last_name (String)
  • :email (String)
  • :phone (String)
  • :message (String)
  • :street (String)
  • :zip_code (Integer)
  • :location (String)
  • :country (String)

78
79
80
# File 'lib/justimmo/api/v1/realty_query.rb', line 78

def inquiry(params = {})
  request('objekt/anfrage', params)
end

.list(params = {}) ⇒ Array<Hash>

Search for a list of realties.

Options Hash (params):

  • :limit (Integer) — default: 10

    Amount of retrieved list items. Max: 100.

  • :offset (Integer) — default: 0

    Offset of the first list item.

  • :language (String) — default: 'de'

    Language for i18n fields.

  • :orderby (Symbol) — default: :asc

    Order direction. Either :asc or :desc.

  • :order (Symbol)

    Order by specific field. One of :price, :zip_code, :created_at, :realty_number, :updated_at and :published_at.

  • :picturesize (Symbol) — default: :small

    The picture size for image urls. One of :small, :medium, :large.

  • :all (Boolean) — default: false

    Show all realties with projects, disregarding realty state.

  • :filter (Hash)

    See build_filter for options.


35
36
37
# File 'lib/justimmo/api/v1/realty_query.rb', line 35

def list(params = {})
  request('objekt/list', params)
end

.request(endpoint, params = {}) ⇒ String?

Parses parameters and handles requests to the API.

See Also:


97
98
99
100
101
102
103
104
105
# File 'lib/justimmo/api/v1/realty_query.rb', line 97

def request(endpoint, params = {})
  response = nil
  params   = build_params(params)
  response = super(endpoint, params)
rescue Query::AuthenticationFailed, Query::RetrievalFailed => e
  log.error(e)
ensure
  response
end