Module: Immoscout::Models::Actions::RealEstate
Overview
Actions to work with real estate objects.
Class Method Summary
collapse
Instance Method Summary
collapse
#api, from_raw, #handle_response, handle_response, #id_from_response, id_from_response, unpack
Class Method Details
.all ⇒ Object
101
102
103
104
105
106
107
108
|
# File 'lib/immoscout/models/actions/real_estate.rb', line 101
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
112
113
114
115
116
|
# File 'lib/immoscout/models/actions/real_estate.rb', line 112
def create(hash)
instance = new(hash)
instance.save
instance
end
|
.find(id) ⇒ Object
90
91
92
93
94
|
# File 'lib/immoscout/models/actions/real_estate.rb', line 90
def find(id)
response = api.get("user/#{api.user_name}/realestate/#{id}")
handle_response(response)
from_raw(response.body)
end
|
.find_by(hash) ⇒ Object
96
97
98
99
|
# File 'lib/immoscout/models/actions/real_estate.rb', line 96
def find_by(hash)
external_id = hash.symbolize_keys.fetch(:external_id)
find("ext-#{external_id}")
end
|
Instance Method Details
#destroy ⇒ Object
38
39
40
41
42
|
# File 'lib/immoscout/models/actions/real_estate.rb', line 38
def destroy
response = api.delete("user/#{api.user_name}/realestate/#{id}")
handle_response(response)
self
end
|
#place(type) ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'lib/immoscout/models/actions/real_estate.rb', line 62
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
44
45
46
47
48
49
50
51
|
# File 'lib/immoscout/models/actions/real_estate.rb', line 44
def publish(channel = 10_000)
publisher = Immoscout::Models::Publish.new(
real_estate: { id: id },
publish_channel: { id: channel }
)
publisher.save
publisher
end
|
#save ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/immoscout/models/actions/real_estate.rb', line 25
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
71
72
73
74
75
76
77
78
|
# File 'lib/immoscout/models/actions/real_estate.rb', line 71
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
53
54
55
56
57
58
59
60
|
# File 'lib/immoscout/models/actions/real_estate.rb', line 53
def unpublish(channel = 10_000)
publisher = Immoscout::Models::Publish.new(
real_estate: { id: id },
publish_channel: { id: channel }
)
publisher.destroy
publisher
end
|