gdrivestrg 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gdrivestrg/gdrivestrg.rb +61 -34
- data/lib/gdrivestrg/gdrivestrg.rb~ +64 -34
- data/lib/gdrivestrg/version.rb +1 -1
- data/lib/gdrivestrg/version.rb~ +3 -0
- metadata +5 -4
@@ -6,6 +6,7 @@ class GdriveStrg < CloudStrg::CloudStorage
|
|
6
6
|
CLIENT_ID = "867108581948.apps.googleusercontent.com"
|
7
7
|
CLIENT_SECRET = "Z3TXaBvx36ex8RRD-Wu-3PGK"
|
8
8
|
SCOPES = [
|
9
|
+
'https://www.googleapis.com/auth/drive',
|
9
10
|
'https://www.googleapis.com/auth/drive.file', # we will only see the files createdby this app
|
10
11
|
'https://www.googleapis.com/auth/userinfo.email',
|
11
12
|
'https://www.googleapis.com/auth/userinfo.profile'
|
@@ -32,25 +33,10 @@ class GdriveStrg < CloudStrg::CloudStorage
|
|
32
33
|
end
|
33
34
|
|
34
35
|
session = params[:session]
|
35
|
-
|
36
|
-
@client.authorization.update_token!(:access_token => session[:gdrive_access_token] , #:access_token => user_params.access_token,
|
37
|
-
:refresh_token => user_params.refresh_token,
|
38
|
-
:expires_in => user_params.expires_in,
|
39
|
-
:issued_at => user_params.issued_at)
|
40
|
-
if @client.authorization.refresh_token && @client.authorization.expired?
|
41
|
-
@client.authorization.fetch_access_token!
|
42
|
-
session[:gdrive_access_token] = @client.authorization.access_token
|
43
|
-
# user.gdrive_access_token = @client.authorization.access_token
|
44
|
-
user_params.refresh_token = @client.authorization.refresh_token
|
45
|
-
user_params.expires_in = @client.authorization.expires_in
|
46
|
-
user_params.issued_at = @client.authorization.issued_at
|
47
|
-
user_params.save()
|
48
|
-
end
|
49
|
-
|
50
36
|
|
51
37
|
if params[:code]
|
52
38
|
authorize_code(params[:code])
|
53
|
-
|
39
|
+
|
54
40
|
session[:gdrive_access_token] = @client.authorization.access_token
|
55
41
|
# user.gdrive_access_token = @client.authorization.access_token
|
56
42
|
user_params.refresh_token = @client.authorization.refresh_token
|
@@ -59,24 +45,39 @@ class GdriveStrg < CloudStrg::CloudStorage
|
|
59
45
|
user_params.save()
|
60
46
|
elsif params[:error] # User denied the oauth grant
|
61
47
|
puts "Denied: #{params[:error]}"
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
@client.
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
48
|
+
else
|
49
|
+
if params[:refresh_token] and params[:access_token] and params[:expires_in]
|
50
|
+
session[:gdrive_access_token] = params[:access_token]
|
51
|
+
# user.gdrive_access_token = @client.authorization.access_token
|
52
|
+
user_params.refresh_token = params[:refresh_token]
|
53
|
+
user_params.expires_in = params[:expires_in]
|
54
|
+
user_params.save()
|
55
|
+
user_params.issued_at = user_params.updated_at
|
56
|
+
user_params.save()
|
57
|
+
end
|
58
|
+
@client.authorization.update_token!(:access_token => session[:gdrive_access_token] , #:access_token => user_params.access_token,
|
59
|
+
:refresh_token => user_params.refresh_token,
|
60
|
+
:expires_in => user_params.expires_in,
|
61
|
+
:issued_at => user_params.issued_at)
|
62
|
+
if @client.authorization.refresh_token && @client.authorization.expired?
|
63
|
+
session = requestAccessToken(session, user_params)
|
64
|
+
else
|
65
|
+
if not authorized?
|
66
|
+
if @client.authorization.refresh_token
|
67
|
+
session = requestAccessToken(session, user_params)
|
68
|
+
else
|
69
|
+
session[:plugin_name] = self.class.to_s.split('Strg')[0].downcase
|
70
|
+
return session, auth_url
|
71
|
+
end
|
72
|
+
else
|
73
|
+
begin
|
74
|
+
@client.execute!(:api_method => @auth_api.userinfo.get)
|
75
|
+
rescue Exception => e
|
76
|
+
session.delete(:gdrive_access_token)
|
77
|
+
session = requestAccessToken(session, user_params)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
80
81
|
end
|
81
82
|
return session, false
|
82
83
|
end
|
@@ -141,6 +142,21 @@ class GdriveStrg < CloudStrg::CloudStorage
|
|
141
142
|
return lines
|
142
143
|
end
|
143
144
|
|
145
|
+
def share_file params
|
146
|
+
new_permission = @drive_api.permissions.insert.request_schema.new({'value' => params[:share_email], 'type' => 'user', 'role' => 'writer'})
|
147
|
+
result = @client.execute!(
|
148
|
+
:api_method => @drive_api.permissions.insert,
|
149
|
+
:body_object => new_permission,
|
150
|
+
:parameters => { 'fileId' => params[:file_id] })
|
151
|
+
if result.status == 200
|
152
|
+
return result.data[:id]
|
153
|
+
else
|
154
|
+
puts "An error occurred: #{result.data['error']['message']}"
|
155
|
+
return nil
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
144
160
|
def check_referer referer
|
145
161
|
if not referer
|
146
162
|
return false
|
@@ -162,4 +178,15 @@ class GdriveStrg < CloudStrg::CloudStorage
|
|
162
178
|
def auth_url(state = '')
|
163
179
|
return @client.authorization.authorization_uri().to_s
|
164
180
|
end
|
181
|
+
|
182
|
+
def requestAccessToken(session, user_params)
|
183
|
+
@client.authorization.fetch_access_token!
|
184
|
+
session[:gdrive_access_token] = @client.authorization.access_token
|
185
|
+
# user.gdrive_access_token = @client.authorization.access_token
|
186
|
+
user_params.refresh_token = @client.authorization.refresh_token
|
187
|
+
user_params.expires_in = @client.authorization.expires_in
|
188
|
+
user_params.issued_at = @client.authorization.issued_at
|
189
|
+
user_params.save()
|
190
|
+
return session
|
191
|
+
end
|
165
192
|
end
|
@@ -6,6 +6,7 @@ class GdriveStrg < CloudStrg::CloudStorage
|
|
6
6
|
CLIENT_ID = "867108581948.apps.googleusercontent.com"
|
7
7
|
CLIENT_SECRET = "Z3TXaBvx36ex8RRD-Wu-3PGK"
|
8
8
|
SCOPES = [
|
9
|
+
'https://www.googleapis.com/auth/drive',
|
9
10
|
'https://www.googleapis.com/auth/drive.file', # we will only see the files createdby this app
|
10
11
|
'https://www.googleapis.com/auth/userinfo.email',
|
11
12
|
'https://www.googleapis.com/auth/userinfo.profile'
|
@@ -32,25 +33,10 @@ class GdriveStrg < CloudStrg::CloudStorage
|
|
32
33
|
end
|
33
34
|
|
34
35
|
session = params[:session]
|
35
|
-
|
36
|
-
@client.authorization.update_token!(:access_token => session[:gdrive_access_token] , #:access_token => user_params.access_token,
|
37
|
-
:refresh_token => user_params.refresh_token,
|
38
|
-
:expires_in => user_params.expires_in,
|
39
|
-
:issued_at => user_params.issued_at)
|
40
|
-
if @client.authorization.refresh_token && @client.authorization.expired?
|
41
|
-
@client.authorization.fetch_access_token!
|
42
|
-
session[:gdrive_access_token] = @client.authorization.access_token
|
43
|
-
# user.gdrive_access_token = @client.authorization.access_token
|
44
|
-
user_params.refresh_token = @client.authorization.refresh_token
|
45
|
-
user_params.expires_in = @client.authorization.expires_in
|
46
|
-
user_params.issued_at = @client.authorization.issued_at
|
47
|
-
user_params.save()
|
48
|
-
end
|
49
|
-
|
50
36
|
|
51
37
|
if params[:code]
|
52
38
|
authorize_code(params[:code])
|
53
|
-
|
39
|
+
|
54
40
|
session[:gdrive_access_token] = @client.authorization.access_token
|
55
41
|
# user.gdrive_access_token = @client.authorization.access_token
|
56
42
|
user_params.refresh_token = @client.authorization.refresh_token
|
@@ -59,24 +45,39 @@ class GdriveStrg < CloudStrg::CloudStorage
|
|
59
45
|
user_params.save()
|
60
46
|
elsif params[:error] # User denied the oauth grant
|
61
47
|
puts "Denied: #{params[:error]}"
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
@client.
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
48
|
+
else
|
49
|
+
if params[:refresh_token] and params[:access_token] and params[:expires_in]
|
50
|
+
session[:gdrive_access_token] = params[:access_token]
|
51
|
+
# user.gdrive_access_token = @client.authorization.access_token
|
52
|
+
user_params.refresh_token = params[:refresh_token]
|
53
|
+
user_params.expires_in = params[:expires_in]
|
54
|
+
user_params.save()
|
55
|
+
user_params.issued_at = user_params.updated_at
|
56
|
+
user_params.save()
|
57
|
+
end
|
58
|
+
@client.authorization.update_token!(:access_token => session[:gdrive_access_token] , #:access_token => user_params.access_token,
|
59
|
+
:refresh_token => user_params.refresh_token,
|
60
|
+
:expires_in => user_params.expires_in,
|
61
|
+
:issued_at => user_params.issued_at)
|
62
|
+
if @client.authorization.refresh_token && @client.authorization.expired?
|
63
|
+
session = requestAccessToken(session, user_params)
|
64
|
+
else
|
65
|
+
if not authorized?
|
66
|
+
if @client.authorization.refresh_token
|
67
|
+
session = requestAccessToken(session, user_params)
|
68
|
+
else
|
69
|
+
session[:plugin_name] = self.class.to_s.split('Strg')[0].downcase
|
70
|
+
return session, auth_url
|
71
|
+
end
|
72
|
+
else
|
73
|
+
begin
|
74
|
+
@client.execute!(:api_method => @auth_api.userinfo.get)
|
75
|
+
rescue Exception => e
|
76
|
+
session.delete(:gdrive_access_token)
|
77
|
+
session = requestAccessToken(session, user_params)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
80
81
|
end
|
81
82
|
return session, false
|
82
83
|
end
|
@@ -141,7 +142,25 @@ class GdriveStrg < CloudStrg::CloudStorage
|
|
141
142
|
return lines
|
142
143
|
end
|
143
144
|
|
145
|
+
def share_file params
|
146
|
+
new_permission = @drive_api.permissions.insert.request_schema.new({'value' => params[:share_email], 'type' => 'user', 'role' => 'writer'})
|
147
|
+
result = @client.execute!(
|
148
|
+
:api_method => @drive_api.permissions.insert,
|
149
|
+
:body_object => new_permission,
|
150
|
+
:parameters => { 'fileId' => params[:file_id] })
|
151
|
+
if result.status == 200
|
152
|
+
return result.data[:id]
|
153
|
+
else
|
154
|
+
puts "An error occurred: #{result.data['error']['message']}"
|
155
|
+
return false
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
144
160
|
def check_referer referer
|
161
|
+
if not referer
|
162
|
+
return false
|
163
|
+
end
|
145
164
|
return referer.include? "accounts.google.com"
|
146
165
|
end
|
147
166
|
|
@@ -159,4 +178,15 @@ class GdriveStrg < CloudStrg::CloudStorage
|
|
159
178
|
def auth_url(state = '')
|
160
179
|
return @client.authorization.authorization_uri().to_s
|
161
180
|
end
|
181
|
+
|
182
|
+
def requestAccessToken(session, user_params)
|
183
|
+
@client.authorization.fetch_access_token!
|
184
|
+
session[:gdrive_access_token] = @client.authorization.access_token
|
185
|
+
# user.gdrive_access_token = @client.authorization.access_token
|
186
|
+
user_params.refresh_token = @client.authorization.refresh_token
|
187
|
+
user_params.expires_in = @client.authorization.expires_in
|
188
|
+
user_params.issued_at = @client.authorization.issued_at
|
189
|
+
user_params.save()
|
190
|
+
return session
|
191
|
+
end
|
162
192
|
end
|
data/lib/gdrivestrg/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gdrivestrg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
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:
|
12
|
+
date: 2013-03-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0.0.
|
37
|
+
version: 0.0.10
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.0.
|
45
|
+
version: 0.0.10
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: google-api-client
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,6 +107,7 @@ files:
|
|
107
107
|
- lib/tasks/gdrivestrg_tasks.rake
|
108
108
|
- lib/gdrivestrg.rb~
|
109
109
|
- lib/gdrivestrg/version.rb
|
110
|
+
- lib/gdrivestrg/version.rb~
|
110
111
|
- lib/gdrivestrg/engine.rb
|
111
112
|
- lib/gdrivestrg/gdrivestrg.rb~
|
112
113
|
- lib/gdrivestrg/gdrivestrg.rb
|