diff --git a/README.md b/README.md index e24c2403..037485ff 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ This Gem allows your rails application to access user files from cloud storage. Currently there are drivers implemented for [Dropbox](http://www.dropbox.com), [Skydrive](https://skydrive.live.com/), [Google Drive](http://drive.google.com), -[Box](http://www.box.com), and a server-side directory share. +[Box](http://www.box.com),[Kaltura](http://www.kaltura.com) and a server-side directory share. The gem uses [OAuth](http://oauth.net/) to connect to a user's account and generate a list of single use urls that your application can then use to @@ -50,7 +50,7 @@ Add `//= require browse_everything` to your application.js ### Adding Providers In order to connect to a provider like [Dropbox](http://www.dropbox.com), [Skydrive](https://skydrive.live.com/), [Google Drive](http://drive.google.com), or -[Box](http://www.box.com), you must provide API keys in _config/browse_everything_providers.yml_. For info on how to edit this file, see [Configuring browse-everything](https://github.com/projecthydra/browse-everything/wiki/Configuring-browse-everything) +[Box](http://www.box.com), [Kaltura](http://www.kaltura.com), you must provide API keys in _config/browse_everything_providers.yml_. For info on how to edit this file, see [Configuring browse-everything](https://github.com/projecthydra/browse-everything/wiki/Configuring-browse-everything) ### Views diff --git a/app/controllers/browse_everything_controller.rb b/app/controllers/browse_everything_controller.rb index 69b1560c..f794daa1 100644 --- a/app/controllers/browse_everything_controller.rb +++ b/app/controllers/browse_everything_controller.rb @@ -7,7 +7,10 @@ class BrowseEverythingController < ActionController::Base after_action { session["#{provider_name}_token"] = provider.token unless provider.nil? } def index - render layout: !request.xhr? + if #{provider_name} == 'kaltura' + $current_user = warden.user.email.split("@")[0] + end + render :layout => !request.xhr? end def show diff --git a/app/views/browse_everything/_file.html.erb b/app/views/browse_everything/_file.html.erb index 8bea9020..984a1beb 100644 --- a/app/views/browse_everything/_file.html.erb +++ b/app/views/browse_everything/_file.html.erb @@ -23,12 +23,24 @@ <%= check_box_tag(:select_all, "0", false, class: "ev-select-all") if file.container? %> - - <%= number_to_human_size(file.size).sub(/Bytes/,'bytes') %> - - - <%= file.type %> - + <% if provide_name = 'kaltura' %> + + + <% else %> + + <%= number_to_human_size(file.size).sub(/Bytes/,'bytes') %> + + <% end %> + + <% if provide_name = 'kaltura' %> + + + <% else %> + + <%= file.type %> + + <% end %> + <%= file.mtime.strftime('%F %R') %> diff --git a/browse-everything.gemspec b/browse-everything.gemspec index 8b6bd094..0a6de23e 100644 --- a/browse-everything.gemspec +++ b/browse-everything.gemspec @@ -30,6 +30,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'signet' spec.add_dependency 'httparty' spec.add_dependency 'aws-sdk' + spec.add_dependency 'kaltura' spec.add_development_dependency 'rspec', '~> 3.0' spec.add_development_dependency 'rspec-rails' spec.add_development_dependency 'rspec-its' diff --git a/lib/browse_everything.rb b/lib/browse_everything.rb index 575031eb..1b088680 100644 --- a/lib/browse_everything.rb +++ b/lib/browse_everything.rb @@ -16,6 +16,7 @@ module Driver autoload :Box, 'browse_everything/driver/box' autoload :GoogleDrive, 'browse_everything/driver/google_drive' autoload :S3, 'browse_everything/driver/s3' + autoload :Kaltura, 'browse_everything/driver/kaltura' end class << self diff --git a/lib/browse_everything/driver/kaltura.rb b/lib/browse_everything/driver/kaltura.rb new file mode 100644 index 00000000..4c443110 --- /dev/null +++ b/lib/browse_everything/driver/kaltura.rb @@ -0,0 +1,53 @@ +module BrowseEverything + module Driver + class Kaltura < Base + require 'kaltura' + + def icon + 'kaltura' + end + + def validate_config + unless [:partner_id,:administrator_secret,:service_url].all? { |key| config[key].present? } + raise BrowseEverything::InitializationError, "Kaltura driver requires :partner_id, :administrator_secret, and :service_url" + end + end + + def contents(path='') + result = [] + + @options = { :filter => { :creatorIdEqual => $current_user } } + @session = ::Kaltura::Session.start + @@entries = ::Kaltura::MediaEntry.list(@options) + @@entries.each do |item| + item.location = item.downloadUrl.sub('https:', 'kaltura:') + item.mtime = Time.at(item.updatedAt.to_i) + result.push(item) + end + result + end + + def link_for(path) + correct_path = path.sub('//', 'https://') + file_list = @@entries + extras = {file_name: ''} + file_list.each do |file| + if file.downloadUrl == correct_path + extras[:file_name] = file.name + end + end + ret = [correct_path, extras] + end + + def details(path) + byebug + contents(path).first + end + + def authorized? + true + end + + end + end +end diff --git a/lib/generators/browse_everything/templates/browse_everything_providers.yml.example b/lib/generators/browse_everything/templates/browse_everything_providers.yml.example index a5597fcb..ff74a22e 100644 --- a/lib/generators/browse_everything/templates/browse_everything_providers.yml.example +++ b/lib/generators/browse_everything/templates/browse_everything_providers.yml.example @@ -20,3 +20,7 @@ # sky_drive: # :client_id: YOUR_MS_LIVE_CONNECT_CLIENT_ID # :client_secret: YOUR_MS_LIVE_CONNECT_CLIENT_SECRET +# kaltura: +# :partner_id: YOUR_KLATURA_PARTNER_ID +# :administrator_secret: YOUR_KALTURA_ADMINSTRATOR_SECRET +# :service_url: YOUR_SERVICE_URL diff --git a/spec/fixtures/vcr_cassettes/Kaltura_Session.yml b/spec/fixtures/vcr_cassettes/Kaltura_Session.yml new file mode 100644 index 00000000..97534763 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Kaltura_Session.yml @@ -0,0 +1,66 @@ +--- +http_interactions: +- request: + method: get + uri: http://www.kaltura.com/api_v3/?action=start&ks=&partnerId=1&secret=superdupersecret&service=session&type=2 + body: + encoding: US-ASCII + string: '' + headers: {} + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 26 Aug 2011 21:38:40 GMT + Server: + - Apache + Vary: + - Accept-Encoding + X-Me: + - pa-apache3 + X-Ua-Compatible: + - IE=EmulateIE7 + Content-Length: + - '230' + Content-Type: + - text/xml + body: + encoding: UTF-8 + string: thisisavalidsession0.048589944839478 + http_version: '1.1' + recorded_at: Fri, 23 Sep 2016 18:46:02 GMT +- request: + method: get + uri: http://www.kaltura.com/api_v3/?action=start&ks=&partnerId=2&secret=superdupersecret&service=session&type=2 + body: + encoding: US-ASCII + string: '' + headers: {} + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 26 Aug 2011 21:38:40 GMT + Server: + - Apache + Vary: + - Accept-Encoding + X-Me: + - pa-apache3 + X-Ua-Compatible: + - IE=EmulateIE7 + Content-Length: + - '227' + Content-Type: + - text/xml + body: + encoding: UTF-8 + string: START_SESSION_ERRORError + while starting session for partner [2]0.040677070617676 + http_version: '1.1' + recorded_at: Fri, 23 Sep 2016 18:46:02 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 600f8508..ace3ddb5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,6 +10,7 @@ require 'capybara/rspec' require 'support/rake' require 'coveralls' +require 'kaltura' Coveralls.wear! EngineCart.load_application! @@ -68,6 +69,11 @@ def stub_configuration app_key: 'S3AppKey', app_secret: 'S3AppSecret', bucket: 's3.bucket' + }, + 'kaltura' => { + partner_id: 'KalturaClientId', + administrator_secret: 'KalturaAdminSecret', + service_url: 'KalturaServiceUrl' }) end diff --git a/spec/unit/kaltura_spec.rb b/spec/unit/kaltura_spec.rb new file mode 100644 index 00000000..333a488f --- /dev/null +++ b/spec/unit/kaltura_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +describe "Kaltura Driver", :vcr => { cassette_name: 'Kaltura_Session', record: :none } do + + context "starting a session", :vcr => { cassette_name: 'Kaltura_Session', record: :none } do + + describe "should properly set and read config values" do + before do + Kaltura.configure do |config| + config.partner_id = 1 + config.administrator_secret = 'superdupersecret' + config.service_url = 'http://www.kaltura.com' + end + end + + it { Kaltura.config.partner_id.should == 1 } + it { Kaltura.config.administrator_secret.should == 'superdupersecret' } + it { Kaltura.config.service_url.should == 'http://www.kaltura.com' } + end + + describe "should begin a session with proper credentials." do + before do + Kaltura.configure do |config| + config.partner_id = 1 + config.administrator_secret = 'superdupersecret' + config.service_url = 'http://www.kaltura.com' + end + @session = Kaltura::Session.start + end + + it { @session.result.should be_an_instance_of String } + it { Kaltura::Session.kaltura_session.should eq(@session.result) } + end + + describe "should not begin a session with invalid credentials." do + before do + Kaltura.configure { |config| config.partner_id = 2 } + end + + it { lambda {Kaltura::Session.start}.should raise_error Kaltura::KalturaError } + end + end +end