Module: ActsAsKaltura::Video

Extended by:
ActiveSupport::Concern
Included in:
ActiveRecord::Base
Defined in:
lib/acts_as_kaltura/video.rb

Defined Under Namespace

Modules: ClassMethods Classes: KalturaVideoAddFailure, NoUploadedFile, NoUploadedTokenFound

Instance Method Summary collapse

Instance Method Details

#create_kaltura_video_entryObject

Create kaltura video entry based on current video data if successful set kaltura id



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/acts_as_kaltura/video.rb', line 54

def create_kaltura_video_entry
  if @video_file.present?
    # There must have uploaded token otherwise this should be invoked
    raise NoUploadedTokenFound if @uploaded_video_token.nil?

    # Covert host model as kaltura entry
    entry        = as_kaltura_entry

    # Request kaltura service to store video entry for the
    # uploaded video file
    stored_entry = add_kaltuar_video_file(entry)

    # Nil return should throw exception
    raise KalturaVideoAddFailure if stored_entry.nil?

    # Set kaltura_key from stored kaltura entry
    self.kaltura_key      = stored_entry.id.to_s
    self.kaltura_syncd_at = Time.now

    self.class.run_kaltura_after_save_callbacks self
  end
end

#destroy_kaltura_video_entryObject



104
105
106
107
108
# File 'lib/acts_as_kaltura/video.rb', line 104

def destroy_kaltura_video_entry
  if kaltura_key
    destroy_kaltura_entry
  end
end

#kaltura_entryObject



95
96
97
98
# File 'lib/acts_as_kaltura/video.rb', line 95

def kaltura_entry
  find_kaltura_entry if @kaltura_entry.nil?
  @kaltura_entry
end

#kaltura_entry=(entry) ⇒ Object



100
101
102
# File 'lib/acts_as_kaltura/video.rb', line 100

def kaltura_entry=(entry)
  @kaltura_entry = entry
end

#process_uploaded_video_fileObject

Push user uploaded video file to kaltura server If successful set upload token with the object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/acts_as_kaltura/video.rb', line 37

def process_uploaded_video_file
  if @video_file.present?
    video_file_stream     = if @video_file.respond_to?(:path, true)
      File.open(@video_file.path)
    else
      @video_file
    end
    @uploaded_video_token = local_or_global_kaltura_client.
        media_service.upload(video_file_stream)
    raise ActsAsKaltura::Video::NoUploadedTokenFound if @uploaded_video_token.nil?
  end
end

#update_kaltura_video_entryObject

Update kaltura existing video entry If successful update kaltura_syncd_at



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/acts_as_kaltura/video.rb', line 81

def update_kaltura_video_entry
  if kaltura_key.present?
    entry = as_kaltura_entry
    update_kaltura_entry(entry)

    if @video_file.nil?
      entry.id = kaltura_key
      add_kaltuar_video_file(entry)
    end

    self.class.run_kaltura_after_save_callbacks self
  end
end