2014-04-25 20:02:47 +00:00
|
|
|
require 'securerandom'
|
|
|
|
|
2014-04-07 18:41:34 +00:00
|
|
|
class Videolisting < ActiveRecord::Base
|
|
|
|
belongs_to :campaign
|
2014-04-08 21:01:22 +00:00
|
|
|
validates :videocode, presence: true, uniqueness: true
|
2014-04-21 18:26:46 +00:00
|
|
|
validates :voiceoverselection, presence: true
|
|
|
|
validates :musicselection, presence: true
|
2014-04-24 19:47:47 +00:00
|
|
|
after_save :send_notification_after_change
|
2014-04-24 21:13:39 +00:00
|
|
|
after_initialize :set_defaults
|
2014-04-21 18:26:46 +00:00
|
|
|
|
2014-04-25 20:02:47 +00:00
|
|
|
def get_video_url
|
2014-05-29 20:57:34 +00:00
|
|
|
if self.on_s3 == true
|
2014-05-29 18:34:52 +00:00
|
|
|
"http://s3.amazonaws.com/#{ENV['VIDEO_BUCKET']}/bvideos/#{videocode}.mp4"
|
|
|
|
else
|
|
|
|
"http://video2.bettervideo.com/video/pro/MP4640x360/720.#{videocode}.mp4"
|
|
|
|
end
|
2014-04-25 20:02:47 +00:00
|
|
|
end
|
2014-04-24 21:13:39 +00:00
|
|
|
|
2014-04-25 20:02:47 +00:00
|
|
|
def get_preview_url
|
2014-05-29 20:57:34 +00:00
|
|
|
if self.on_s3 == true
|
2014-05-29 18:34:52 +00:00
|
|
|
"http://s3.amazonaws.com/#{ENV['VIDEO_BUCKET']}/bvideos_preview/#{videocode}.jpg"
|
|
|
|
else
|
|
|
|
"http://video2.bettervideo.com/video/pro/jpg640x360/720.#{videocode}.jpg"
|
|
|
|
end
|
2014-04-24 16:51:50 +00:00
|
|
|
end
|
|
|
|
|
2014-04-15 17:04:58 +00:00
|
|
|
def asseturls_array
|
2014-04-18 19:34:44 +00:00
|
|
|
self.asseturls.split(',').collect { |url| { asseturl: url.strip } }
|
2014-04-15 17:04:58 +00:00
|
|
|
end
|
2014-04-24 19:47:47 +00:00
|
|
|
|
2014-05-02 20:55:27 +00:00
|
|
|
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
|
|
|
|
|
2014-04-25 20:02:47 +00:00
|
|
|
private
|
|
|
|
def set_defaults
|
|
|
|
self.producttypeid = 721
|
|
|
|
end
|
|
|
|
|
|
|
|
def send_notification_after_change
|
|
|
|
if self.published_changed? && self.published?
|
|
|
|
end
|
|
|
|
true
|
2014-04-24 19:47:47 +00:00
|
|
|
end
|
2014-04-07 18:41:34 +00:00
|
|
|
end
|