Class: Justimmo::API::Realty

Inherits:
Resource show all
Defined in:
lib/justimmo/api/v1/realty.rb

Overview

Represents a complete realty resource.

Direct Known Subclasses

Realty

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

class_name, from_json, mapper, query, #to_h, #to_json

Constructor Details

#initialize(options = {}) ⇒ Realty


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/justimmo/api/v1/realty.rb', line 16

def initialize(options = {})
  @attributes = i[
    id external_id
    title description
    openimmo_obid language
    teaser proximity
    first_image second_image
    created_at updated_at
  ] + SECTIONS

  SECTIONS.each { |x| options[x] = build_section(x, options) }
  MERGE.each { |x| merge_section(x, options) }

  super(options)
end

Class Method Details

.detail(params = {}) ⇒ Realty


100
101
102
# File 'lib/justimmo/api/v1/realty.rb', line 100

def detail(params = {})
  from_xml(query.detail(params))
end

.expose(params = {}) ⇒ Object


104
105
106
# File 'lib/justimmo/api/v1/realty.rb', line 104

def expose(params = {})
  query.expose(params)
end

.from_xml(xml) ⇒ Object


83
84
85
86
87
88
89
90
# File 'lib/justimmo/api/v1/realty.rb', line 83

def from_xml(xml)
  parsed = Justimmo::Parser.parse(xml, mapper)
  parsed = parsed.dig(:justimmo, :realty) || {}
  case parsed
  when Array then parsed.map { |x| new(x) }
  when Hash  then new(parsed)
  end
end

.ids(params = {}) ⇒ Object


112
113
114
# File 'lib/justimmo/api/v1/realty.rb', line 112

def ids(params = {})
  query.ids(params)
end

.inquiry(params = {}) ⇒ Object


108
109
110
# File 'lib/justimmo/api/v1/realty.rb', line 108

def inquiry(params = {})
  query.inquiry(params)
end

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


94
95
96
# File 'lib/justimmo/api/v1/realty.rb', line 94

def list(params = {})
  from_xml(query.list(params))
end

Instance Method Details

#descriptionObject


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

def description
  @attributes[:free_text].description
end

#inspectObject


36
37
38
# File 'lib/justimmo/api/v1/realty.rb', line 36

def inspect
  "<Realty: #{self}>"
end

#property_numberObject


40
41
42
# File 'lib/justimmo/api/v1/realty.rb', line 40

def property_number
  external_id
end

#titleObject


48
49
50
# File 'lib/justimmo/api/v1/realty.rb', line 48

def title
  @attributes[:free_text].title
end

#to_sObject


32
33
34
# File 'lib/justimmo/api/v1/realty.rb', line 32

def to_s
  @attributes[:id].to_s
end