lib/mls/models/listing.rb in mls-0.2.10 vs lib/mls/models/listing.rb in mls-0.2.11
- old
+ new
@@ -1,11 +1,11 @@
class MLS::Listing < MLS::Resource
STATES = %w(processing listed leased expired)
KINDS = %w(lease sublease coworking)
SPACE_TYPES = %w(unit floor building)
- LEASE_TYPES = ['Full Service', 'NNN', 'Gross', 'Industrial Gross', 'Modified Gross', 'Triple Net', 'Modified Net']
+ LEASE_TERMS = ['Full Service', 'NNN', 'Modified Gross']
RATE_UNITS = ['ft^2/year', 'ft^2/month', 'month', 'year', 'desk/month']
USES = ["Office", "Creative", "Loft", "Medical Office", "Flex Space", "R&D", "Office Showroom", "Industrial", "Retail"]
SOURCE_TYPES = %w(website flyer)
CHANNELS = %w(excavator mls staircase broker_dashboard)
@@ -30,11 +30,11 @@
property :total_size, Fixnum
property :maximum_contiguous_size, Fixnum
property :minimum_divisable_size, Fixnum
- property :lease_type, String
+ property :lease_terms, String
property :rate, Decimal
property :rate_units, String, :default => 'ft^2/month'
property :rate_per_month, Decimal, :serialize => :false # need to make write methods for these that set rate to the according rate units. not accepted on api
property :rate_per_year, Decimal, :serialize => :false
property :total_rate_per_month, Decimal, :serialize => :false
@@ -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)
@@ -232,9 +239,15 @@
class MLS::Listing::Parser < MLS::Parser
def photos=(photos)
@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,