Skip to content

Commit

Permalink
Adds Kaltura driver.
Browse files Browse the repository at this point in the history
  • Loading branch information
scherztc committed Sep 28, 2016
1 parent 4d022a3 commit 992055a
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
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
3 changes: 3 additions & 0 deletions app/controllers/browse_everything_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class BrowseEverythingController < ActionController::Base
after_filter {session["#{provider_name}_token"] = provider.token unless provider.nil? }

def index
if #{provider_name} == 'kaltura'
$current_user = warden.user.email.split("@")[0]
end
render :layout => !request.xhr?
end

Expand Down
24 changes: 18 additions & 6 deletions app/views/browse_everything/_file.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,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
2 changes: 2 additions & 0 deletions browse-everything.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "bootstrap-sass"
spec.add_dependency "font-awesome-rails"
spec.add_dependency "google-api-client", "~> 0.8.6"
spec.add_dependency "kaltura"
spec.add_dependency "httparty"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "rspec-rails"
Expand All @@ -44,4 +45,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "jasmine", '~> 2.3'
spec.add_development_dependency "coveralls"
spec.add_development_dependency "poltergeist", "~> 1.10"
spec.add_development_dependency "rack"
end
1 change: 1 addition & 0 deletions lib/browse_everything.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Driver
autoload :SkyDrive, 'browse_everything/driver/sky_drive'
autoload :Box, 'browse_everything/driver/box'
autoload :GoogleDrive, 'browse_everything/driver/google_drive'
autoload :Kaltura, 'browse_everything/driver/kaltura'
end

class << self
Expand Down
53 changes: 53 additions & 0 deletions lib/browse_everything/driver/kaltura.rb
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,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
2 changes: 1 addition & 1 deletion spec/features/select_files_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
it "selects files from the filesystem" do
click_button('Browse')
sleep(5)
click_link("README.rdoc")
click_link("README.md")
within(".modal-footer") do
expect(page).to have_selector("span", text: "1 file selected")
click_button("Submit")
Expand Down
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.

8 changes: 7 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
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 @@ -64,7 +65,12 @@ def stub_configuration
"sky_drive" => {
client_id: "SkyDriveClientId",
client_secret: "SkyDriveClientSecret"
}
},
"kaltura" => {
partner_id: "KalturaClientId",
administrator_secret: "KalturaAdminSecret",
service_url: "KalturaServiceUrl"
}
})
end

Expand Down
43 changes: 43 additions & 0 deletions spec/unit/kaltura_spec.rb
Original file line number Diff line number Diff line change
@@ -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 992055a

Please sign in to comment.