api to generate a media comment session, closes #4068

Change-Id: Ia94541216b4203e496f75cf243ba3245635399c2
Reviewed-on: https://gerrit.instructure.com/5864
Reviewed-by: Brian Palmer <brianp@instructure.com>
Tested-by: Hudson <hudson@instructure.com>
This commit is contained in:
Brian Palmer 2011-09-27 13:14:48 -06:00
parent 87588f5307
commit 7d05603d33
6 changed files with 63 additions and 33 deletions

View File

@ -60,5 +60,36 @@ class ServicesApiController < ApplicationController
render_unauthorized_action
end
end
# @API
# Start a new Kaltura session, so that new media can be recorded and uploaded
# to this Canvas instance's Kaltura instance.
#
# @response_field ks The kaltura session id, for use in the kaltura v3 API.
# This can be used in the uploadtoken service, for instance, to upload a new
# media file into kaltura.
#
# @example_response
#
# {
# 'ks': '1e39ad505f30c4fa1af5752b51bd69fe'
# }
def start_kaltura_session
@user = @current_user
if !@current_user
render :json => {:errors => {:base => t('must_be_logged_in', "You must be logged in to use Kaltura")}, :logged_in => false}.to_json
end
client = Kaltura::ClientV3.new
uid = "#{@user.id}_#{@domain_root_account.id}"
res = client.startSession(Kaltura::SessionType::USER, uid)
raise "Kaltura session failed to generate" if res.match(/START_SESSION_ERROR/)
render :json => {
:ks => res,
:subp_id => Kaltura::ClientV3.config['subpartner_id'],
:partner_id => Kaltura::ClientV3.config['partner_id'],
:uid => uid,
:serverTime => Time.now.to_i
}.to_json
end
end
end

View File

@ -606,25 +606,7 @@ class UsersController < ApplicationController
end
end
end
def kaltura_session
@user = @current_user
if !@current_user
render :json => {:errors => {:base => t('must_be_logged_in', "You must be logged in to use Kaltura")}, :logged_in => false}.to_json
end
client = Kaltura::ClientV3.new
uid = "#{@user.id}_#{@domain_root_account.id}"
res = client.startSession(Kaltura::SessionType::USER, uid)
raise "Kaltura session failed to generate" if res.match(/START_SESSION_ERROR/)
render :json => {
:ks => res,
:subp_id => Kaltura::ClientV3.config['subpartner_id'],
:partner_id => Kaltura::ClientV3.config['partner_id'],
:uid => uid,
:serverTime => Time.now.to_i
}.to_json
end
def media_download
url = Rails.cache.fetch(['media_download_url', params[:entryId], params[:type]].cache_key, :expires_in => 30.minutes) do
client = Kaltura::ClientV3.new

View File

@ -549,7 +549,8 @@ ActionController::Routing::Routes.draw do |map|
dashboard.eportfolios "eportfolios", :controller => "eportfolios", :action => "user_index"
dashboard.grades "grades", :controller => "users", :action => "grades"
dashboard.resources :rubrics, :as => :assessments
dashboard.comment_session "comment_session", :controller => "users", :action => "kaltura_session"
# comment_session can be removed once the iOS apps are no longer using it
dashboard.comment_session "comment_session", :controller => "services_api", :action => "start_kaltura_session"
dashboard.ignore_stream_item 'ignore_stream_item/:id', :controller => 'users', :action => 'ignore_stream_item', :conditions => {:method => :delete}
end
map.dashboard_ignore_channel 'dashboard/ignore_path', :controller => "users", :action => "ignore_channel", :conditions => {:method => :post}
@ -712,9 +713,10 @@ ActionController::Routing::Routes.draw do |map|
conversations.post 'conversations/:id/add_recipients', :action => :add_recipients
conversations.post 'conversations/:id/remove_messages', :action => :remove_messages
end
api.with_options(:controller => :services_api) do |services|
services.get 'services/kaltura', :action => :show_kaltura_config
services.post 'services/kaltura_session', :action => :start_kaltura_session
end
end

View File

@ -618,7 +618,7 @@ I18n.scoped('media_comments', function(I18n) {
width: 470,
height: 300
}).dialog('open');
$.ajaxJSON('/dashboard/comment_session', 'GET', {}, function(data) {
$.ajaxJSON('/api/v1/services/kaltura_session', 'POST', {}, function(data) {
$div.data('ks', data.ks);
$div.data('uid', data.uid);
}, function(data) {

View File

@ -56,4 +56,19 @@ describe "Services API", :type => :integration do
'enabled' => false,
}
end
end
it "should return a new kaltura session" do
stub_kaltura
kal = mock(Kaltura::ClientV3)
kal.should_receive(:startSession).and_return "new_session_id_here"
Kaltura::ClientV3.stub!(:new).and_return(kal)
json = api_call(:post, "/api/v1/services/kaltura_session",
:controller => "services_api", :action => "start_kaltura_session", :format => "json")
json.delete_if { |k,v| %w(serverTime).include?(k) }.should == {
'ks' => "new_session_id_here",
'subp_id' => '10000',
'partner_id' => '100',
'uid' => "#{@user.id}_#{Account.default.id}",
}
end
end

View File

@ -418,15 +418,15 @@ Spec::Runner.configure do |config|
def stub_kaltura
# trick kaltura into being activated
Kaltura::ClientV3.stub!(:config).and_return({
:domain => 'kaltura.example.com',
:resource_domain => 'kaltura.example.com',
:partner_id => '100',
:subpartner_id => '10000',
:secret_key => 'fenwl1n23k4123lk4hl321jh4kl321j4kl32j14kl321',
:user_secret_key => '1234821hrj3k21hjk4j3kl21j4kl321j4kl3j21kl4j3k2l1',
:player_ui_conf => '1',
:kcw_ui_conf => '1',
:upload_ui_conf => '1'
'domain' => 'kaltura.example.com',
'resource_domain' => 'kaltura.example.com',
'partner_id' => '100',
'subpartner_id' => '10000',
'secret_key' => 'fenwl1n23k4123lk4hl321jh4kl321j4kl32j14kl321',
'user_secret_key' => '1234821hrj3k21hjk4j3kl21j4kl321j4kl3j21kl4j3k2l1',
'player_ui_conf' => '1',
'kcw_ui_conf' => '1',
'upload_ui_conf' => '1'
})
end