Module: Immoscout::Models::Actions::RealEstate
Overview
Actions to work with real estate objects.
Class Method Summary
collapse
Instance Method Summary
collapse
from_raw, handle_response, id_from_response, unpack
Class Method Details
.all ⇒ Object
95
96
97
98
99
100
101
102
|
# File 'lib/immoscout/models/actions/real_estate.rb', line 95
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
106
107
108
109
110
|
# File 'lib/immoscout/models/actions/real_estate.rb', line 106
def create(hash)
instance = new(hash)
instance.save
instance
end
|
.find(id) ⇒ Object
84
85
86
87
88
|
# File 'lib/immoscout/models/actions/real_estate.rb', line 84
def find(id)
response = api.get("user/#{api.user_name}/realestate/#{id}")
handle_response(response)
from_raw(response.body)
end
|
.find_by(hash) ⇒ Object
90
91
92
93
|
# File 'lib/immoscout/models/actions/real_estate.rb', line 90
def find_by(hash)
external_id = hash.symbolize_keys.fetch(:external_id)
find("ext-#{external_id}")
end
|
Instance Method Details
#destroy ⇒ Object
32
33
34
35
36
|
# File 'lib/immoscout/models/actions/real_estate.rb', line 32
def destroy
response = api.delete("user/#{api.user_name}/realestate/#{id}")
handle_response(response)
self
end
|
#place(type) ⇒ Object
56
57
58
59
60
61
62
63
|
# File 'lib/immoscout/models/actions/real_estate.rb', line 56
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
38
39
40
41
42
43
44
45
|
# File 'lib/immoscout/models/actions/real_estate.rb', line 38
def publish(channel = 10_000)
publisher = Immoscout::Models::Publish.new(
real_estate: { id: id },
publish_channel: { id: channel }
)
publisher.save
publisher
end
|
#save ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/immoscout/models/actions/real_estate.rb', line 19
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
65
66
67
68
69
70
71
72
|
# File 'lib/immoscout/models/actions/real_estate.rb', line 65
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
47
48
49
50
51
52
53
54
|
# File 'lib/immoscout/models/actions/real_estate.rb', line 47
def unpublish(channel = 10_000)
publisher = Immoscout::Models::Publish.new(
real_estate: { id: id },
publish_channel: { id: channel }
)
publisher.destroy
publisher
end
|