Rails engine providing access to files in cloud storage
Ruby JavaScript CoffeeScript HTML CSS
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app Fix all failing cops Jul 24, 2018
config Ensures that file and directory paths containing "." characters resol… Apr 6, 2018
lib Update version for v0.16.1 Aug 2, 2018
spec Allow browse_everything_providers.yml to contain symbols Aug 2, 2018
tasks Updating FactoryGirl to FactoryBot and Rubocop; Restructuring test su… Mar 5, 2018
vendor/assets Address @Jeck's comments from #68 Jul 29, 2014
.engine_cart.yml Update test matrix. Drop Rails 4.1, add 5.1 (#166) Jul 5, 2017
.gitignore Allow browse_everything_providers.yml to contain symbols Aug 2, 2018
.rspec Use .rspec file for color and common spec_helper requirement Sep 8, 2016
.rubocop.yml Fix all failing cops Jul 24, 2018
.rubocop_todo.yml Updating FactoryGirl to FactoryBot and Rubocop; Restructuring test su… Mar 5, 2018
.travis.yml Upgrading engine_cart to 2.0.1; Ensuring that puma is included for fu… Jun 12, 2018
CODE_OF_CONDUCT.md Fix issues link/add Code of Conduct. Aug 14, 2018
CONTRIBUTING.md Fix issues link/add Code of Conduct. Aug 14, 2018
Gemfile Merge branch 'master' into issues-220-jrgriffiniii-ecart-upgrade Jul 23, 2018
HISTORY.md Prepare for 0.10.5 release Sep 23, 2016
LICENSE.txt Initial commit Sep 17, 2013
README.md Resolve #228; Update docs to use templates Aug 14, 2018
Rakefile Updating FactoryGirl to FactoryBot and Rubocop; Restructuring test su… Mar 5, 2018
SUPPORT.md Resolve #228; Update docs to use templates Aug 14, 2018
browse-everything.gemspec Allow browse_everything_providers.yml to contain symbols Aug 2, 2018

README.md

BrowseEverything

Code: Gem Version Build Status Coverage Status

Docs: Contribution Guidelines Apache 2.0 License

Jump in: Slack Status

What is BrowseEverything?

This Gem allows your rails application to access user files from cloud storage. Currently there are drivers implemented for Dropbox, Google Drive, Box, Amazon S3, and a server-side directory share.

The gem uses OAuth to connect to a user's account and generate a list of single use urls that your application can then use to download the files.

This gem does not depend on hydra-head

Product Owner & Maintenance

BrowseEverything is a Core Component of the Samvera community. The documentation for what this means can be found here.

Product Owner

mbklein

Getting Started

Supported Ruby Releases

Currently, the following releases of Ruby are supported:

  • 2.5.1
  • 2.4.4
  • 2.3.7
    • Please note that this is the last release in the 2.3.x series, and support is scheduled to be withdrawn. We would strongly recommend that one upgrades from 2.3.7 in response to this.

Supported Rails Releases

  • 5.2.0
  • 5.1.6
  • 5.0.7
  • 4.2.10
    • The supported Rail releases follow those specified by the security policy of the Rails Community. As is the case with the supported Ruby releases, it is recommended that one upgrades from any Rails release no longer receiving security updates.

Installation

Add this lines to your application's Gemfile:

gem 'jquery-rails'
gem 'browse-everything'

And then execute:

$ bundle

Or install it yourself as:

$ gem install browse-everything

Configuring the gem

After installing the gem, run the generator

$ rails g browse_everything:install

This generator will set up the config/browse_everything_providers.yml file and add the browse-everything engine to your application's routes.

If you prefer not to use the generator, or need info on how to set up providers in the browse_everything_providers.yml, use the info on Configuring browse-everything.

Include the CSS and JavaScript

Add @import "browse_everything"; to your application.css.scss

In app/assets/javascripts/application.js include jquery and the BrowseEverything

//= require jquery
//= require browse_everything

Testing

This is a Rails Engine which is tested using the engine_cart Gem. Test suites may be executed with the following invocation:

bundle exec rake

Testing Problems

Should you attempt to execute the test suite and encounter the following error:

Your Ruby version is 2.x.x, but your Gemfile specified 2.y.z

...then you must clean the internal test app generated by engine_cart with the following:

bundle exec rake engine_cart:clean

Usage

Adding Providers

In order to connect to a provider like Dropbox, Google Drive, or Box, you must provide API keys in config/browse_everything_providers.yml. For info on how to edit this file, see Configuring browse-everything

Views

browse-everything can be triggered in two ways -- either via data attributes in an HTML tag or via JavaScript. Either way, it accepts the same options:

Options

Name Type Default Description
route path (required) '' The base route of the browse-everything engine.
target xpath or jQuery null A form object to add the results to as hidden fields.
context text null App-specific context information (passed with each request)
accept MIME mask / A list of acceptable MIME types to browse (e.g., 'video/*')

If a target is provided, browse-everything will automatically convert the JSON response to a series of hidden form fields that can be posted back to Rails to re-create the array on the server side.

Via data attributes

To trigger browse-everything using data attributes, set the data-toggle attribute to "browse-everything" on the HTML tag. This tells the javascript where to attach the browse-everything behaviors. Pass in the options using the data-route and data-target attributes, as in data-target="#myForm".

For example:

<button type="button" data-toggle="browse-everything" data-route="<%=browse_everything_engine.root_path%>"
  data-target="#myForm" class="btn btn-large btn-success" id="browse">Browse!</button>

Via JavaScript

To trigger browse-everything via javascript, use the .browseEverything() method to attach the behaviors to DOM elements.

$('#browse').browseEverything(options)

The options argument should be a JSON object with the route and (optionally) target values set. For example:

$('#browse').browseEverything({
  route: "/browse",
  target: "#myForm"
})

See JavaScript Methods for more info on using javascript to trigger browse-everything.

The Results (Data Structure)

browse-everything returns a JSON data structure consisting of an array of URL specifications. Each URL specification is a plain object with the following properties:

Property Description
url The URL of the selected remote file.
auth_header Any headers that need to be added to the request in order to access the remote file.
expires The expiration date/time of the specified URL.
file_name The base name (filename.ext) of the selected file.

For example, after picking two files from dropbox,

If you initialized browse-everything via JavaScript, the results data passed to the .done() callback will look like this:

[
  {
    "url": "https://dl.dropbox.com/fake/filepicker-demo.txt.txt",
    "expires": "2014-03-31T20:37:36.214Z",
    "file_name": "filepicker-demo.txt.txt"
  }, {
    "url": "https://dl.dropbox.com/fake/Getting%20Started.pdf",
    "expires": "2014-03-31T20:37:36.731Z",
    "file_name": "Getting Started.pdf"
  }
]

See JavaScript Methods for more info on using javascript to trigger browse-everything.

If you initialized browse-everything via data-attributes and set the target option (via the data-target attribute or via the target option on the javascript method), the results data be written as hidden fields in the <form> you've specified as the target. When the user submits that form, the results will look like this:

"selected_files" => {
  "0"=>{
    "url"=>"https://dl.dropbox.com/fake/filepicker-demo.txt.txt",
    "expires"=>"2014-03-31T20:37:36.214Z",
    "file_name"=>"filepicker-demo.txt.txt"
  },
  "1"=>{
    "url"=>"https://dl.dropbox.com/fake/Getting%20Started.pdf",
    "expires"=>"2014-03-31T20:37:36.731Z",
    "file_name"=>"Getting Started.pdf"
  }
}

Retrieving Files

The BrowseEverything::Retriever class has two methods, #retrieve and #download, that can be used to retrieve selected content. #retrieve streams the file by yielding it, chunk by chunk, to a block, while #download saves it to a local file.

Given the above response data:

retriever = BrowseEverything::Retriever.new
download_spec = params['selected_files']['1']

# Retrieve the file, yielding each chunk to a block
retriever.retrieve(download_spec) do |chunk, retrieved, total|
  # do something with the `chunk` of data received, and/or
  # display some progress using `retrieved` and `total` bytes.
end

# Download the file. If `target_file` isn't specified, the
# retriever will create a tempfile and return the name.
retriever.download(download_spec, target_file) do |filename, retrieved, total|
  # The block is still useful for showing progress, but the
  # first argument is the filename instead of a chunk of data.
end

Examples

See spec/support/app/views/file_handler/index.html for an example use case. You can also run rake app:generate to create a fully-functioning demo app in spec/internal (though you will have to create spec/internal/config/browse_everything.providers.yml file with your own configuration info.)

Help

The Samvera community is here to help. Please see our support guide.

Acknowledgments

This software has been developed by and is brought to you by the Samvera community. Learn more at the Samvera website.

Samvera Logo