@@ -38,7 +38,6 @@ class Storage
38
38
# @params [Object] Storage object
39
39
def initialize ( store )
40
40
@store = store
41
- self . authorize
42
41
end
43
42
44
43
##
@@ -58,18 +57,20 @@ def write_credentials(authorization=nil)
58
57
# Loads credentials and authorizes an client.
59
58
# @return [Object] Signet::OAuth2::Client or NIL
60
59
def authorize
61
- if load_credentials
62
- cached_credentials = load_credentials
60
+ @authorization = false
61
+ cached_credentials = load_credentials
62
+ if cached_credentials && cached_credentials . size > 0
63
63
@authorization = Signet ::OAuth2 ::Client . new ( cached_credentials )
64
64
@authorization . issued_at = Time . at ( cached_credentials [ 'issued_at' ] . to_i )
65
65
self . refresh_authorization if @authorization . expired?
66
66
end
67
+ return @authorization
67
68
end
68
69
69
70
##
70
71
# refresh credentials and save them to store
71
72
def refresh_authorization
72
- @ authorization. refresh!
73
+ authorization . refresh!
73
74
self . write_credentials
74
75
end
75
76
@@ -85,14 +86,14 @@ def load_credentials
85
86
# @return [Hash] with credentials
86
87
def credentials_hash
87
88
{
88
- :access_token => @ authorization. access_token ,
89
+ :access_token => authorization . access_token ,
89
90
:authorization_uri => AUTHORIZATION_URI ,
90
- :client_id => @ authorization. client_id ,
91
- :client_secret => @ authorization. client_secret ,
92
- :expires_in => @ authorization. expires_in ,
93
- :refresh_token => @ authorization. refresh_token ,
91
+ :client_id => authorization . client_id ,
92
+ :client_secret => authorization . client_secret ,
93
+ :expires_in => authorization . expires_in ,
94
+ :refresh_token => authorization . refresh_token ,
94
95
:token_credential_uri => TOKEN_CREDENTIAL_URI ,
95
- :issued_at => @ authorization. issued_at . to_i
96
+ :issued_at => authorization . issued_at . to_i
96
97
}
97
98
end
98
99
end
0 commit comments