Skip to content

Commit 5c61e39

Browse files
committed
use authorization method instead of variable
remove authorize from initialize
1 parent 05baf20 commit 5c61e39

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

lib/google/api_client/auth/storage.rb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class Storage
3838
# @params [Object] Storage object
3939
def initialize(store)
4040
@store= store
41-
self.authorize
4241
end
4342

4443
##
@@ -58,18 +57,20 @@ def write_credentials(authorization=nil)
5857
# Loads credentials and authorizes an client.
5958
# @return [Object] Signet::OAuth2::Client or NIL
6059
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
6363
@authorization = Signet::OAuth2::Client.new(cached_credentials)
6464
@authorization.issued_at = Time.at(cached_credentials['issued_at'].to_i)
6565
self.refresh_authorization if @authorization.expired?
6666
end
67+
return @authorization
6768
end
6869

6970
##
7071
# refresh credentials and save them to store
7172
def refresh_authorization
72-
@authorization.refresh!
73+
authorization.refresh!
7374
self.write_credentials
7475
end
7576

@@ -85,14 +86,14 @@ def load_credentials
8586
# @return [Hash] with credentials
8687
def credentials_hash
8788
{
88-
:access_token => @authorization.access_token,
89+
:access_token => authorization.access_token,
8990
: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,
9495
:token_credential_uri => TOKEN_CREDENTIAL_URI,
95-
:issued_at => @authorization.issued_at.to_i
96+
:issued_at => authorization.issued_at.to_i
9697
}
9798
end
9899
end

0 commit comments

Comments
 (0)