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 CHANGED
@@ -1,5 +1,4 @@
1
-
2
- # PaperclipGoogledrive
1
+ # PaperclipGoogledrive [![Code Climate](https://codeclimate.com/badge.png)](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
- 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
- puts 'Enter redirect URI:'
17
- redirect_uri = $stdin.gets.chomp.strip
18
-
19
- # Create a new API client & load the Google Drive API
20
- client = Google::APIClient.new
21
- drive = client.discovered_api('drive', 'v2')
22
-
23
- client.authorization.client_id = client_id
24
- client.authorization.client_secret = client_secret
25
- client.authorization.scope = oauth_scope
26
- client.authorization.redirect_uri = redirect_uri
27
-
28
- # Request authorization
29
- uri = client.authorization.authorization_uri.to_s
30
- puts "\nGo to this url:"
31
- puts client.authorization.authorization_uri.to_s
32
- puts "\n Accept the authorization request from Google in your browser"
33
-
34
- 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"
35
-
36
- code = $stdin.gets.chomp.strip
37
- client.authorization.code = code
38
- client.authorization.fetch_access_token!
39
-
40
- puts "\nAuthorization complete!:\n\n"
41
- puts "client = Google::APIClient.new"
42
- puts "client.authorization.client_id = '#{client_id}'"
43
- puts "client.authorization.client_secret = '#{client_secret}'"
44
- puts "client.authorization.access_token = '#{client.authorization.access_token}'"
45
- puts "client.authorization.refresh_token = '#{client.authorization.refresh_token}'"
46
- puts "\n"
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
- oauth2 = client.discovered_api('oauth2', 'v2')
53
- result = client.execute!(:api_method => oauth2.userinfo.get)
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
@@ -1,3 +1,3 @@
1
1
  module PaperclipGoogleDrive
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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.2
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-01-30 00:00:00.000000000 Z
12
+ date: 2013-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: paperclip