Sha256: 0f4c2dfba2cb4d2489f3ab260d55090cb8d8963d15dfe5abc5f55bbfd7171726

Contents?: true

Size: 1.14 KB

Versions: 7

Compression:

Stored size: 1.14 KB

Contents

class ApplicationController < ActionController::Base
  include ExceptionHandler

  before_action :check_env_variables
  protect_from_forgery prepend: true

  helper_method :authorized?

  private

  def authorized?
    HubspotToken.instance.filled? && TrelloToken.instance.filled?
  end

  def check_env_variables
    missing_vars = %w[
      HUBSPOT_CLIENT_ID
      HUBSPOT_CLIENT_SECRET
      HUBSPOT_DEVELOPER_API_KEY
      HUBSPOT_APPLICATION_ID
      TRELLO_KEY
      TRELLO_SECRET
    ].select { |var| ENV[var].blank? }
    raise(ExceptionHandler::HubspotError.new, "Please specify #{missing_vars.join(', ')} in .env") if missing_vars.present?
  end

  def authorize
    redirect_to login_path and return unless authorized?

    new_hubspot_tokens = Services::Hubspot::Authorization::Tokens::Refresh.new(
      tokens: HubspotToken.instance.attributes,
      request: request
    ).call
    HubspotToken.instance.update_attributes(new_hubspot_tokens)
    Services::Hubspot::Authorization::Authorize.new(tokens: HubspotToken.instance.attributes).call
    Services::Trello::Authorization::Authorize.new(tokens: TrelloToken.instance.attributes).call
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hubspot-api-client-9.0.0 sample-apps/trello-integration-app/app/controllers/application_controller.rb
hubspot-api-client-8.0.1 sample-apps/trello-integration-app/app/controllers/application_controller.rb
hubspot-api-client-8.0.0 sample-apps/trello-integration-app/app/controllers/application_controller.rb
hubspot-api-client-7.3.0 sample-apps/trello-integration-app/app/controllers/application_controller.rb
hubspot-api-client-7.2.0 sample-apps/trello-integration-app/app/controllers/application_controller.rb
hubspot-api-client-7.1.1 sample-apps/trello-integration-app/app/controllers/application_controller.rb
hubspot-api-client-7.1.0 sample-apps/trello-integration-app/app/controllers/application_controller.rb