paperclip-dropbox 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/README.md +37 -20
- data/lib/paperclip/dropbox/rake.rb +5 -3
- data/lib/paperclip/dropbox/tasks/authorize.rake +4 -1
- data/lib/paperclip/storage/dropbox.rb +6 -4
- data/paperclip-dropbox.gemspec +2 -3
- metadata +5 -20
- data/UPGRADING +0 -7
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Janko Marohnić
|
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
CHANGED
@@ -48,21 +48,21 @@ access_token_secret: <%= ENV["DROPBOX_ACCESS_TOKEN_SECRET"] %>
|
|
48
48
|
user_id: <%= ENV["DROPBOX_USER_ID"] %>
|
49
49
|
```
|
50
50
|
|
51
|
-
This is a good practice;
|
52
|
-
set them in
|
51
|
+
This is a good practice; Don't put your credentials directly in your YAML file.
|
52
|
+
Instead set them in system environment variables, and then embed them here through ERB.
|
53
53
|
|
54
54
|
Note that all credentials mentioned here are required.
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
have to be stored in your `Public` directory, otherwise accessing their URLs
|
61
|
-
would be too slow.
|
56
|
+
If you don't have your app key and secret yet, go to your [Dropbox apps](https://www.dropbox.com/developers/apps),
|
57
|
+
and create a new app there, which will then provide you your app key and secret.
|
58
|
+
Note that your app has to have the **Full Dropbox** access level (not the "App folder").
|
59
|
+
This is because the uploaded files have to be stored in your `Public` folder.
|
62
60
|
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
If you're a relatively new Dropbox user, you'll have to enable your `Public` folder first by visiting
|
62
|
+
[this link](https://www.dropbox.com/enable_public_folder).
|
63
|
+
|
64
|
+
After you obtain your app key and secret, you can obtain the rest of the credentials
|
65
|
+
through the `dropbox:authorize` rake task, which is described in more detail at the bottom of the readme.
|
66
66
|
|
67
67
|
You can also namespace your credentials in `development`, `testing` and `production` environments
|
68
68
|
(just like you do in your `database.yml`).
|
@@ -77,7 +77,7 @@ You can pass it 3 options:
|
|
77
77
|
- `:unique_filename` – Boolean
|
78
78
|
|
79
79
|
The `:path` option works in this way; you give it a block, and the return value
|
80
|
-
will be the path that the uploaded file will be saved to. The block yields
|
80
|
+
will be the path that the uploaded file will be saved to. The block yields attachment style,
|
81
81
|
and is executed in the scope of the class' instance. For example, let's say you have
|
82
82
|
|
83
83
|
```ruby
|
@@ -85,15 +85,15 @@ class User < ActiveRecord::Base
|
|
85
85
|
has_attached_file :avatar,
|
86
86
|
:storage => :dropbox,
|
87
87
|
:dropbox_credentials => "...",
|
88
|
+
:styles => { :medium => "300x300" },
|
88
89
|
:dropbox_options => {
|
89
90
|
:path => proc { |style| "#{style}/#{id}_#{avatar.original_filename}"}
|
90
|
-
}
|
91
|
-
:styles => { :medium => "300x300" }
|
91
|
+
}
|
92
92
|
end
|
93
93
|
```
|
94
94
|
|
95
|
-
Let's say now that a user is
|
96
|
-
avatar. The
|
95
|
+
Let's say now that a new user is created with the ID of `23`, and a `photo.jpg` as his
|
96
|
+
avatar. The following files would be saved to the Dropbox:
|
97
97
|
|
98
98
|
```
|
99
99
|
Public/original/23_photo.jpg
|
@@ -101,12 +101,29 @@ Public/medium/23_photo_medium.jpg
|
|
101
101
|
```
|
102
102
|
|
103
103
|
The other file is called `photo_medium.jpg` because style names (other than `original`)
|
104
|
-
will always be appended to the filenames.
|
104
|
+
will always be appended to the filenames, for better management.
|
105
105
|
|
106
106
|
Files in Dropbox inside a certain folder have to have **unique filenames**, otherwise exception
|
107
107
|
`Paperclip::Storage::Dropbox::FileExists` is thrown. To help you with that, you
|
108
|
-
can
|
109
|
-
|
108
|
+
can set
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
# ...
|
112
|
+
:dropbox_options => {
|
113
|
+
:unique_filename => true
|
114
|
+
}
|
115
|
+
```
|
116
|
+
|
117
|
+
That will set `:path` to something that will be unique.
|
118
|
+
|
119
|
+
You can also pass in the `:download` option to attachment's `#url`:
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
user.avatar.url(:download => true)
|
123
|
+
```
|
124
|
+
|
125
|
+
And that will return a download URL for that attachment (so, if a user clicks to
|
126
|
+
that link, the file will be downloaded, as opposed to being opened in the browser).
|
110
127
|
|
111
128
|
### The `dropbox:authorize` rake task
|
112
129
|
|
@@ -120,7 +137,7 @@ It will provide you an authorization URL which you have to visit, and after that
|
|
120
137
|
it will output the rest of your credentials, which you just copy-paste wherever
|
121
138
|
you need to.
|
122
139
|
|
123
|
-
If you're in a non-Rails application, to get this task, you must require it in
|
140
|
+
If you're in a non-Rails application, to get this rake task, you must require it in
|
124
141
|
your `Rakefile`:
|
125
142
|
|
126
143
|
```ruby
|
@@ -7,19 +7,23 @@ module Paperclip
|
|
7
7
|
|
8
8
|
def authorize(app_key, app_secret)
|
9
9
|
session = create_new_session(app_key, app_secret)
|
10
|
-
|
10
|
+
|
11
|
+
puts "\nVisit this URL: #{session.get_authorize_url}"
|
11
12
|
print "And after you approved the authorization confirm it here (y/n): "
|
13
|
+
|
12
14
|
assert_answer!
|
13
15
|
session.get_access_token
|
14
16
|
dropbox_client = DropboxClient.new(session, "dropbox")
|
15
17
|
account_info = dropbox_client.account_info
|
16
18
|
|
17
19
|
puts <<-MESSAGE
|
20
|
+
|
18
21
|
Authorization was successful. Here you go:
|
19
22
|
|
20
23
|
access_token: #{session.access_token.key}
|
21
24
|
access_token_secret: #{session.access_token.secret}
|
22
25
|
user_id: #{account_info["uid"]}
|
26
|
+
|
23
27
|
MESSAGE
|
24
28
|
end
|
25
29
|
|
@@ -34,5 +38,3 @@ user_id: #{account_info["uid"]}
|
|
34
38
|
end
|
35
39
|
end
|
36
40
|
end
|
37
|
-
|
38
|
-
load "paperclip/dropbox/tasks/authorize.rake"
|
@@ -2,8 +2,11 @@ require "rake"
|
|
2
2
|
require "paperclip/dropbox/rake" unless defined?(Paperclip::Dropbox::Rake)
|
3
3
|
|
4
4
|
namespace :dropbox do
|
5
|
-
desc "Obtains your credentials"
|
5
|
+
desc "Obtains your Dropbox credentials"
|
6
6
|
task :authorize do
|
7
|
+
if ENV["APP_KEY"].nil? or ENV["APP_SECRET"].nil?
|
8
|
+
raise ArgumentError, "usage: `rake dropbox:authorize APP_KEY=your_app_key APP_SECRET=your_app_secret`"
|
9
|
+
end
|
7
10
|
Paperclip::Dropbox::Rake.authorize(ENV["APP_KEY"], ENV["APP_SECRET"])
|
8
11
|
end
|
9
12
|
end
|
@@ -44,11 +44,13 @@ module Paperclip
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def url(*args)
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
unless blank?
|
48
|
+
style = args.first.is_a?(Symbol) ? args.first : default_style
|
49
|
+
options = args.last.is_a?(Hash) ? args.last : {}
|
50
|
+
query = options[:download] ? "?dl=1" : ""
|
50
51
|
|
51
|
-
|
52
|
+
File.join("http://dl.dropbox.com/u/#{user_id}", path_for_url(style) + query)
|
53
|
+
end
|
52
54
|
end
|
53
55
|
|
54
56
|
def path(style)
|
data/paperclip-dropbox.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.name = "paperclip-dropbox"
|
5
|
-
gem.version = "1.0.
|
5
|
+
gem.version = "1.0.1"
|
6
6
|
gem.platform = Gem::Platform::RUBY
|
7
7
|
|
8
8
|
gem.homepage = "https://github.com/janko-m/paperclip-dropbox"
|
@@ -11,13 +11,12 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.authors = ["Janko Marohnić"]
|
12
12
|
gem.email = ["janko.marohnic@gmail.com"]
|
13
13
|
|
14
|
-
gem.files = Dir["lib/**/*"] + ["README.md", "
|
14
|
+
gem.files = Dir["lib/**/*"] + ["README.md", "LICENSE", "paperclip-dropbox.gemspec"]
|
15
15
|
gem.require_path = "lib"
|
16
16
|
|
17
17
|
gem.required_ruby_version = ">= 1.9.2"
|
18
18
|
|
19
19
|
gem.license = "MIT"
|
20
|
-
gem.post_install_message = File.read("UPGRADING")
|
21
20
|
|
22
21
|
gem.add_dependency "paperclip", "~> 3.1"
|
23
22
|
gem.add_dependency "dropbox-sdk", "~> 1.3"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip-dropbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: paperclip
|
@@ -169,25 +169,12 @@ files:
|
|
169
169
|
- lib/paperclip/storage/dropbox.rb
|
170
170
|
- lib/paperclip-dropbox.rb
|
171
171
|
- README.md
|
172
|
-
-
|
172
|
+
- LICENSE
|
173
173
|
- paperclip-dropbox.gemspec
|
174
174
|
homepage: https://github.com/janko-m/paperclip-dropbox
|
175
175
|
licenses:
|
176
176
|
- MIT
|
177
|
-
post_install_message:
|
178
|
-
|
179
|
-
# NOTE FOR UPGRADING FROM 0.x VERSIONS #
|
180
|
-
|
181
|
-
########################################
|
182
|
-
|
183
|
-
|
184
|
-
paperclip-dropbox 1.0 is a rewrite of 0.x versions,
|
185
|
-
|
186
|
-
and it introduces a lot of non-backwards compatible changes.
|
187
|
-
|
188
|
-
It is suggested that you read the Readme again.
|
189
|
-
|
190
|
-
'
|
177
|
+
post_install_message:
|
191
178
|
rdoc_options: []
|
192
179
|
require_paths:
|
193
180
|
- lib
|
@@ -203,9 +190,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
190
|
- - ! '>='
|
204
191
|
- !ruby/object:Gem::Version
|
205
192
|
version: '0'
|
206
|
-
segments:
|
207
|
-
- 0
|
208
|
-
hash: -407876590355858584
|
209
193
|
requirements: []
|
210
194
|
rubyforge_project:
|
211
195
|
rubygems_version: 1.8.23
|
@@ -213,3 +197,4 @@ signing_key:
|
|
213
197
|
specification_version: 3
|
214
198
|
summary: Extends Paperclip with Dropbox storage.
|
215
199
|
test_files: []
|
200
|
+
has_rdoc:
|
data/UPGRADING
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
########################################
|
2
|
-
# NOTE FOR UPGRADING FROM 0.x VERSIONS #
|
3
|
-
########################################
|
4
|
-
|
5
|
-
paperclip-dropbox 1.0 is a rewrite of 0.x versions,
|
6
|
-
and it introduces a lot of non-backwards compatible changes.
|
7
|
-
It is suggested that you read the Readme again.
|