Class: GAAPI::AccessToken
- Inherits:
-
Object
- Object
- GAAPI::AccessToken
- Defined in:
- lib/gaapi/access_token.rb
Overview
An access token generated from a credential file provided by Google Analystics. The credential file is suitable for using in applications where humans aren’t involved, such as scheduled jobs. To obtain a credential file, follow the instructions at developers.google.com/identity/protocols/OAuth2ServiceAccount.
Instance Method Summary collapse
-
#initialize(credential_file = nil) ⇒ AccessToken
constructor
Get a new access token.
-
#token ⇒ String
(also: #to_s)
An access token that can be used in a request to Google Analytics Reporting API v4.
Constructor Details
#initialize(credential_file = nil) ⇒ AccessToken
Get a new access token. The actual token is lazily-generated, so no call is made to Google Analytics until #token is called.
16 17 18 19 20 |
# File 'lib/gaapi/access_token.rb', line 16 def initialize(credential_file = nil) @credential_file = credential_file || File.("~/.gaapi/ga-api-key") stat = File::Stat.new(@credential_file) raise "#{@credential_file} must be readable and writable only by you." if stat.world_readable? || stat.world_writable? end |
Instance Method Details
#token ⇒ String Also known as: to_s
An access token that can be used in a request to Google Analytics Reporting API v4.
24 25 26 |
# File 'lib/gaapi/access_token.rb', line 24 def token (@token ||= fetch_access_token)["access_token"] end |