Class: GoogleService

Inherits:
Object
  • Object
show all
Defined in:
app/services/google_service.rb

Instance Method Summary collapse

Constructor Details

#initializeGoogleService

Returns a new instance of GoogleService.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/services/google_service.rb', line 4

def initialize
  name = Rails.application.class.to_s
  version = "1"
  issuer = Rails.application.secrets.ga_client_email
  key_path = Rails.root.join("config", "google_service_key.p12").to_s
  passphrase = Rails.application.secrets.ga_passphrase
  scope = ["https://www.googleapis.com/auth/analytics.readonly"]

  @client = Google::APIClient.new(application_name: name,
                                  application_version: version)

  key = Google::APIClient::PKCS12.load_key(key_path, passphrase)
   = Google::APIClient::JWTAsserter.new(issuer, scope, key)
  @client.authorization = .authorize
end

Instance Method Details

#access_tokenObject



20
21
22
23
# File 'app/services/google_service.rb', line 20

def access_token
  response = @client.authorization.fetch_access_token!
  response["access_token"]
end