<commit_before>require "excon"
require "json"
require "quickpay/api/error"

module QuickPay
  module API
    class Client
      APP_VERSION = "2.0.0".freeze
      API_VERSION = "v10".freeze
      DEFAULT_HEADERS = {
        "User-Agent"     => "quickpay-ruby-client, v#{APP_VERSION}",
        "Accept-Version" => API_VERSION
      }.freeze

      def initialize(username: nil, password: <PASSWORD>, base_uri: "https://api.quickpay.net", options: {})
        opts = {
          read_timeout: options.fetch(:read_timeout, 60),
          write_timeout: options.fetch(:write_timeout, 60),
          connect_timeout: options.fetch(:connect_timeout, 60),
        }

        opts[:username] = Excon::Utils.escape_uri(username) if username
        opts[:password] = Excon::Utils.escape_uri(password) if password

        @connection = Excon.new(base_uri, opts)
      end

      [:get, :post, :patch, :put, :delete, :head].each do |method|
        define_method(method) do |path, options = {}|
          headers = DEFAULT_HEADERS.merge(options.fetch(:headers, {}))
          body    = begin
            data = options.fetch(:body, "")
            if headers["Content-Type"] == "application/json" && data.instance_of?(Hash)
              data.to_json 
            else
              data
            end
          end

          res = @connection.__send__(
            method,
            path: path,
            body: body,
            headers: headers,
            query: options.fetch(:query, {})
          )

          if options.fetch(:raw, false)
            [res.status, res.body, res.headers]
          else
            if res.status >= 400
              raise QuickPay::API::Error.by_status_code(res.status, res.body, res.headers)
            end

            res.headers["Content-Type"] == "application/json" ? JSON.parse(res.body) : res.body
          end
        end
      end
    end
  end
end
<commit_msg>minor optimization<commit_after>require "excon"
require "json"
require "quickpay/api/error"
require "quickpay/api/version"

module QuickPay
  module API
    class Client
      DEFAULT_HEADERS = {
        "User-Agent"     => "quickpay-ruby-client, v#{QuickPay::API::VERSION}",
        "Accept-Version" => "v10"
      }.freeze

      def initialize(username: nil, password: <PASSWORD>, base_uri: "https://api.quickpay.net", options: {})
        opts = {
          read_timeout: options.fetch(:read_timeout, 60),
          write_timeout: options.fetch(:write_timeout, 60),
          connect_timeout: options.fetch(:connect_timeout, 60),
        }

        opts[:username] = Excon::Utils.escape_uri(username) if username
        opts[:password] = Excon::Utils.escape_uri(password) if password

        @connection = Excon.new(base_uri, opts)
      end

      [:get, :post, :patch, :put, :delete, :head].each do |method|
        define_method(method) do |path, options = {}|
          headers = DEFAULT_HEADERS.merge(options.fetch(:headers, {}))
          body    = begin
            data = options.fetch(:body, "")
            if headers["Content-Type"] == "application/json" && data.instance_of?(Hash)
              data.to_json 
            else
              data
            end
          end

          res = @connection.__send__(
            method,
            path: path,
            body: body,
            headers: headers,
            query: options.fetch(:query, {})
          )

          if options.fetch(:raw, false)
            [res.status, res.body, res.headers]
          else
            if res.status >= 400
              raise QuickPay::API::Error.by_status_code(res.status, res.body, res.headers)
            end

            res.headers["Content-Type"] == "application/json" ? JSON.parse(res.body) : res.body
          end
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.12556053811659193, 'fraction_numerical': 0.006594566077552097, 'mean_word_length': 1.9671361502347418, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 2, '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': '2853659', 'n_tokens_mistral': 1117, 'n_tokens_neox': 1080, 'n_words': 231}