lib/mls/models/listing.rb in mls-0.2.9 vs lib/mls/models/listing.rb in mls-0.2.9.1

- old
+ new

@@ -60,12 +60,14 @@ property :created_at, DateTime, :serialize => :false property :updated_at, DateTime, :serialize => :false property :leased_on, DateTime + property :flyer_id, Fixnum, :serialize => :if_present + property :avatar_digest, String, :serialize => false - attr_accessor :address, :agents, :account, :photos, :flyer, :floor_plan + attr_accessor :address, :agents, :account, :photos, :flyer, :floor_plan, :videos attr_writer :amenities def avatar(size='150x100', protocol='http') if avatar_digest "#{protocol}://#{MLS.asset_host}/photos/#{size}/#{avatar_digest}.jpg" @@ -131,13 +133,12 @@ # listing.request_tour('name', 'email@address.com', info) # => #<MLS::TourRequest> # # listing.request_tour('', 'emai', info) # => #<MLS::TourRequest> will have errors on account def request_tour(account, tour={}) params = {:account => account, :tour => tour} - MLS.post("/listings/#{id}/tour_requests", params, 400) do |response, code| - return MLS::TourRequest::Parser.parse(response.body) - end + response = MLS.post("/listings/#{id}/tour_requests", params) + return MLS::TourRequest::Parser.parse(response.body) end def create MLS.post('/listings', {:listing => to_hash}, 201, 400) do |response, code| @@ -161,10 +162,11 @@ def to_hash hash = super hash[:address_attributes] = address.to_hash if address hash[:agents_attributes] = agents.inject({}) { |acc, x| acc[acc.length] = x.to_hash; acc } if agents hash[:photo_ids] = photos.map(&:id) if photos + hash[:videos_attributes] = videos.map(&:to_hash) if videos hash end def to_param "#{address.to_param}/#{id}" @@ -196,18 +198,23 @@ def all_photos photos + address.photos end + def all_videos + videos + address.videos + end + def amenities MLS.listing_amenities end class << self def find(id) response = MLS.get("/listings/#{id}") + puts response.body MLS::Listing::Parser.parse(response.body) end def all(filters = {}, limit = nil, order = 'listings.id') response = MLS.get('/listings', :filters => filters, :limit => limit, :order => order) @@ -235,17 +242,22 @@ @object.photos = photos.map do |p| MLS::Photo.new(:digest => p[:digest], :id => p[:id].to_i) end end + def videos=(videos) + @object.videos = videos.map do |video| + MLS::Video::Parser.build(video) + 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) end def flyer=(flyer) - @object.flyer = MLS::PDF.new(:digest => flyer[:digest], :id => flyer[:id].to_i, - :file_url => flyer[:file_url], :type => :flyer) + @object.flyer = MLS::Flyer::Parser.build(flyer) end def address=(address) @object.address = MLS::Address::Parser.build(address) end