carrierwave-dropbox 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +82 -0
- data/Rakefile +6 -0
- data/carrierwave-dropbox.gemspec +32 -0
- data/lib/carrierwave/dropbox.rb +18 -0
- data/lib/carrierwave/dropbox/authorize.rake +13 -0
- data/lib/carrierwave/dropbox/railtie.rb +9 -0
- data/lib/carrierwave/dropbox/rake.rb +41 -0
- data/lib/carrierwave/dropbox/version.rb +5 -0
- data/lib/carrierwave/storage/dropbox.rb +62 -0
- data/spec/carrierwave-uploader-base_spec.rb +18 -0
- data/spec/dummy/.gitignore +16 -0
- data/spec/dummy/Gemfile +11 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/articles_controller.rb +58 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/articles_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/article.rb +3 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/uploaders/image_uploader.rb +19 -0
- data/spec/dummy/app/views/articles/_form.html.erb +29 -0
- data/spec/dummy/app/views/articles/edit.html.erb +6 -0
- data/spec/dummy/app/views/articles/index.html.erb +31 -0
- data/spec/dummy/app/views/articles/new.html.erb +5 -0
- data/spec/dummy/app/views/articles/show.html.erb +1 -0
- data/spec/dummy/app/views/layouts/application.html.erb +12 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +23 -0
- data/spec/dummy/config/boot.rb +4 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/carrierwave.rb +8 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/db/migrate/20130801141015_create_articles.rb +11 -0
- data/spec/dummy/db/schema.rb +24 -0
- data/spec/dummy/db/seeds.rb +7 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/robots.txt +5 -0
- data/spec/features/upload_file_spec.rb +32 -0
- data/spec/fixtures/ruby.png +0 -0
- data/spec/spec_helper.rb +15 -0
- metadata +307 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c2ca8dc58cbc02e2c7c1a98eed41c49ed45699b0
|
4
|
+
data.tar.gz: 550df72f35dce48e4d39eb32d368f502968fcdeb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ea3d13fe24390bab8c55344013277dfa0a08a141bfd1ab9d8b30277532036d42da685b3f48bd5dc37565f59dbc241a4b6bde876019a0414242be82fd3ae11551
|
7
|
+
data.tar.gz: 499f42b826128d0e6f1b849a5991b76fae97765ef3a3da01cb32b4d6dcc3d682613f74f7cc6c0fa64975c41c6bd3b2ca998f70eddd4e839829b246942abf978a
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Robin Dupret
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Carrierwave uploads on Dropbox
|
2
|
+
|
3
|
+
This gem allows you to easily upload your medias on Dropbox using the awesome
|
4
|
+
[Carrierwave](https://github.com/carrierwaveuploader/carrierwave) gem.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
First, you have to create a [Dropbox app](https://www.dropbox.com/developers/apps). You can either create a "full dropbox" or "app folder" application. Please see
|
9
|
+
[this wiki](https://github.com/janko-m/paperclip-dropbox/wiki/Access-types) for
|
10
|
+
further information and gotchas.
|
11
|
+
|
12
|
+
Then, add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
~~~ruby
|
15
|
+
gem 'carrierwave-dropbox'
|
16
|
+
~~~
|
17
|
+
|
18
|
+
And make sure that it get installed running the `bundle` command. Then, you have
|
19
|
+
to run the `rake authorize` command to authorize your application to access to
|
20
|
+
your Dropbox.
|
21
|
+
|
22
|
+
If you are using Rails, the Rake task is automatically loaded. Otherwise, if you
|
23
|
+
aren't running a Rails application, first load the task in your `Rakefile`:
|
24
|
+
|
25
|
+
~~~ruby
|
26
|
+
load "paperclip/dropbox/tasks.rake"
|
27
|
+
~~~
|
28
|
+
|
29
|
+
Then you have to run this task:
|
30
|
+
|
31
|
+
~~~bash
|
32
|
+
rake dropbox:authorize APP_KEY=app_key APP_SECRET=app_secret ACCESS_TYPE=dropbox|app_folder
|
33
|
+
~~~
|
34
|
+
|
35
|
+
Finally, you will get your credentials. Config CarrierWave to make it work with
|
36
|
+
your Dropbox:
|
37
|
+
|
38
|
+
~~~ruby
|
39
|
+
CarrierWave.configure do |config|
|
40
|
+
config.dropbox_app_key = ENV["APP_KEY"]
|
41
|
+
config.dropbox_app_secret = ENV["APP_SECRET"]
|
42
|
+
config.dropbox_access_token = ENV["ACCESS_TOKEN"]
|
43
|
+
config.dropbox_access_token_secret = ENV["ACCESS_TOKEN_SECRET"]
|
44
|
+
config.dropbox_user_id = ENV["USER_ID"]
|
45
|
+
config.dropbox_access_type = "dropbox"
|
46
|
+
end
|
47
|
+
~~~
|
48
|
+
|
49
|
+
**Note**: It's advisable not to directly store the credentials in your files
|
50
|
+
especially if you are using a SCM (e.g. git). You should store these values in
|
51
|
+
[environment variables for instance](https://gist.github.com/canton7/1423106)
|
52
|
+
like in the above example.
|
53
|
+
|
54
|
+
Then you can either specify in your uploader files the storage or define it
|
55
|
+
globally through `CarrierWave.configure`:
|
56
|
+
|
57
|
+
~~~ruby
|
58
|
+
class ImageUploader < CarrierWave::Uploader::Base
|
59
|
+
storage :dropbox
|
60
|
+
end
|
61
|
+
~~~
|
62
|
+
|
63
|
+
## Special thanks
|
64
|
+
|
65
|
+
This project is highly based on these two gems:
|
66
|
+
|
67
|
+
* [paperclip-dropbox](https://github.com/janko-m/paperclip-dropbox)
|
68
|
+
* [carrierwave-aws](https://github.com/sorentwo/carrierwave-aws)
|
69
|
+
|
70
|
+
Thanks to their respective authors and contributors!
|
71
|
+
|
72
|
+
## Contributing
|
73
|
+
|
74
|
+
1. Fork it
|
75
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
76
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
77
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
78
|
+
5. Create new Pull Request
|
79
|
+
|
80
|
+
## License
|
81
|
+
|
82
|
+
Please see the `LICENSE` file for further information.
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'carrierwave/dropbox/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "carrierwave-dropbox"
|
8
|
+
spec.version = CarrierWave::Dropbox::VERSION
|
9
|
+
spec.authors = ["Robin Dupret"]
|
10
|
+
spec.email = ["robin.dupret@gmail.com"]
|
11
|
+
spec.description = %q{CarrierWave storage for Dropbox}
|
12
|
+
spec.summary = %q{Dropbox integration for CarrierWave}
|
13
|
+
spec.homepage = "https://github.com/robin850/carrierwave-dropbox"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "carrierwave", "~> 0.9"
|
22
|
+
spec.add_dependency "dropbox-sdk", "~> 1.6"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "capybara", "~> 2.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 2.14"
|
28
|
+
spec.add_development_dependency "sqlite3"
|
29
|
+
spec.add_development_dependency "mini_magick"
|
30
|
+
spec.add_development_dependency "selenium-webdriver"
|
31
|
+
spec.add_development_dependency "rails", ">= 3.2.14", "< 5.0"
|
32
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'carrierwave'
|
2
|
+
require 'carrierwave/storage/dropbox'
|
3
|
+
|
4
|
+
require 'carrierwave/dropbox/version'
|
5
|
+
require 'carrierwave/dropbox/railtie' if defined?(Rails)
|
6
|
+
|
7
|
+
class CarrierWave::Uploader::Base
|
8
|
+
add_config :dropbox_app_key
|
9
|
+
add_config :dropbox_app_secret
|
10
|
+
add_config :dropbox_access_token
|
11
|
+
add_config :dropbox_access_token_secret
|
12
|
+
add_config :dropbox_user_id
|
13
|
+
add_config :dropbox_access_type
|
14
|
+
|
15
|
+
configure do |config|
|
16
|
+
config.storage_engines[:dropbox] = 'CarrierWave::Storage::Dropbox'
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "carrierwave/dropbox/rake"
|
2
|
+
|
3
|
+
namespace :dropbox do
|
4
|
+
desc "Obtains your Dropbox credentials"
|
5
|
+
task :authorize do
|
6
|
+
if ENV["APP_KEY"].nil? or ENV["APP_SECRET"].nil?
|
7
|
+
puts "USAGE: `rake dropbox:authorize APP_KEY=your_app_key APP_SECRET=your_app_secret` ACCESS_TYPE=your_access_type"
|
8
|
+
exit
|
9
|
+
end
|
10
|
+
|
11
|
+
CarrierWave::Dropbox::Rake.authorize(ENV["APP_KEY"], ENV["APP_SECRET"], ENV["ACCESS_TYPE"] || "dropbox")
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "dropbox_sdk"
|
2
|
+
|
3
|
+
# This code is directly extracted from this repository:
|
4
|
+
# https://github.com/janko-m/paperclip-dropbox
|
5
|
+
module CarrierWave
|
6
|
+
module Dropbox
|
7
|
+
module Rake
|
8
|
+
extend self
|
9
|
+
|
10
|
+
def authorize(app_key, app_secret, access_type)
|
11
|
+
session = create_new_session(app_key, app_secret)
|
12
|
+
|
13
|
+
puts "Visit this URL: #{session.get_authorize_url}"
|
14
|
+
print "And after you approved the authorization confirm it here (y/n): "
|
15
|
+
|
16
|
+
assert_answer!
|
17
|
+
session.get_access_token
|
18
|
+
dropbox_client = DropboxClient.new(session, access_type)
|
19
|
+
account_info = dropbox_client.account_info
|
20
|
+
|
21
|
+
puts <<-MESSAGE
|
22
|
+
|
23
|
+
Authorization was successful. Here you go:
|
24
|
+
|
25
|
+
access_token: #{session.access_token.key}
|
26
|
+
access_token_secret: #{session.access_token.secret}
|
27
|
+
user_id: #{account_info["uid"]}
|
28
|
+
MESSAGE
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_new_session(app_key, app_secret)
|
32
|
+
DropboxSession.new(app_key, app_secret)
|
33
|
+
end
|
34
|
+
|
35
|
+
def assert_answer!
|
36
|
+
answer = STDIN.gets.strip
|
37
|
+
exit if answer == "n"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'dropbox_sdk'
|
3
|
+
|
4
|
+
module CarrierWave
|
5
|
+
module Storage
|
6
|
+
class Dropbox < Abstract
|
7
|
+
|
8
|
+
# Stubs we must implement to create and save
|
9
|
+
# files (here on Dropbox)
|
10
|
+
|
11
|
+
# Store a single file
|
12
|
+
def store!(file)
|
13
|
+
location = uploader.store_path
|
14
|
+
location = "/Public/#{location}" if config[:access_type] == "dropbox"
|
15
|
+
|
16
|
+
dropbox_client.put_file(location, file.to_file)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Retrieve a single file
|
20
|
+
def retrieve!(file)
|
21
|
+
CarrierWave::Storage::Dropbox::File.new(uploader, config, uploader.store_path(file))
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def dropbox_client
|
27
|
+
@dropbox_client ||= begin
|
28
|
+
session = DropboxSession.new(config[:app_key], config[:app_secret])
|
29
|
+
session.set_access_token(config[:access_token], config[:access_token_secret])
|
30
|
+
DropboxClient.new(session, config[:access_type])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def config
|
35
|
+
@config ||= {}
|
36
|
+
|
37
|
+
@config[:app_key] ||= uploader.dropbox_app_key
|
38
|
+
@config[:app_secret] ||= uploader.dropbox_app_secret
|
39
|
+
@config[:access_token] ||= uploader.dropbox_access_token
|
40
|
+
@config[:access_token_secret] ||= uploader.dropbox_access_token_secret
|
41
|
+
@config[:access_type] ||= uploader.dropbox_access_type || "dropbox"
|
42
|
+
@config[:user_id] ||= uploader.dropbox_user_id
|
43
|
+
|
44
|
+
@config
|
45
|
+
end
|
46
|
+
|
47
|
+
class File
|
48
|
+
include CarrierWave::Utilities::Uri
|
49
|
+
attr_reader :path
|
50
|
+
|
51
|
+
def initialize(uploader, config, path)
|
52
|
+
@uploader, @config, @path = uploader, config, path
|
53
|
+
end
|
54
|
+
|
55
|
+
def url
|
56
|
+
user_id, path = @config[:user_id], @path
|
57
|
+
"https://dl.dropboxusercontent.com/u/#{user_id}/#{path}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CarrierWave::Uploader::Base do
|
4
|
+
it "has the dropbox storage" do
|
5
|
+
described_class.configure do |c|
|
6
|
+
c.storage_engines.should have_key(:dropbox)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should respond to the different configuration methods" do
|
11
|
+
described_class.should respond_to(:dropbox_app_key)
|
12
|
+
described_class.should respond_to(:dropbox_app_secret)
|
13
|
+
described_class.should respond_to(:dropbox_access_token)
|
14
|
+
described_class.should respond_to(:dropbox_access_token_secret)
|
15
|
+
described_class.should respond_to(:dropbox_user_id)
|
16
|
+
described_class.should respond_to(:dropbox_access_type)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
6
|
+
|
7
|
+
# Ignore bundler config.
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore the default SQLite database.
|
11
|
+
/db/*.sqlite3
|
12
|
+
/db/*.sqlite3-journal
|
13
|
+
|
14
|
+
# Ignore all logfiles and tempfiles.
|
15
|
+
/log/*.log
|
16
|
+
/tmp
|
data/spec/dummy/Gemfile
ADDED
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
class ArticlesController < ApplicationController
|
2
|
+
before_action :set_article, only: [:show, :edit, :update, :destroy]
|
3
|
+
|
4
|
+
# GET /articles
|
5
|
+
def index
|
6
|
+
@articles = Article.all
|
7
|
+
end
|
8
|
+
|
9
|
+
# GET /articles/1
|
10
|
+
def show
|
11
|
+
end
|
12
|
+
|
13
|
+
# GET /articles/new
|
14
|
+
def new
|
15
|
+
@article = Article.new
|
16
|
+
end
|
17
|
+
|
18
|
+
# GET /articles/1/edit
|
19
|
+
def edit
|
20
|
+
end
|
21
|
+
|
22
|
+
# POST /articles
|
23
|
+
def create
|
24
|
+
@article = Article.new(article_params)
|
25
|
+
|
26
|
+
if @article.save
|
27
|
+
redirect_to @article, notice: 'Article was successfully created.'
|
28
|
+
else
|
29
|
+
render action: 'new'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# PATCH/PUT /articles/1
|
34
|
+
def update
|
35
|
+
if @article.update(article_params)
|
36
|
+
redirect_to @article, notice: 'Article was successfully updated.'
|
37
|
+
else
|
38
|
+
render action: 'edit'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# DELETE /articles/1
|
43
|
+
def destroy
|
44
|
+
@article.destroy
|
45
|
+
redirect_to articles_url, notice: 'Article was successfully destroyed.'
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
# Use callbacks to share common setup or constraints between actions.
|
50
|
+
def set_article
|
51
|
+
@article = Article.find(params[:id])
|
52
|
+
end
|
53
|
+
|
54
|
+
# Only allow a trusted parameter "white list" through.
|
55
|
+
def article_params
|
56
|
+
params.require(:article).permit(:title, :body, :image)
|
57
|
+
end
|
58
|
+
end
|