Make the scope optional

This commit is contained in:
Tim Emiola committed 2015-03-17 16:46:55 -07:00
1 parent 7a9dea37f1
commit bd97c23d9f
7 files changed
+31 -19

No files matched your search

+6 -6
View File
@@ -61,13 +61,13 @@ module Google
# Creates an instance from the path specified in an environment
# variable.
#
# @param scope [string|array] the scope(s) to access
def from_env(scope)
# @param scope [string|array|nil] the scope(s) to access
def from_env(scope = nil)
return nil unless ENV.key?(ENV_VAR)
path = ENV[ENV_VAR]
fail 'file #{path} does not exist' unless File.exist?(path)
File.open(path) do |f|
return make_creds(scope, f)
return make_creds(f, scope)
end
rescue StandardError => e
raise "#{NOT_FOUND_ERROR}: #{e}"
@@ -75,15 +75,15 @@ module Google
# Creates an instance from a well known path.
#
# @param scope [string|array] the scope(s) to access
def from_well_known_path(scope)
# @param scope [string|array|nil] the scope(s) to access
def from_well_known_path(scope = nil)
home_var, base = windows? ? 'APPDATA' : 'HOME', WELL_KNOWN_PATH
root = ENV[home_var].nil? ? '' : ENV[home_var]
base = File.join('.config', base) unless windows?
path = File.join(root, base)
return nil unless File.exist?(path)
File.open(path) do |f|
return make_creds(scope, f)
return make_creds(f, scope)
end
rescue StandardError => e
raise "#{WELL_KNOWN_ERROR}: #{e}"
+2 -2
View File
@@ -57,9 +57,9 @@ module Google
# Initializes a ServiceAccountCredentials.
#
# @param scope [string|array] the scope(s) to access
# @param json_key_io [IO] an IO from which the JSON key can be read
def initialize(scope, json_key_io)
# @param scope [string|array|nil] the scope(s) to access
def initialize(json_key_io, scope = nil)
private_key, client_email = self.class.read_json_key(json_key_io)
super(token_credential_uri: TOKEN_CRED_URI,
audience: TOKEN_CRED_URI,
+2 -2
View File
@@ -61,9 +61,9 @@ module Google
# Initializes a UserRefreshCredentials.
#
# @param scope [string|array] the scope(s) to access
# @param json_key_io [IO] an IO from which the JSON key can be read
def initialize(scope, json_key_io)
# @param scope [string|array|nil] the scope(s) to access
def initialize(json_key_io, scope = nil)
user_creds = self.class.read_json_key(json_key_io)
super(token_credential_uri: TOKEN_CRED_URI,
client_id: user_creds['client_id'],