Class: SheetsV4::CreateCredential

Inherits:
Object
  • Object
show all
Defined in:
lib/sheets_v4/create_credential.rb

Overview

Creates a Google API credential with an access token

Class Method Summary collapse

Class Method Details

.call(credential_source, scopes, credential_factory = Google::Auth::DefaultCredentials) ⇒ Object

Creates a Google API credential with an access token

This wraps the boiler plate code into one function to make constructing a credential easy and less error prone.

Examples:

Constructing a credential from the contents of ~/.credential

credential_source = File.read(File.join(Dir.home, '.credential'))
scope = Google::Apis::SheetsV4::AUTH_SPREADSHEETS
credential = SheetsV4::CreateCredential.call(credential_source, scope)


28
29
30
31
32
33
34
35
36
# File 'lib/sheets_v4/create_credential.rb', line 28

def self.call(
  credential_source, scopes, credential_factory = Google::Auth::DefaultCredentials
)
  return credential_source if credential?(credential_source)

  credential_source ||= default_credential_source
  options = make_creds_options(credential_source, scopes)
  credential_factory.make_creds(options).tap(&:fetch_access_token)
end