adds method path= to proof if file can be accessed
This commit is contained in:
parent
146ccad83a
commit
10a337b807
|
@ -24,7 +24,7 @@ module Google
|
|||
#
|
||||
class FileStorage
|
||||
# @return [String] Path to the credentials file.
|
||||
attr_accessor :path
|
||||
attr_reader :path
|
||||
|
||||
# @return [Signet::OAuth2::Client] Path to the credentials file.
|
||||
attr_reader :authorization
|
||||
|
@ -41,17 +41,18 @@ module Google
|
|||
|
||||
##
|
||||
# Attempt to read in credentials from the specified file.
|
||||
# TODO: add methods to:
|
||||
# check if file exists
|
||||
# check if file is writeable
|
||||
# check json structure is valid
|
||||
def load_credentials
|
||||
cached_credentials = JSON.load(self.path)
|
||||
cached_credentials = JSON.load(path)
|
||||
@authorization = Signet::OAuth2::Client.new(cached_credentials)
|
||||
@authorization.issued_at = Time.at(cached_credentials['issued_at'])
|
||||
self.refresh_authorization if @authorization.expired?
|
||||
end
|
||||
|
||||
def path=(value)
|
||||
@path=value
|
||||
raise "Credentials on path #{path} not accessible" unless File.exists?(@path) && File.readable?(@path) && File.writable?(@path)
|
||||
end
|
||||
|
||||
##
|
||||
# refresh credentials and save them to file
|
||||
def refresh_authorization
|
||||
|
|
Loading…
Reference in New Issue