vidpush/app/models/videolisting.rb
2014-04-30 15:53:58 -04:00

48 lines
1.1 KiB
Ruby

require 'securerandom'
class Videolisting < ActiveRecord::Base
belongs_to :campaign
validates :videocode, presence: true, uniqueness: true
validates :voiceoverselection, presence: true
validates :musicselection, presence: true
after_create :fix_videocode
after_save :send_notification_after_change
after_initialize :set_defaults
before_validation :set_videocode
def get_video_url
"http://video2.bettervideo.com/video/pro/MP4640x360/720.#{videocode}.mp4"
end
def get_preview_url
"http://video2.bettervideo.com/video/pro/jpg640x360/720.#{videocode}.jpg"
end
def asseturls_array
self.asseturls.split(',').collect { |url| { asseturl: url.strip } }
end
private
def set_videocode
self.videocode ||= SecureRandom.hex
end
def fix_videocode
if self.campaign
self.videocode = "#{self.campaign.listingcode}-#{self.id}"
self.save
end
end
def set_defaults
self.producttypeid = 721
end
def send_notification_after_change
if self.published_changed? && self.published?
#TODO: SEND OUT EMAIL HERE TO CLIENT SERVICES REP
end
true
end
end