<commit_before>require 'netrc'
require 'faraday'
require 'json'

module Acquia
  module CloudApi
    class Client
      def initialize(options = {})
        # Providing that we have both the username and the password, use it
        # otherwise we will run through the available authentication sources to
        # find our user details.
        options[:username] ||= user_credentials[:username]
        options[:password] ||= user_credentials[:password]

        if proxy?
          connection = Faraday.new(url: Acquia.cloud_api_uri, proxy: { uri: ENV['HTTPS_PROXY'] })
        else
          connection = Faraday.new(url: Acquia.cloud_api_uri)
        end

        connection.headers['User-Agent'] = "Acquia SDK (#{Acquia::VERSION})"
        connection.basic_auth(options[:username], options[:password])
        response = connection.get "#{Acquia.cloud_api_version}/sites.json"

        fail InvalidUserCredentials, "Invalid user credentials" if response.status == 401
      end

      # Internal: Determine if the user is behind a firewall or proxy.
      #
      # Returns a boolean based on whether the environment variable is found.
      def proxy?
        (ENV['HTTPS_PROXY'].nil?) ? false : true
      end

      # Internal: Get the user credentials from available sources.
      #
      # This method is responsible for checking the available sources and
      # providing the user credentials back in a hash.
      #
      # Returns a hash of the user credentials keyed with 'username' and
      # 'password'.
      def user_credentials
        acquia_conf_auth if File.exist? acquia_conf_path
        netrc_auth if File.exist? netrc_path
      end

      # Internal: Pull the details out of the Acquia configuration file.
      #
      # This will find the Acquia Cloud configuration file and extract the
      # username and password from the JSON object.
      #
      # Returns a hash of the username and password.
      def acquia_conf_auth<commit_msg>Provide a default site option<commit_after>require 'netrc'
require 'faraday'
require 'json'

module Acquia
  module CloudApi
    class Client
      def initialize(options = {})
        # Providing that we have both the username and the password, use it
        # otherwise we will run through the available authentication sources to
        # find our user details.
        options[:username] ||= user_credentials[:username]
        options[:password] ||= user_credentials[:password]

        if proxy?
          connection = Faraday.new(url: Acquia.cloud_api_uri, proxy: { uri: ENV['HTTPS_PROXY'] })
        else
          connection = Faraday.new(url: Acquia.cloud_api_uri)
        end

        connection.headers['User-Agent'] = "Acquia SDK (#{Acquia::VERSION})"
        connection.basic_auth(options[:username], options[:password])
        response = connection.get "#{Acquia.cloud_api_version}/sites.json"

        fail InvalidUserCredentials, 'Invalid user credentials' if response.status == 401

        # Haven't made a site selection? Looks like you get the first one we
        # find.
        options[:site] ||= JSON.parse(response.body).first
      end

      # Internal: Determine if the user is behind a firewall or proxy.
      #
      # Returns a boolean based on whether the environment variable is found.
      def proxy?
        (ENV['HTTPS_PROXY'].nil?) ? false : true
      end

      # Internal: Get the user credentials from available sources.
      #
      # This method is responsible for checking the available sources and
      # providing the user credentials back in a hash.
      #
      # Returns a hash of the user credentials keyed with 'username' and
      # 'password'.
      def user_credentials
        acquia_conf_auth if File.exist? acquia_conf_path
        netrc_auth if File.exist? netrc_path
      end

      # Internal: Pull the details out of the Acquia configuration file.
      #
      # This will find the Acquia Cloud configuration file and extract the
      # username and password from the JSON object.
      #
      # Returns a hash of the username and password.
      def acquia_conf_auth
{'fraction_non_alphanumeric': 0.07540744344441741, 'fraction_numerical': 0.001459498905375821, 'mean_word_length': 2.655111111111111, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7194708', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1073, 'n_words': 399}