55 lines
1.4 KiB
Ruby
55 lines
1.4 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_save :send_notification_after_change
|
|
after_initialize :set_defaults
|
|
|
|
def get_video_url
|
|
if self.on_s3 == true
|
|
"http://s3.amazonaws.com/#{ENV['VIDEO_BUCKET']}/bvideos/#{videocode}.mp4"
|
|
else
|
|
"http://video2.bettervideo.com/video/pro/MP4640x360/720.#{videocode}.mp4"
|
|
end
|
|
end
|
|
|
|
def get_preview_url
|
|
if self.on_s3 == true
|
|
"http://s3.amazonaws.com/#{ENV['VIDEO_BUCKET']}/bvideos_preview/#{videocode}.jpg"
|
|
else
|
|
"http://video2.bettervideo.com/video/pro/jpg640x360/720.#{videocode}.jpg"
|
|
end
|
|
end
|
|
|
|
def asseturls_array
|
|
self.asseturls.split(',').collect { |url| { asseturl: url.strip } }
|
|
end
|
|
|
|
def as_json
|
|
{
|
|
assets: self.asseturls_array,
|
|
clientprovidedscript: self.clientprovidedscript,
|
|
musicselection: self.musicselection,
|
|
notes: self.notes,
|
|
producttypeid: 721,
|
|
toneofvideo: self.toneofvideo,
|
|
videocode: self.videocode,
|
|
voiceoverselection: self.voiceoverselection
|
|
}.as_json
|
|
end
|
|
|
|
private
|
|
def set_defaults
|
|
self.producttypeid = 721
|
|
end
|
|
|
|
def send_notification_after_change
|
|
if self.published_changed? && self.published?
|
|
end
|
|
true
|
|
end
|
|
end
|