paperclip-googledrive 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +1 -5
- data/lib/paperclip/google_drive/rake.rb +38 -37
- data/lib/paperclip/storage/google_drive.rb +8 -6
- data/lib/paperclip/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
# PaperclipGoogledrive
|
|
1
|
+
# PaperclipGoogledrive [](https://codeclimate.com/github/evinsou/paperclip-googledrive)
|
|
3
2
|
|
|
4
3
|
PaperclipGoogledrive is a gem that extends paperclip storage for Google Drive. Works with Rails 3.x.
|
|
5
4
|
|
|
@@ -100,6 +99,3 @@ Useful links
|
|
|
100
99
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
|
101
100
|
4. Push to the branch (`git push origin my-new-feature`)
|
|
102
101
|
5. Create new Pull Request
|
|
103
|
-
=======
|
|
104
|
-
paperclip-googledrive
|
|
105
|
-
=====================
|
|
@@ -7,43 +7,44 @@ module Paperclip
|
|
|
7
7
|
extend self
|
|
8
8
|
|
|
9
9
|
def authorize
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
10
|
+
puts 'Enter client ID:'
|
|
11
|
+
client_id = $stdin.gets.chomp
|
|
12
|
+
puts 'Enter client SECRET:'
|
|
13
|
+
client_secret = $stdin.gets.chomp.strip
|
|
14
|
+
# puts 'Enter SCOPE:'
|
|
15
|
+
# oauth_scope = $stdin.gets.chomp.strip
|
|
16
|
+
oauth_scope = ['https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/userinfo.profile']
|
|
17
|
+
puts 'Enter redirect URI:'
|
|
18
|
+
redirect_uri = $stdin.gets.chomp.strip
|
|
19
|
+
|
|
20
|
+
# Create a new API client & load the Google Drive API
|
|
21
|
+
client = Google::APIClient.new(:application_name => 'ppc-gd', :application_version => PaperclipGoogleDrive::VERSION)
|
|
22
|
+
drive = client.discovered_api('drive', 'v2')
|
|
23
|
+
|
|
24
|
+
client.authorization.client_id = client_id
|
|
25
|
+
client.authorization.client_secret = client_secret
|
|
26
|
+
client.authorization.scope = oauth_scope
|
|
27
|
+
client.authorization.redirect_uri = redirect_uri
|
|
28
|
+
|
|
29
|
+
# Request authorization
|
|
30
|
+
uri = client.authorization.authorization_uri.to_s
|
|
31
|
+
puts "\nGo to this url:"
|
|
32
|
+
puts client.authorization.authorization_uri.to_s
|
|
33
|
+
puts "\n Accept the authorization request from Google in your browser"
|
|
34
|
+
|
|
35
|
+
puts "\n\n\n Google will redirect you to localhost, but just copy the code parameter out of the URL they redirect you to, paste it here and hit enter:\n"
|
|
36
|
+
|
|
37
|
+
code = $stdin.gets.chomp.strip
|
|
38
|
+
client.authorization.code = code
|
|
39
|
+
client.authorization.fetch_access_token!
|
|
40
|
+
|
|
41
|
+
puts "\nAuthorization completed.\n\n"
|
|
42
|
+
puts "client = Google::APIClient.new"
|
|
43
|
+
puts "client.authorization.client_id = '#{client_id}'"
|
|
44
|
+
puts "client.authorization.client_secret = '#{client_secret}'"
|
|
45
|
+
puts "client.authorization.access_token = '#{client.authorization.access_token}'"
|
|
46
|
+
puts "client.authorization.refresh_token = '#{client.authorization.refresh_token}'"
|
|
47
|
+
puts "\n"
|
|
47
48
|
end
|
|
48
49
|
end
|
|
49
50
|
end
|
|
@@ -49,8 +49,10 @@ module Paperclip
|
|
|
49
49
|
#upload(style, file) #style file
|
|
50
50
|
client = google_api_client
|
|
51
51
|
drive = client.discovered_api('drive', 'v2')
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
result = client.execute(
|
|
53
|
+
:api_method => drive.files.get,
|
|
54
|
+
:parameters => { 'fileId' => @google_drive_options[:public_folder_id],
|
|
55
|
+
'fields' => ' id, title' })
|
|
54
56
|
client.authorization.access_token = result.request.authorization.access_token
|
|
55
57
|
client.authorization.refresh_token = result.request.authorization.refresh_token
|
|
56
58
|
title, mime_type = title_for_file(style), "#{content_type}"
|
|
@@ -101,7 +103,8 @@ module Paperclip
|
|
|
101
103
|
@google_api_client ||= begin
|
|
102
104
|
assert_required_keys
|
|
103
105
|
# Initialize the client & Google+ API
|
|
104
|
-
client = Google::APIClient.new
|
|
106
|
+
client = Google::APIClient.new(:application_name => 'ppc-gd', :application_version => PaperclipGoogleDrive::VERSION)
|
|
107
|
+
# client = Google::APIClient.new(:application_name => @google_drive_credentials[:application_name], :application_version => @google_drive_credentials[:application_version])
|
|
105
108
|
client.authorization.client_id = @google_drive_credentials[:client_id]
|
|
106
109
|
client.authorization.client_secret = @google_drive_credentials[:client_secret]
|
|
107
110
|
client.authorization.access_token = @google_drive_credentials[:access_token]
|
|
@@ -132,9 +135,7 @@ module Paperclip
|
|
|
132
135
|
|
|
133
136
|
def title_for_file(style)
|
|
134
137
|
file_name = instance.instance_exec(style, &file_title)
|
|
135
|
-
|
|
136
138
|
style_suffix = (style != default_style ? "_#{style}" : "")
|
|
137
|
-
|
|
138
139
|
if original_extension.present? && file_name =~ /#{original_extension}$/
|
|
139
140
|
file_name.sub(original_extension, "#{style_suffix}#{original_extension}")
|
|
140
141
|
else
|
|
@@ -186,7 +187,8 @@ module Paperclip
|
|
|
186
187
|
end
|
|
187
188
|
end
|
|
188
189
|
|
|
189
|
-
def exists?(style)
|
|
190
|
+
def exists?(style = default_style)
|
|
191
|
+
return false if not present?
|
|
190
192
|
result_id = search_for_title(path(style))
|
|
191
193
|
if result_id.nil?
|
|
192
194
|
false
|
data/lib/paperclip/version.rb
CHANGED
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.1.
|
|
4
|
+
version: 0.1.3
|
|
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: 2013-
|
|
12
|
+
date: 2013-09-12 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: paperclip
|