diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index cb82d2b0..1bd48995 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -64,12 +64,10 @@ Rails/OutputSafety: Rails/TimeZone: Exclude: - 'lib/browse_everything/driver/google_drive.rb' - - 'lib/browse_everything/driver/sky_drive.rb' - 'lib/browse_everything/retriever.rb' - 'spec/unit/browse_everything_helper_spec.rb' - 'spec/unit/file_entry_spec.rb' - 'spec/unit/retriever_spec.rb' - - 'spec/unit/sky_drive_spec.rb' - 'spec/views/browse_everything/_file.html.erb_spec.rb' # Offense count: 3 @@ -96,7 +94,6 @@ Style/FileName: Style/GuardClause: Exclude: - 'lib/browse_everything/driver/google_drive.rb' - - 'lib/browse_everything/driver/sky_drive.rb' # Offense count: 1 Style/MultilineBlockChain: @@ -109,22 +106,6 @@ Style/MultilineBlockLayout: Exclude: - 'spec/unit/dropbox_spec.rb' -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: symmetrical, new_line, same_line -Style/MultilineHashBraceLayout: - Exclude: - - 'spec/unit/sky_drive_spec.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. -# SupportedStyles: aligned, indented, indented_relative_to_receiver -Style/MultilineMethodCallIndentation: - Exclude: - - 'spec/unit/sky_drive_spec.rb' - # Offense count: 1 # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist. # NamePrefix: is_, has_, have_ diff --git a/README.md b/README.md index 44b17625..7247e460 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,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), +[Google Drive](http://drive.google.com), [Box](http://www.box.com), [Amazon S3](https://aws.amazon.com/s3/), and a server-side directory share. @@ -57,7 +57,7 @@ In `app/assets/javascripts/application.js` include jquery and the BrowseEverythi ### 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 +[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) ### Views diff --git a/browse-everything.gemspec b/browse-everything.gemspec index 14cffd81..e12b76eb 100644 --- a/browse-everything.gemspec +++ b/browse-everything.gemspec @@ -22,7 +22,6 @@ Gem::Specification.new do |spec| spec.add_dependency 'addressable', '~> 2.5' spec.add_dependency 'google_drive' spec.add_dependency 'dropbox-sdk', '>= 1.6.2' - spec.add_dependency 'skydrive' spec.add_dependency 'ruby-box' spec.add_dependency 'sass-rails' spec.add_dependency 'bootstrap-sass' diff --git a/lib/browse_everything.rb b/lib/browse_everything.rb index 575031eb..3fda1674 100644 --- a/lib/browse_everything.rb +++ b/lib/browse_everything.rb @@ -12,7 +12,6 @@ module Driver autoload :Base, 'browse_everything/driver/base' autoload :FileSystem, 'browse_everything/driver/file_system' autoload :Dropbox, 'browse_everything/driver/dropbox' - autoload :SkyDrive, 'browse_everything/driver/sky_drive' autoload :Box, 'browse_everything/driver/box' autoload :GoogleDrive, 'browse_everything/driver/google_drive' autoload :S3, 'browse_everything/driver/s3' diff --git a/lib/browse_everything/driver/sky_drive.rb b/lib/browse_everything/driver/sky_drive.rb deleted file mode 100644 index 4a250c3b..00000000 --- a/lib/browse_everything/driver/sky_drive.rb +++ /dev/null @@ -1,125 +0,0 @@ -module BrowseEverything - module Driver - class SkyDrive < Base - require 'skydrive' - - def icon - 'windows' - end - - def container_items - %w(folder album) - end - - def validate_config - unless config[:client_id] - raise BrowseEverything::InitializationError, 'SkyDrive driver requires a :client_id argument' - end - unless config[:client_secret] - raise BrowseEverything::InitializationError, 'SkyDrive driver requires a :client_secret argument' - end - end - - def contents(path = '') - result = [] - token_obj = rehydrate_token - client = Skydrive::Client.new(token_obj) - if path == '' - folder = client.my_skydrive - # TODO: do some loop to get down to my path - else - folder = client.get("/#{path.tr('-', '.')}/") - result += [parent_folder_details(folder)] if folder.parent_id - end - - files = folder.files - files.items.each do |item| - if container_items.include? item.type - result += [folder_details(item)] - else - Rails.logger.warn("\n\nID #{item.id} #{item.type}") - result += [file_details(item)] - end - end - result - end - - def link_for(path) - response = Skydrive::Client.new(rehydrate_token).get("/#{real_id(path)}/") - [response.download_link, { expires: 1.hour.from_now, file_name: File.basename(path), file_size: response.size.to_i }] - end - - def file_details(file) - BrowseEverything::FileEntry.new( - safe_id(file.id), - "#{key}:#{safe_id(file.id)}", - file.name, - file.size, - file.updated_time, - false - ) - end - - def parent_folder_details(file) - BrowseEverything::FileEntry.new( - safe_id(file.parent_id), - "#{key}:#{safe_id(file.parent_id)}", - '..', - 0, - Time.now, - true - ) - end - - def folder_details(folder) - BrowseEverything::FileEntry.new( - safe_id(folder.id), - "#{key}:#{safe_id(folder.id)}", - folder.name, - 0, - folder.updated_time, - true, - 'directory' # TODO: how are we getting mime type - ) - end - - def auth_link - oauth_client.authorize_url - end - - def authorized? - return false unless @token.present? - !rehydrate_token.expired? - end - - def connect(params, _data) - Rails.logger.warn "params #{params.inspect}" - token = oauth_client.get_access_token(params[:code]) - @token = { token: token.token, expires_at: token.expires_at } - end - - private - - def oauth_client - Skydrive::Oauth::Client.new(config[:client_id], config[:client_secret], callback.to_s, 'wl.skydrive') - # TODO: error checking here - end - - def rehydrate_token - return @rehydrate_token if @rehydrate_token - token_str = @token[:token] - token_expires = @token[:expires_at] - Rails.logger.warn "\n\n Rehydrating: #{@token} #{token_str} #{token_expires}" - @rehydrate_token = oauth_client.get_access_token_from_hash(token_str, expires_at: token_expires) - end - - def safe_id(id) - id.tr('.', '-') - end - - def real_id(id) - id.tr('-', '.') - 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 c66d468d..4a9150ac 100644 --- a/lib/generators/browse_everything/templates/browse_everything_providers.yml.example +++ b/lib/generators/browse_everything/templates/browse_everything_providers.yml.example @@ -18,6 +18,3 @@ # :app_secret: YOUR_AWS_S3_SECRET # explicitly here, or left out to use system-configured # :region: YOUR_AWS_S3_REGION # defaults. # See https://aws.amazon.com/blogs/security/a-new-and-standardized-way-to-manage-credentials-in-the-aws-sdks/ -# sky_drive: -# :client_id: YOUR_MS_LIVE_CONNECT_CLIENT_ID -# :client_secret: YOUR_MS_LIVE_CONNECT_CLIENT_SECRET diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 600f8508..2fa3d2d4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -60,10 +60,6 @@ def stub_configuration client_id: 'GoogleClientId', client_secret: 'GoogleClientSecret' }, - 'sky_drive' => { - client_id: 'SkyDriveClientId', - client_secret: 'SkyDriveClientSecret' - }, 's3' => { app_key: 'S3AppKey', app_secret: 'S3AppSecret', diff --git a/spec/unit/sky_drive_spec.rb b/spec/unit/sky_drive_spec.rb deleted file mode 100644 index a9b29c95..00000000 --- a/spec/unit/sky_drive_spec.rb +++ /dev/null @@ -1,65 +0,0 @@ -describe BrowseEverything::Driver::SkyDrive do - include BrowseEverything::Engine.routes.url_helpers - - let(:provider_yml) do - { - client_id: 'CLIENTID', client_secret: 'CLIENTSECRET', - url_options: { port: '3000', protocol: 'http://', host: 'example.com' } - } - end - - let(:redirect_url) { connector_response_url(provider_yml[:url_options]) } - - let(:response_body) do - { - 'client_id' => 'CLIENTID', 'client_secret' => 'CLIENTSECRET', 'code' => 'code', - 'grant_type' => 'authorization_code', 'redirect_uri' => redirect_url.to_s - } - end - - let(:driver) { described_class.new(provider_yml) } - - subject { driver } - - context 'when expiration is in the future' do - before do - stub_request(:post, 'https://login.live.com/oauth20_token.srf') - .with(body: response_body) - .to_return(status: 200, - body: { - 'token_type' => 'bearer', - 'expires_at' => (Time.now + (60 * 60 * 24)).to_i, - 'scope' => 'wl.skydrive_update,wl.offline_access', - 'access_token' => 'access_token', - 'refresh_token' => 'refresh_token', - 'authentication_token' => 'authentication_token' - }.to_json, - headers: { - 'content-type' => 'application/json' }) - driver.connect({ code: 'code' }, {}) - end - - it { is_expected.to be_authorized } - end - - context 'when the session has expired' do - before do - stub_request(:post, 'https://login.live.com/oauth20_token.srf') - .with(body: response_body) - .to_return(status: 200, - body: { - 'token_type' => 'bearer', - 'expires_at' => (Time.now - (60 * 60 * 24)).to_i, - 'scope' => 'wl.skydrive_update,wl.offline_access', - 'access_token' => 'access_token', - 'refresh_token' => 'refresh_token', - 'authentication_token' => 'authentication_token' - }.to_json, - headers: { - 'content-type' => 'application/json' }) - driver.connect({ code: 'code' }, {}) - end - - it { is_expected.not_to be_authorized } - end -end