Start of Main Content

In the first installment of my "Riding on Rails with Kaltura" series, I talked about the kaltura-ruby API library. While we've been able to accomplish some good things with the library, it tends to be a bit too low of a level for day-to-day Rails application development.

Ready to kick off your next digital marketing project? Start the conversation.

We can’t wait to hear all about your organization’s unique needs and develop innovative ways you can foster lasting connections with your audiences.

Enter Kaltura_Fu

There are a number of things that I just don't want to handle when I'm integrating Kaltura in a web application. The first of which is managing the session needed to perform API actions. Without Kaltura_Fu, this is how you would start a client session:

  #initializing a new Kaltura client session
  admin_secret = '35AFadgasdas5235acaa'
  partner_id = '101'
  config = Kaltura::Configuration.new( partner_id )
  client = Kaltura::Client.new( config )
  session = client.session_service.start( admin_secret, '',
    Kaltura::Constants::SessionType::ADMIN
  )
  client.ks = session

That would get tedious very quickly to ensure there is a valid Kaltura::Client object and session on each rails action that uses Kaltura in any shape or form! Another example of tedium that I just couldn't stand is adding metadata to a Kaltura entry. I've opted to provide a simple interface for managing metatada:

  #adding "This is a fun video's" database category to the Kaltura entry.
  include KalturaFu::Entry

  video = Video.find_by_name('This is a fun video')
  add_categories(video.entry_id,video.category)

That method in itself performing a number of actions. First, it is ensuring a valid session. Secondly, it checks if the category you wish to add already exists as a Kaltura Media Console category filter, and adds it if it doesn't. This allows you to search the KMC for the category you added onto the video. Finally, it appends the category onto the end of the current category list for that specific video. If you want to override existing categories, you can choose to call this instead:

  set_categories(video.entry_id, video.category)

The Entry module works by dynamically adding getters, setters, and adders based upon the version of the Kaltura API you are working on. If Kaltura decides to add a bunch of fields onto the Media Entry object in the future, this library won't need to be updated. One other crucial component to the Kaltura_Fu gem is the ViewHelpers module. Embedding a flash player has become very easy:

    #in a view.html.erb
    <%= kaltura_player_embed @video.entry_id, :size=>[544,360] %>
    #in a view.html.haml
    = kaltura_player_embed @video.entry_id, :size => [336,240]

It's a robust enough method that allows you to configure the player as you desire. Check it out here. As with our kaltura-ruby library, our code is available on github and the documentation is online as well.

Published:

Latest Ideas

Take advantage of our expertise with your next project.