Class: Google::APIClient::FileStore

Inherits:
Object
  • Object
show all
Defined in:
lib/google/api_client/auth/storages/file_store.rb

Overview

Represents cached OAuth 2 tokens stored on local disk in a JSON serialized file. Meant to resemble the serialized format google-api-python-client.googlecode.com/hg/docs/epy/oauth2client.file.Storage-class.html

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FileStore

Initializes the FileStorage object.

Parameters:

  • path (String)

    Path to the credentials file.



33
34
35
# File 'lib/google/api_client/auth/storages/file_store.rb', line 33

def initialize(path)
  @path= path
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



26
27
28
# File 'lib/google/api_client/auth/storages/file_store.rb', line 26

def path
  @path
end

Instance Method Details

#load_credentialsObject

Attempt to read in credentials from the specified file.



39
40
41
42
43
# File 'lib/google/api_client/auth/storages/file_store.rb', line 39

def load_credentials
  open(path, 'r') { |f| JSON.parse(f.read) }
rescue
  nil
end

#write_credentials(credentials_hash) ⇒ Object

Write the credentials to the specified file.

Parameters:

  • authorization (Signet::OAuth2::Client)

    Optional authorization instance. If not provided, the authorization already associated with this instance will be written.



51
52
53
54
55
# File 'lib/google/api_client/auth/storages/file_store.rb', line 51

def write_credentials(credentials_hash)
  open(self.path, 'w+') do |f|
    f.write(credentials_hash.to_json)
  end
end