Skip to content

Commit

Permalink
Support for videos
Browse files Browse the repository at this point in the history
Updated Gemspec.
  • Loading branch information
dana11235 committed Jan 3, 2013
1 parent db50de5 commit cf87d07
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/mls.rb
Expand Up @@ -419,6 +419,7 @@ def self.parse(json) # TODO: testme
require 'mls/models/listing' require 'mls/models/listing'
require 'mls/models/address' require 'mls/models/address'
require 'mls/models/photo' require 'mls/models/photo'
require 'mls/models/video'
require 'mls/models/pdf' require 'mls/models/pdf'
require 'mls/models/tour_request' require 'mls/models/tour_request'
require 'mls/models/flyer' require 'mls/models/flyer'
Expand Down
15 changes: 14 additions & 1 deletion lib/mls/models/address.rb
Expand Up @@ -48,7 +48,7 @@ class MLS::Address < MLS::Resource


property :avatar_digest, String, :serialize => false property :avatar_digest, String, :serialize => false


attr_accessor :listings, :listing_kinds, :photos attr_accessor :listings, :listing_kinds, :photos, :videos


# should include an optional use address or no_image image # should include an optional use address or no_image image
def avatar(size='100x200', protocol='http') def avatar(size='100x200', protocol='http')
Expand Down Expand Up @@ -81,6 +81,7 @@ def save
def to_hash def to_hash
hash = super hash = super
hash[:photo_ids] = photos.map(&:id) if photos hash[:photo_ids] = photos.map(&:id) if photos
hash[:videos_attributes] = videos.map(&:to_hash) if videos
hash hash
end end


Expand Down Expand Up @@ -114,6 +115,12 @@ def amenities
MLS.address_amenities MLS.address_amenities
end end


def find_listings(space_available, floor, unit)
response = MLS.get("/addresses/#{id}/find_listings",
:floor => floor, :unit => unit, :space_available => space_available)
MLS::Listing::Parser.parse_collection(response.body)
end

class << self class << self


def query(q) def query(q)
Expand Down Expand Up @@ -161,4 +168,10 @@ def photos=(photos)
MLS::Photo.new(:digest => p[:digest], :id => p[:id].to_i) MLS::Photo.new(:digest => p[:digest], :id => p[:id].to_i)
end end
end end

def videos=(videos)
@object.videos = videos.map do |video|
MLS::Video::Parser.build(video)
end
end
end end
14 changes: 13 additions & 1 deletion lib/mls/models/listing.rb
Expand Up @@ -65,7 +65,7 @@ class MLS::Listing < MLS::Resource
property :flyer_id, Fixnum, :serialize => :if_present property :flyer_id, Fixnum, :serialize => :if_present


property :avatar_digest, String, :serialize => false 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 attr_writer :amenities


def avatar(size='150x100', protocol='http') def avatar(size='150x100', protocol='http')
Expand Down Expand Up @@ -164,6 +164,7 @@ def to_hash
hash[:address_attributes] = address.to_hash if address 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[:agents_attributes] = agents.inject({}) { |acc, x| acc[acc.length] = x.to_hash; acc } if agents
hash[:photo_ids] = photos.map(&:id) if photos hash[:photo_ids] = photos.map(&:id) if photos
hash[:videos_attributes] = videos.map(&:to_hash) if videos
hash hash
end end


Expand Down Expand Up @@ -199,6 +200,10 @@ def all_photos
photos + address.photos photos + address.photos
end end


def all_videos
videos + address.videos
end

def amenities def amenities
MLS.listing_amenities MLS.listing_amenities
end end
Expand All @@ -207,6 +212,7 @@ class << self


def find(id) def find(id)
response = MLS.get("/listings/#{id}") response = MLS.get("/listings/#{id}")
puts response.body
MLS::Listing::Parser.parse(response.body) MLS::Listing::Parser.parse(response.body)
end end


Expand Down Expand Up @@ -238,6 +244,12 @@ def photos=(photos)
end end
end end


def videos=(videos)
@object.videos = videos.map do |video|
MLS::Video::Parser.build(video)
end
end

def floor_plan=(floor_plan) def floor_plan=(floor_plan)
@object.floor_plan = MLS::PDF.new(:digest => floor_plan[:digest], :id => floor_plan[:id].to_i, @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) :file_url => floor_plan[:file_url], :type => :floor_plan)
Expand Down
12 changes: 12 additions & 0 deletions lib/mls/models/video.rb
@@ -0,0 +1,12 @@
class MLS::Video < MLS::Resource
property :id, Fixnum
property :vts_key, String
property :video_type, String
property :subject_type, String
property :created_at, DateTime, :serialize => :if_present
property :updated_at, DateTime, :serialize => :if_present
end

class MLS::Video::Parser < MLS::Parser

end
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| Gem::Specification.new do |s|
s.name = "mls" s.name = "mls"
s.version = '0.2.9' s.version = '0.2.9.1'
s.authors = ["James R. Bracy"] s.authors = ["James R. Bracy"]
s.email = ["james@42floors.com"] s.email = ["james@42floors.com"]
s.homepage = "http://mls.42floors.com" s.homepage = "http://mls.42floors.com"
Expand Down

0 comments on commit cf87d07

Please sign in to comment.