Sha256: 466bcb295a634aea8a7c0f97687dd6657b087e628922d3f0176cdb0a2548365e

Contents?: true

Size: 1.74 KB

Versions: 13

Compression:

Stored size: 1.74 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 :set_apparience_colors
    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']

      gon.color = @color
    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

    def set_apparience_colors
      variables_file = File.readlines(style_file)
      @color = ""
      variables_file.each { |line| @color = line[15..21] if line.include?('$keppler-color') }


      puts "********************** #{@color}"
    end

    def style_file
      "#{Rails.root}/app/assets/stylesheets/admin/utils/_variables.scss"
    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

13 entries across 13 versions & 1 rubygems

Version Path
keppler-2.1.11 installer/core/rockets/keppler_ga_dashboard/app/controllers/keppler_ga_dashboard/dashboard_controller.rb
keppler-2.1.10 installer/core/rockets/keppler_ga_dashboard/app/controllers/keppler_ga_dashboard/dashboard_controller.rb
keppler-2.1.9 installer/core/rockets/keppler_ga_dashboard/app/controllers/keppler_ga_dashboard/dashboard_controller.rb
keppler-2.1.8 installer/core/rockets/keppler_ga_dashboard/app/controllers/keppler_ga_dashboard/dashboard_controller.rb
keppler-2.1.7 installer/core/rockets/keppler_ga_dashboard/app/controllers/keppler_ga_dashboard/dashboard_controller.rb
keppler-2.1.6 installer/core/rockets/keppler_ga_dashboard/app/controllers/keppler_ga_dashboard/dashboard_controller.rb
keppler-2.1.5 installer/core/rockets/keppler_ga_dashboard/app/controllers/keppler_ga_dashboard/dashboard_controller.rb
keppler-2.1.4 installer/core/rockets/keppler_ga_dashboard/app/controllers/keppler_ga_dashboard/dashboard_controller.rb
keppler-2.1.3 installer/core/rockets/keppler_ga_dashboard/app/controllers/keppler_ga_dashboard/dashboard_controller.rb
keppler-2.1.2 installer/core/rockets/keppler_ga_dashboard/app/controllers/keppler_ga_dashboard/dashboard_controller.rb
keppler-2.1.1 installer/core/rockets/keppler_ga_dashboard/app/controllers/keppler_ga_dashboard/dashboard_controller.rb
keppler-2.1.pre.p1 installer/core/rockets/keppler_ga_dashboard/app/controllers/keppler_ga_dashboard/dashboard_controller.rb
keppler-2.1 installer/core/rockets/keppler_ga_dashboard/app/controllers/keppler_ga_dashboard/dashboard_controller.rb