Skip to content

Commit

Permalink
Adds Kaltura driver.
Browse files Browse the repository at this point in the history
  • Loading branch information
scherztc committed Nov 17, 2016
1 parent d0438f1 commit 899b039
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/browse_everything_controller.rb
Expand Up @@ -7,7 +7,7 @@ class BrowseEverythingController < ActionController::Base
after_action { session["#{provider_name}_token"] = provider.token unless provider.nil? }

def index
render layout: !request.xhr?
render :layout => !request.xhr?
end

def show
Expand Down
24 changes: 18 additions & 6 deletions app/views/browse_everything/_file.html.erb
Expand Up @@ -23,12 +23,24 @@
<td role="gridcell" class="ev-directory-select">
<%= check_box_tag(:select_all, "0", false, class: "ev-select-all") if file.container? %>
</td>
<td role="gridcell" class="ev-file-size">
<%= number_to_human_size(file.size).sub(/Bytes/,'bytes') %>
</td>
<td role="gridcell" class="ev-file-kind">
<%= file.type %>
</td>
<% if provide_name = 'kaltura' %>
<td role="gridcell" class="ev-file-size">
</td>
<% else %>
<td role="gridcell" class="ev-file-size">
<%= number_to_human_size(file.size).sub(/Bytes/,'bytes') %>
</td>
<% end %>
<% if provide_name = 'kaltura' %>
<td role="gridcell" class="ev-file-kind">
</td>
<% else %>
<td role="gridcell" class="ev-file-kind">
<%= file.type %>
</td>
<% end %>

<td role="gridcell" class="ev-file-date">
<%= file.mtime.strftime('%F %R') %>
</td>
Expand Down
1 change: 1 addition & 0 deletions browse-everything.gemspec
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions lib/browse_everything.rb
Expand Up @@ -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
Expand Down
53 changes: 53 additions & 0 deletions 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 = []
$current_user = main_app.scope.env['warden'].user.email.split("@")[0]
@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
Expand Up @@ -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
66 changes: 66 additions & 0 deletions spec/fixtures/vcr_cassettes/Kaltura_Session.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -10,6 +10,7 @@
require 'capybara/rspec'
require 'support/rake'
require 'coveralls'
require 'kaltura'

Coveralls.wear!
EngineCart.load_application!
Expand Down Expand Up @@ -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

Expand Down
43 changes: 43 additions & 0 deletions 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

0 comments on commit 899b039

Please sign in to comment.