<commit_before># encoding: utf-8

require 'signet/oauth_2/client'
require_relative '../../../../../lib/carto/http/client'

module CartoDB
  module Datasources
    module Url
      class BigQuery < BaseOAuth

        # Required for all providers
        DATASOURCE_NAME = 'bigquery'

        # Constructor (hidden)
        # @param config
        # [
        #  'application_name'
        #  'client_id'
        #  'client_secret'
        # ]
        # @param user ::User
        # @throws UninitializedError
        # @throws MissingConfigurationError
        def initialize(config, user)
          super(config, user, %w{ application_name client_id client_secret callback_url }, DATASOURCE_NAME)

          raise UninitializedError.new('missing user instance', DATASOURCE_NAME) if user.nil?

          @user = user

          self.filter = []
          @refresh_token = nil

          @client = Signet::OAuth2::Client.new(
            authorization_uri: config.fetch('authorization_uri'),
            token_credential_uri:  config.fetch('token_credential_uri'),
            client_id: config.fetch('client_id'),
            client_secret: config.fetch('client_secret'),
            scope: config.fetch('scope'),
            redirect_uri: config.fetch('callback_url'),
            access_type: :offline
          )
          @revoke_uri = config.fetch('revoke_auth_uri')
        end

        # Factory method
        # @param config {}
        # @param user ::User
        # @return CartoDB::Datasources::Url::GDrive
        def self.get_new(config, user)
          new(config, user)
        end

        # If will provide a url to download the resource, or requires calling get_resource()
        # @return bool
        def providers_download_url?
          false
        end

        # Return the url to be displayed or sent the user to to authenticate and get authorization code
        # @return string | nil
        def get_auth_url()
          # service_name = service_name_for_user(DATASOURCE_NAME, @user)
          @client.state = CALLBACK_STATE_DATA_PLACEHOLDER.sub('user', @user.username)
          @client.authorization_uri.to_s
        end

        # Validates the authorization callback
        # @param params : mixed
        def validate_callback(params)
          if params[:error].present?
            raise AuthError.new("validate_callback: #{params[:error]}", DATASOURCE_NAME)
          end

          if params[:code]
            validate_auth_code(params[:code])
          else
            raise AuthError.new('validate_callback: Missing authorization code', DATASOURCE_NAME)
          end
        end
<commit_msg>Fixing getting the auth URL for bigquery connector<commit_after># encoding: utf-8

require 'signet/oauth_2/client'
require_relative '../../../../../lib/carto/http/client'

module CartoDB
  module Datasources
    module Url
      class BigQuery < BaseOAuth

        # Required for all providers
        DATASOURCE_NAME = 'bigquery'

        # Constructor (hidden)
        # @param config
        # [
        #  'application_name'
        #  'client_id'
        #  'client_secret'
        # ]
        # @param user ::User
        # @throws UninitializedError
        # @throws MissingConfigurationError
        def initialize(config, user)
          super(config, user, %w{ application_name client_id client_secret callback_url }, DATASOURCE_NAME)

          raise UninitializedError.new('missing user instance', DATASOURCE_NAME) if user.nil?

          @user = user

          self.filter = []
          @refresh_token = nil

          @client = Signet::OAuth2::Client.new(
            authorization_uri: config.fetch('authorization_uri'),
            token_credential_uri:  config.fetch('token_credential_uri'),
            client_id: config.fetch('client_id'),
            client_secret: config.fetch('client_secret'),
            scope: config.fetch('scope'),
            redirect_uri: config.fetch('callback_url'),
            access_type: :offline
          )
          @revoke_uri = config.fetch('revoke_auth_uri')
        end

        # Factory method
        # @param config {}
        # @param user ::User
        # @return CartoDB::Datasources::Url::GDrive
        def self.get_new(config, user)
          new(config, user)
        end

        # If will provide a url to download the resource, or requires calling get_resource()
        # @return bool
        def providers_download_url?
          false
        end

        # Return the url to be displayed or sent the user to to authenticate and get authorization code
        # @return string | nil
        def get_auth_url()
          service_name = service_name_for_user(DATASOURCE_NAME, @user)
          @client.state = CALLBACK_STATE_DATA_PLACEHOLDER.sub('user', @user.username)
                                                         .sub('service', service_name)
          @client.authorization_uri.to_s
        end

        # Validates the authorization callback
        # @param params : mixed
        def validate_callback(params)
          if params[:error].present?
            raise AuthError.new("validate_callback: #{params[:error]}", DATASOURCE_NAME)
          end

          if params[:code]
            validate_auth_code(params[:code])
          else
            raise AuthError.new('validate_callback: Missing authorization code', DATASOURCE_NAME)
          end
        end

{'fraction_non_alphanumeric': 0.09143175074183976, 'fraction_numerical': 0.001112759643916914, 'mean_word_length': 2.1047783534830167, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6340670', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1436, 'n_words': 349}