Sha256: db36c93e5b778495eec1c81b3da1761c1e83b0ab2ff2065f273d5df817032e0f

Contents?: true

Size: 1.34 KB

Versions: 6

Compression:

Stored size: 1.34 KB

Contents

require 'google/api_client'

module KepplerGaDashboard
  # DashboarController
  class DashboardController < ::ApplicationController
    layout 'keppler_ga_dashboard/admin/layouts/application'
    before_action :dashboard_access, only: [:analytics]
    before_action :authenticate_user!

    def analytics
      # set up a client instance
      client = ::Google::APIClient.new(
        application_name: 'keppler',
        application_version: '1'
      )

      client.authorization = Signet::OAuth2::Client.new(
        options
      ).tap(&:fetch_access_token!)

      @access_token = client.authorization.fetch_access_token!['access_token']
    end

    # Options for authenticate
    def options
      { token_credential_uri: 'https://accounts.google.com/o/oauth2/token',
        audience: 'https://accounts.google.com/o/oauth2/token',
        scope: 'https://www.googleapis.com/auth/analytics.readonly',
        issuer: Rails.application.secrets.ga_auth.fetch(
          :service_account_email_address
        ),
        signing_key: Google::APIClient::KeyUtils.load_from_pkcs12(
          file_key, 'notasecret'
        )
      }
    end

    # get .p12 File for authenticate token
    def file_key
      File.join(
        Rails.root,
        'config',
        'gaAuth',
        Rails.application.secrets.ga_auth.fetch(:file_key_name)
      )
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
keppler-2.0.7 installer/core/rockets/keppler_ga_dashboard/app/controllers/keppler_ga_dashboard/dashboard_controller.rb
keppler-2.0.6 installer/core/rockets/keppler_ga_dashboard/app/controllers/keppler_ga_dashboard/dashboard_controller.rb
keppler-2.0.5 installer/core/rockets/keppler_ga_dashboard/app/controllers/keppler_ga_dashboard/dashboard_controller.rb
keppler-2.0.4.p1 installer/core/rockets/keppler_ga_dashboard/app/controllers/keppler_ga_dashboard/dashboard_controller.rb
keppler-2.0.4.pre.p1 installer/core/rockets/keppler_ga_dashboard/app/controllers/keppler_ga_dashboard/dashboard_controller.rb
keppler-2.0.4 installer/core/rockets/keppler_ga_dashboard/app/controllers/keppler_ga_dashboard/dashboard_controller.rb