Module: Immoscout::Models::Actions::RealEstate

Extended by:
ActiveSupport::Concern
Includes:
Concerns::Modelable
Included in:
Immoscout::Models::ApartmentBuy, HouseBuy
Defined in:
lib/immoscout/models/actions/real_estate.rb

Overview

Actions to work with real estate objects.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Modelable

from_raw, handle_response, id_from_response, unpack

Class Method Details

.allObject



97
98
99
100
101
102
103
104
# File 'lib/immoscout/models/actions/real_estate.rb', line 97

def all
  response = api.get("user/#{api.user_name}/realestate")
  handle_response(response)
  objects = unpack_collection.call(response.body)
  objects
    .map { |object| new(object) }
    .select { |object| object.type =~ /#{name.demodulize}/i }
end

.create(hash) ⇒ Object



108
109
110
111
112
# File 'lib/immoscout/models/actions/real_estate.rb', line 108

def create(hash)
  instance = new(hash)
  instance.save
  instance
end

.find(id) ⇒ Object



86
87
88
89
90
# File 'lib/immoscout/models/actions/real_estate.rb', line 86

def find(id)
  response = api.get("user/#{api.user_name}/realestate/#{id}")
  handle_response(response)
  from_raw(response.body)
end

.find_by(hash) ⇒ Object



92
93
94
95
# File 'lib/immoscout/models/actions/real_estate.rb', line 92

def find_by(hash)
  external_id = hash.symbolize_keys.fetch(:external_id)
  find("ext-#{external_id}")
end

Instance Method Details

#destroyObject



34
35
36
37
38
# File 'lib/immoscout/models/actions/real_estate.rb', line 34

def destroy
  response = api.delete("user/#{api.user_name}/realestate/#{id}")
  handle_response(response)
  self
end

#place(type) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/immoscout/models/actions/real_estate.rb', line 58

def place(type)
  check_placement_type(type)
  response = api.post(
    "user/#{api.user_name}/realestate/#{id}/#{type}"
  )
  handle_response(response)
  self
end

#publish(channel = 10_000) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/immoscout/models/actions/real_estate.rb', line 40

def publish(channel = 10_000)
  publisher = Immoscout::Models::Publish.new(
    real_estate: { id: id },
    publish_channel: { id: channel }
  )
  publisher.save
  publisher
end

#saveObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/immoscout/models/actions/real_estate.rb', line 21

def save
  response =
    if id
      api.put("user/#{api.user_name}/realestate/#{id}", as_json)
    else
      api.post("user/#{api.user_name}/realestate", as_json)
    end

  handle_response(response)
  self.id = id_from_response(response) unless id
  self
end

#unplace(type) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/immoscout/models/actions/real_estate.rb', line 67

def unplace(type)
  check_placement_type(type)
  response = api.delete(
    "user/#{api.user_name}/realestate/#{id}/#{type}"
  )
  handle_response(response)
  self
end

#unpublish(channel = 10_000) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/immoscout/models/actions/real_estate.rb', line 49

def unpublish(channel = 10_000)
  publisher = Immoscout::Models::Publish.new(
    real_estate: { id: id },
    publish_channel: { id: channel }
  )
  publisher.destroy
  publisher
end