Permalink
Browse files

Added Floorplans

  • Loading branch information...
malomalo committed Jan 9, 2013
1 parent 7ca1f29 commit df3e9338f3b35aa143aa8548715574afd433bf04
Showing with 49 additions and 5 deletions.
  1. +45 −0 lib/mls/models/floorplan.rb
  2. +3 −4 lib/mls/models/listing.rb
  3. +1 −1 mls.gemspec
@@ -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
@@ -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')
@@ -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)
View
@@ -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"

0 comments on commit df3e933

Please sign in to comment.