paperclip-dropbox 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -3,29 +3,45 @@
3
3
  This gem extends [Paperclip](https://github.com/thoughtbot/paperclip) with
4
4
  [Dropbox](https://www.dropbox.com) storage.
5
5
 
6
- ## Installation
6
+ ## Setup
7
7
 
8
- ```sh
9
- $ gem install paperclip-dropbox
8
+ ```ruby
9
+ gem "paperclip-dropbox", ">= 1"
10
+ ```
11
+
12
+ Example:
13
+
14
+ ```ruby
15
+ class User < ActiveRecord::Base
16
+ has_attached_file :avatar,
17
+ :storage => :dropbox,
18
+ :dropbox_credentials => Rails.root.join("config/dropbox.yml"),
19
+ :dropbox_options => {...}
20
+ end
10
21
  ```
11
22
 
12
- ## Dropbox Setup
23
+ Your `config/dropbox.yml`:
13
24
 
14
- You must [create a Dropbox app](https://www.dropbox.com/developers/apps) and
15
- authorize it to access the Dropbox account you want to use for storage. You have
16
- a choice of two access types: **App folder** or **Full Dropbox**. You can read
17
- about the differences in [this wiki](https://github.com/janko-m/paperclip-dropbox/wiki/Access-types).
25
+ ```yaml
26
+ app_key: "..."
27
+ app_secret: "..."
28
+ access_token: "..."
29
+ access_token_secret: "..."
30
+ user_id: "..."
31
+ access_type: "..."
32
+ ```
18
33
 
19
- After creating your app, it will have an "App key" and "App secret". Provide
20
- these and the access type (`dropbox` or `app_folder`) to the authorization Rake task:
34
+ In order to fill these in, you must [create a Dropbox app](https://www.dropbox.com/developers/apps)
35
+ and authorize it. There are two types of Dropbox apps: **App folder** or **Full Dropbox**. You can read
36
+ about the differences and gotchas in [this wiki](https://github.com/janko-m/paperclip-dropbox/wiki/Access-types).
37
+
38
+ After you have created an app, you will be given the "App key" and "App secret". Provide
39
+ these and the access type to the authorization Rake task:
21
40
 
22
41
  ```sh
23
- $ rake dropbox:authorize APP_KEY=your_app_key APP_SECRET=your_app_secret ACCESS_TYPE=your_access_type
42
+ $ rake dropbox:authorize APP_KEY=your_app_key APP_SECRET=your_app_secret ACCESS_TYPE=dropbox|app_folder
24
43
  ```
25
44
 
26
- First it will give you an authorization URL that you must visit to grant the app access.
27
- Then it will output your **access token**, and **user ID**.
28
-
29
45
  For non-Rails projects, you must require this task in your `Rakefile`:
30
46
 
31
47
  ```ruby
@@ -33,47 +49,29 @@ For non-Rails projects, you must require this task in your `Rakefile`:
33
49
  load "paperclip/dropbox/tasks.rake"
34
50
  ```
35
51
 
36
- ## Configuration
37
-
38
- Example:
52
+ Follow the instructions, and it will authorize the Dropbox app and output the rest of the credentials.
53
+ Then you can fill in the rest of `config/dropbox.yml`.
39
54
 
40
- ```ruby
41
- class User < ActiveRecord::Base
42
- has_attached_file :avatar,
43
- :storage => :dropbox,
44
- :dropbox_credentials => "#{Rails.root}/config/dropbox.yml",
45
- :dropbox_options => {...}
46
- end
47
- ```
55
+ And that's it. Everything should work now :)
48
56
 
49
57
  ### The `:dropbox_credentials` option
50
58
 
51
- This can be a hash or path to a YAML file containing the keys listed in the
52
- example below. These are obtained from your Dropbox app settings and the
53
- authorization Rake task.
54
-
55
- Example `config/dropbox.yml`:
56
-
57
- ```yaml
58
- app_key: "APP_KEY"
59
- app_secret: "APP_SECRET"
60
- access_token: "ACCESS_TOKEN"
61
- access_token_secret: "ACCESS_TOKEN_SECRET"
62
- user_id: "USER_ID"
63
- access_type: "ACCESS_TYPE"
59
+ ```ruby
60
+ :dropbox_credentials => Rails.root.join("config/dropbox.yml")
61
+ # or
62
+ :dropbox_credentials => {app_key: "foo", app_secret: "bar", ...}
64
63
  ```
65
64
 
66
- Of course, replace these strings with real values. The `"ACCESS_TYPE"`
67
- must be either `"dropbox"` or `"app_folder"` depending on the access
68
- type of your app; see **Dropbox Setup** above. If you're keeping your
69
- credentials in environment variables (or something similar), you can also use
70
- ERB:
65
+ For the list of required credentials, take a look at the `config/dropbox.yml`
66
+ above.
67
+
68
+ The YAML file supports ERB:
71
69
 
72
70
  ```erb
73
71
  app_key: <%= ENV["DROPBOX_APP_KEY"] %>
74
72
  ```
75
73
 
76
- You can also nest your credentials in environments (like in your `database.yml`):
74
+ And it supports environment nesting (just like `database.yml`):
77
75
 
78
76
  ```yaml
79
77
  development:
@@ -88,60 +86,42 @@ production:
88
86
 
89
87
  This is a hash containing any of the following options:
90
88
 
91
- - `:path` – Block, works similarly to Paperclip's `:path` option
92
- - `:unique_filename` – Boolean, whether to generate unique names for files in
93
- the absence of a custom `:path`
94
89
  - `:environment` – String, the environment name to use for selecting namespaced
95
90
  credentials in a non-Rails app
96
91
 
97
- The `:path` option should be a block that returns a path that the uploaded file
98
- should be saved to. The block yields the attachment style and is executed in the
99
- scope of the model instance. For example:
92
+ For example:
100
93
 
101
94
  ```ruby
102
95
  class User < ActiveRecord::Base
103
96
  has_attached_file :avatar,
104
97
  :storage => :dropbox,
105
- :dropbox_credentials => "#{Rails.root}/config/dropbox.yml",
106
- :styles => { :medium => "300x300" },
107
- :dropbox_options => {
108
- :path => proc { |style| "#{style}/#{id}_#{avatar.original_filename}" }
109
- }
98
+ :dropbox_credentials => Rails.root.join("config/dropbox.yml"),
99
+ :dropbox_options => {environment: ENV["RACK_ENV"]}
110
100
  end
111
101
  ```
112
102
 
113
- Let's say now that a new user is created with the ID of `23`, and a `photo.jpg`
114
- as his avatar. The following files would be saved to the Dropbox:
103
+ In Rails you don't need to specify it.
115
104
 
116
- ```
117
- Public/original/23_photo.jpg
118
- Public/medium/23_photo_medium.jpg
119
- ```
105
+ ### The `:path` option
120
106
 
121
- The other file is called `photo_medium.jpg` because style names (other than
122
- `original`) will always be appended to the filenames, for better management.
107
+ To change the path of the file, use Paperclip's `:path` option:
123
108
 
124
- Filenames within a Dropbox folder must be unique; uploading a file with a
125
- duplicate name will throw error `Paperclip::Storage::Dropbox::FileExists`. If
126
- you don't want to bother crafting your own unique filenames with the `:path`
127
- option, you can instead set the `:unique_filename` option to true and it will
128
- take care of that.
109
+ ```ruby
110
+ :path => ":style/:id_:filename" # Defaults to ":filename"
111
+ ```
112
+
113
+ In "Full Dropbox" mode it will automatically be searched in the `Public` folder,
114
+ so there is not need to specify it.
129
115
 
130
116
  ### URL options
131
117
 
132
- When using `dropbox` access type, the `#url` method of attachments returns a
133
- URL to a "landing page" that provides a preview of the file and a download link.
134
- To make `#url` return a direct file download link, set the `:download` option as
135
- a parameter:
118
+ If you want to force the browser to always download the file, you can use
119
+ the `:download` option.
136
120
 
137
121
  ```ruby
138
122
  user.avatar.url(:download => true)
139
123
  ```
140
124
 
141
- When using `app_folder` access type, `#url` always returns a direct link, and
142
- setting the `:download` option simply forces the file to be downloaded even if
143
- the browser would normally just display it.
144
-
145
125
  ### Check if the file exists
146
126
 
147
127
  You can easily check if the file exists on Dropbox:
@@ -16,7 +16,7 @@ module Paperclip
16
16
  url.query = [url.query, "dl=1"].compact.join("&") if options[:download]
17
17
  url.to_s
18
18
  else
19
- @attachment_options[:default_url]
19
+ @attachment_options[:interpolator].interpolate(@attachment_options[:default_url], @attachment, style)
20
20
  end
21
21
  end
22
22
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "paperclip-dropbox"
5
- gem.version = "1.1.4"
5
+ gem.version = "1.1.5"
6
6
 
7
7
  gem.homepage = "https://github.com/janko-m/paperclip-dropbox"
8
8
  gem.description = %q{Extends Paperclip with Dropbox storage.}
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.1.4
4
+ version: 1.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -201,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
201
  version: '0'
202
202
  segments:
203
203
  - 0
204
- hash: 487816321
204
+ hash: 129369807
205
205
  requirements: []
206
206
  rubyforge_project:
207
207
  rubygems_version: 1.8.23