/
floorplan.rb
45 lines (34 loc) · 1.08 KB
/
floorplan.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'restclient'
class MLS::Floorplan < MLS::Resource
property :id, Fixnum
property :digest, String
property :avatar_digest, String
property :file_name, String
property :file_size, Fixnum
def url(protocol='http')
"#{protocol}://#{MLS.asset_host}/floorplans/#{digest}/#{file_name}"
end
def avatar(size='150x100', protocol='http')
"#{protocol}://#{MLS.asset_host}/photos/#{size}/#{avatar_digest}.jpg"
end
def self.create(attrs)
attrs[:file].rewind
url = MLS.url.dup
url.user = nil
url.path = "/api/floorplans"
if attrs[:subject]
attrs[:subject_id] = attrs[:subject].id
attrs[:subject_type] = attrs[:subject].class.name.split("::").last
attrs.delete(:subject)
end
response = RestClient.post(url.to_s, {:floorplan => attrs}, MLS.headers)
attrs[:file].close unless attrs[:file].closed?
MLS::Floorplan::Parser.parse(response.body)
end
def self.find(id)
response = MLS.get("/floorplans/#{id}")
MLS::Floorplan::Parser.parse(response.body)
end
end
class MLS::Floorplan::Parser < MLS::Parser
end