Skip to content

Commit

Permalink
Added Floorplans
Browse files Browse the repository at this point in the history
  • Loading branch information
malomalo committed Jan 9, 2013
1 parent 7ca1f29 commit df3e933
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
45 changes: 45 additions & 0 deletions lib/mls/models/floorplan.rb
@@ -0,0 +1,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
7 changes: 3 additions & 4 deletions lib/mls/models/listing.rb
Expand Up @@ -64,7 +64,7 @@ class MLS::Listing < MLS::Resource
property :flyer_id, Fixnum, :serialize => :if_present

property :avatar_digest, String, :serialize => false
attr_accessor :address, :agents, :account, :photos, :flyer, :floor_plan, :videos
attr_accessor :address, :agents, :account, :photos, :flyer, :floorplan, :videos
attr_writer :amenities

def avatar(size='150x100', protocol='http')
Expand Down Expand Up @@ -255,9 +255,8 @@ def videos=(videos)
end
end

def floor_plan=(floor_plan)
@object.floor_plan = MLS::PDF.new(:digest => floor_plan[:digest], :id => floor_plan[:id].to_i,
:file_url => floor_plan[:file_url], :type => :floor_plan)
def floorplan=(floorplan)
@object.floorplan = MLS::Floorplan::Parser.build(floorplan)
end

def flyer=(flyer)
Expand Down
2 changes: 1 addition & 1 deletion mls.gemspec
Expand Up @@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)

Gem::Specification.new do |s|
s.name = "mls"
s.version = '0.2.15'
s.version = '0.2.16'
s.authors = ["James R. Bracy"]
s.email = ["james@42floors.com"]
s.homepage = "http://mls.42floors.com"
Expand Down

0 comments on commit df3e933

Please sign in to comment.