# Video SEO Developer Kit Version 1.4 # Feb 10, 2010, Ooyala # # The Video SEO Develop Kit is a set of methods which enable publishers to increase the visibility of their content # to search engines. The Develop Kit contains a primary class Ooyala::SEOFriendlyVideo, and two primary methods: # header() and body(). # # See example.rb for an example of how to call these methods require "rubygems" require "base64" require "cgi" require "digest/sha2" require "net/http" require "rexml/document" module Ooyala class BacklotAPIClient def initialize(partner_code, secret_code, cache_for_num_seconds=900) @partner_code = partner_code @secret_code = secret_code @cache_for_num_seconds = cache_for_num_seconds end def query(params) return send_request("query", params) end private def send_request(request_type, params) # Round expires to nearest @cache_for_num_seconds interval params['expires'] = ((Time.now.to_i + 15).to_f / @cache_for_num_seconds).ceil * @cache_for_num_seconds string_to_sign = @secret_code url = "http://cdn.api.ooyala.com/partner/#{request_type}?pcode=#{@partner_code}" params.keys.sort.each do |key| string_to_sign += "#{key}=#{params[key]}" url += "{CGI.escape(key.to_s)}=#{CGI.escape(params[key].to_s)}" end digest = Digest::SHA256.digest(string_to_sign) signature = Base64::encode64(digest).chomp.gsub(/=+$/, '') url += "&signature=#{CGI.escape(signature)}" xml_data = Net::HTTP.get_response(URI.parse(url)).body return xml_data end end class SEOFriendlyVideo # Creates an SEOFriendlyVideo instance. Performs a calls to Ooyala's API to obtain relevant SEO data. # # partner_code: the partner code found in your Backlot > Account > Developers tab # secret_code: the secret code found in your Backlot > Account > Developers tab # embed_code: the embed code of your video or channel, found in your Manage > Embed tab def initialize(partner_code, secret_code, embed_code) @api_client = BacklotAPIClient.new(partner_code, secret_code) @embed_code = embed_code fetch_data() end # Returns a string to be inserted into the header of your page. def header() # We assume keywords are stored in the metadata entry for "keywords". return %Q(