Class: Google::APIClient::FileStore
- Inherits:
-
Object
- Object
- Google::APIClient::FileStore
- 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
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path) ⇒ FileStore
constructor
Initializes the FileStorage object.
-
#load_credentials ⇒ Object
Attempt to read in credentials from the specified file.
-
#write_credentials(credentials_hash) ⇒ Object
Write the credentials to the specified file.
Constructor Details
#initialize(path) ⇒ FileStore
Initializes the FileStorage object.
33 34 35 |
# File 'lib/google/api_client/auth/storages/file_store.rb', line 33 def initialize(path) @path= path end |
Instance Attribute Details
#path ⇒ Object
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_credentials ⇒ Object
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.
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 |