lionel_richie 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lionel.rb +1 -1
- data/lib/lionel/cli.rb +1 -1
- data/lib/lionel/export.rb +1 -1
- data/lib/lionel/google_authentication.rb +39 -20
- data/lib/lionel/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f27fcc463388c7304b7ad1962c6e1a9410395eb8
|
4
|
+
data.tar.gz: 8bc504b7f0f628f7c9929b81e5e10b2f44cf67c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b82b9e20b78ee845efcf62b2e95ebdbe779c1ff410f8cd74bc4e5275cdc06d1b6bc624b47a8890dbb8b6c5afe48ba87ec43c42fad6e565132f17730b93cf3462
|
7
|
+
data.tar.gz: 484b84c4d2f7756afa9ca66819a7b62fea7365d49f4ca87ea0a401fa441c61d5c8c507d910be137ae1fb786019af4746e69d8593a87831f29785f894d3febe4d
|
data/lib/lionel.rb
CHANGED
data/lib/lionel/cli.rb
CHANGED
@@ -66,7 +66,7 @@ module Lionel
|
|
66
66
|
|
67
67
|
begin
|
68
68
|
export.authenticate
|
69
|
-
rescue
|
69
|
+
rescue GoogleDrive::Error, GoogleDrive::AuthenticationError
|
70
70
|
@google_attempts ||= 0
|
71
71
|
@google_attempts += 1
|
72
72
|
Lionel::GoogleAuthentication.new.refresh
|
data/lib/lionel/export.rb
CHANGED
@@ -1,56 +1,75 @@
|
|
1
|
+
require "google/api_client"
|
2
|
+
|
1
3
|
module Lionel
|
2
4
|
class GoogleAuthentication
|
3
5
|
include Configurable
|
4
6
|
|
5
|
-
attr_accessor :access_token
|
7
|
+
attr_accessor :access_token, :refresh_token
|
6
8
|
attr_writer :client
|
7
9
|
config_accessor :google_client_id, :google_client_secret
|
8
10
|
|
9
11
|
def data
|
10
12
|
raise "No access token" unless access_token
|
11
13
|
{
|
12
|
-
google_token: access_token
|
13
|
-
google_refresh_token:
|
14
|
+
google_token: access_token,
|
15
|
+
google_refresh_token: refresh_token,
|
14
16
|
google_client_id: google_client_id,
|
15
17
|
google_client_secret: google_client_secret
|
16
18
|
}
|
17
19
|
end
|
18
20
|
|
19
21
|
def retrieve_access_token(authorization_code)
|
20
|
-
|
21
|
-
|
22
|
+
authorization.code = authorization_code
|
23
|
+
authorization.fetch_access_token!
|
24
|
+
@access_token = authorization.access_token
|
25
|
+
@refresh_token = authorization.refresh_token
|
22
26
|
end
|
23
27
|
|
24
28
|
def refresh
|
25
|
-
return false unless refresh_token
|
29
|
+
return false unless refresh_token && access_token
|
30
|
+
|
31
|
+
authorization.access_token = access_token
|
32
|
+
authorization.refresh_token = refresh_token
|
33
|
+
authorization.refresh!
|
26
34
|
|
27
|
-
|
28
|
-
:refresh_token => refresh_token,
|
29
|
-
:expires_in => one_year
|
30
|
-
)
|
31
|
-
@access_token = current_token.refresh! # returns new access_token
|
35
|
+
@access_token = authorization.access_token
|
32
36
|
end
|
33
37
|
|
34
38
|
def authorize_url
|
35
|
-
|
36
|
-
:redirect_uri => "urn:ietf:wg:oauth:2.0:oob",
|
37
|
-
:scope => scopes.join(' ')
|
38
|
-
)
|
39
|
+
authorization.authorization_uri
|
39
40
|
end
|
40
41
|
|
41
42
|
def api_console_url
|
42
43
|
"https://code.google.com/apis/console"
|
43
44
|
end
|
44
45
|
|
46
|
+
def authorization
|
47
|
+
@authorization ||= begin
|
48
|
+
auth = client.authorization
|
49
|
+
auth.client_id = google_client_id
|
50
|
+
auth.client_secret = google_client_secret
|
51
|
+
auth.scope = scopes
|
52
|
+
auth.expires_in = one_year
|
53
|
+
auth.redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
|
54
|
+
auth
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
45
58
|
def client
|
46
|
-
@client ||=
|
47
|
-
:site => "https://accounts.google.com",
|
48
|
-
:token_url => "/o/oauth2/token",
|
49
|
-
:authorize_url => "/o/oauth2/auth")
|
59
|
+
@client ||= Google::APIClient.new(auto_refresh_token: true)
|
50
60
|
end
|
51
61
|
|
52
62
|
private
|
53
63
|
|
64
|
+
def build_client
|
65
|
+
auth = client.authorization
|
66
|
+
auth.client_id = google_client_id
|
67
|
+
auth.client_secret = google_client_secret
|
68
|
+
auth.scope = scopes
|
69
|
+
auth.redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
|
70
|
+
client
|
71
|
+
end
|
72
|
+
|
54
73
|
def refresh_token
|
55
74
|
@refresh_token || configuration.google_refresh_token
|
56
75
|
end
|
@@ -64,7 +83,7 @@ module Lionel
|
|
64
83
|
end
|
65
84
|
|
66
85
|
def one_year # in seconds
|
67
|
-
|
86
|
+
60*60*24*36
|
68
87
|
end
|
69
88
|
|
70
89
|
end
|
data/lib/lionel/version.rb
CHANGED