paperclip-googledrive 0.0.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README.md +78 -6
- data/lib/paperclip/version.rb +1 -1
- data/paperclip-googledrive.gemspec +1 -1
- metadata +2 -2
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
+
|
1
2
|
# PaperclipGoogledrive
|
2
|
-
--- WORK IN PROGRESS ---
|
3
3
|
|
4
|
-
PaperclipGoogledrive is a gem that extends paperclip storage for Google Drive.
|
4
|
+
PaperclipGoogledrive is a gem that extends paperclip storage for Google Drive. Works with Rails 3.x.
|
5
5
|
|
6
6
|
## Installation
|
7
7
|
|
@@ -17,12 +17,81 @@ Or install it yourself as:
|
|
17
17
|
|
18
18
|
$ gem install paperclip-googledrive
|
19
19
|
|
20
|
-
##
|
20
|
+
## Google Drive Setup
|
21
|
+
|
22
|
+
Google Drive is a free service for file storage files. In order to use this storage you have to create oauth 2.0 client in [Google APIs console](https://code.google.com/apis/console/) and authorize access to Google Drive account.
|
23
|
+
|
24
|
+
After creating your app, it will have an Client ID, Client Secret, Redirect URL. Get auth scope for drive [Google Drive scopes](https://developers.google.com/drive/scopes). You need these for the authorization Rake task:
|
25
|
+
```
|
26
|
+
$ rake google_drive:authorize
|
27
|
+
```
|
28
|
+
When you call this Rake task, it will ask you to provide the client id, client secret, redirect url and auth scope. Afterwards it will present you with an authorize url on Google Drive. Simply go to that url, authorize the app, then enter code from url in the console. The rake task will output valid ruby code which you can use to create a client.
|
29
|
+
|
30
|
+
## Configuration
|
31
|
+
|
32
|
+
Example:
|
33
|
+
```ruby
|
34
|
+
class Product < ActiveRecord::Base
|
35
|
+
has_attached_file :photo,
|
36
|
+
:storage => :google_drive,
|
37
|
+
:google_drive_credentials => "#{Rails.root}/config/google_drive.yml"
|
38
|
+
end
|
39
|
+
```
|
40
|
+
The `:google_drive_credentials` option
|
41
|
+
|
42
|
+
This can be a hash or path to a YAML file containing the keys listed in the example below. These are obtained from your Google Drive app settings and the authorization Rake task.
|
43
|
+
|
44
|
+
Example `config/google_drive.yml`:
|
45
|
+
```erb
|
46
|
+
client_id: <%= ENV["CLIENT_ID"] %>
|
47
|
+
client_secret: <%= ENV["CLIENT_SECRET"] %>
|
48
|
+
access_token: <%= ENV["ACCESS_TOKEN"] %>
|
49
|
+
refresh_token: <%= ENV["REFRESH_TOKEN"] %>
|
50
|
+
```
|
51
|
+
It is good practice to not include the credentials directly in the YAML file. Instead you can set them in environment variables and embed them with ERB.
|
52
|
+
|
53
|
+
## Options
|
54
|
+
|
55
|
+
The `:google_drive_options` option
|
56
|
+
|
57
|
+
This is a hash containing any of the following options:
|
58
|
+
- `:path` – block, works similarly to Paperclip's `:path` option
|
59
|
+
- `:folder_id`- id of folder that must be created in google drive and set public permessions on it
|
60
|
+
- `:default_image` - an image in Public folder that used for attachemnts if attachement is not present
|
61
|
+
|
62
|
+
The :path option should be a block that returns a path that the uploaded file should be saved to. The block yields the attachment style and is executed in the scope of the model instance. For example:
|
63
|
+
```ruby
|
64
|
+
class Product < ActiveRecord::Base
|
65
|
+
has_attached_file :photo,
|
66
|
+
:storage => :google_drive,
|
67
|
+
:google_drive_credentials => "#{Rails.root}/config/google_drive.yml",
|
68
|
+
:styles => { :medium => "300x300" },
|
69
|
+
:google_drive_options => {
|
70
|
+
:path => proc { |style| "#{style}_#{id}_#{photo.original_filename}" }
|
71
|
+
}
|
72
|
+
end
|
73
|
+
```
|
74
|
+
For example, a new product is created with the ID of 14, and a some_photo.jpg as its photo. The following files would be saved to the Google Drive:
|
75
|
+
|
76
|
+
Public/14_some_photo.jpg
|
77
|
+
Public/14_some_photo_medium.jpg
|
78
|
+
|
79
|
+
The another file is called some_photo_medium.jpg because style names (other than original) will always be appended to the filenames, for better management.
|
80
|
+
|
81
|
+
## Misc
|
82
|
+
|
83
|
+
Useful links
|
84
|
+
[Google APIs console](https://code.google.com/apis/console/)
|
85
|
+
|
86
|
+
[Google Drive scopes](https://developers.google.com/drive/scopes)
|
87
|
+
|
88
|
+
[Enable the Drive API and SDK](https://developers.google.com/drive/enable-sdk)
|
89
|
+
|
90
|
+
[Quickstart](https://developers.google.com/drive/quickstart-ruby#step_1_enable_the_drive_api)
|
21
91
|
|
22
|
-
|
92
|
+
## License
|
23
93
|
|
24
|
-
|
25
|
-
has_attach_file method and descript name of attachemnt, set storage to google drive and set credentials and options.
|
94
|
+
[MIT License](https://github.com/evinsou/paperclip-googledrive/blob/master/LICENSE)
|
26
95
|
|
27
96
|
## Contributing
|
28
97
|
|
@@ -31,3 +100,6 @@ has_attach_file method and descript name of attachemnt, set storage to google dr
|
|
31
100
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
32
101
|
4. Push to the branch (`git push origin my-new-feature`)
|
33
102
|
5. Create new Pull Request
|
103
|
+
=======
|
104
|
+
paperclip-googledrive
|
105
|
+
=====================
|
data/lib/paperclip/version.rb
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
|
|
11
11
|
|
12
12
|
gem.summary = %q{Extends Paperclip with Google Drive storage}
|
13
13
|
gem.description = %q{paperclip-googledrive extends paperclip support of storage for google drive storage}
|
14
|
-
gem.homepage = ""
|
14
|
+
gem.homepage = "https://github.com/evinsou/paperclip-googledrive"
|
15
15
|
|
16
16
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
17
|
gem.files = Dir["lib/**/*"] + ["README.md", "LICENSE", "paperclip-googledrive.gemspec"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip-googledrive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -77,7 +77,7 @@ files:
|
|
77
77
|
- README.md
|
78
78
|
- LICENSE
|
79
79
|
- paperclip-googledrive.gemspec
|
80
|
-
homepage:
|
80
|
+
homepage: https://github.com/evinsou/paperclip-googledrive
|
81
81
|
licenses:
|
82
82
|
- MIT
|
83
83
|
post_install_message:
|