From 10a337b807953521ce3c1b389ebc21be7eeef47e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volker=20Z=C3=B6pfel?= Date: Thu, 14 Nov 2013 08:31:21 +0100 Subject: [PATCH] adds method path= to proof if file can be accessed --- lib/google/api_client/auth/file_storage.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/google/api_client/auth/file_storage.rb b/lib/google/api_client/auth/file_storage.rb index 716f109d3..d19927ab6 100644 --- a/lib/google/api_client/auth/file_storage.rb +++ b/lib/google/api_client/auth/file_storage.rb @@ -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