<commit_before>module Relax
  class Performer
    def initialize(method, url, values, options={})
      @method = method
      @url = url
      @values = values
      @credentials = options.delete(:credentials)
      @proxy = options.delete(:proxy)
      @options = options

      parse_url_tokens
    end

    def perform
      RestClient.proxy = @proxy if @proxy

      case @method
        when :delete, :get, :head then RestClient.send(@method, url)
        when :post, :put then RestClient.send(@method, url, query)
      end
    end

    def url
      url = @url.gsub(/\:[a-z_]+/) do |name|
        @url_values[name[1..-1].to_sym]
      end

      uri = URI.parse(url)
      uri.query = query unless query.nil? || query.empty?
      uri.userinfo = @credentials.join(':') if @credentials
      uri.to_s
    end
    private :url

    def query
      @values.collect do |name, value|
        "#{name}=#{value}" if value || @options[:include_blank_values]
      end.compact.join('&')
    end
    private :query

    def parse_url_tokens
      tokens = @url.scan(/(?:\:)([a-z_]+)/).flatten<commit_msg>Added basic request logging.<commit_after>module Relax
  class Performer
    def initialize(method, url, values, options={})
      @method = method
      @url = url
      @values = values
      @logger = options.delete(:logger)
      @credentials = options.delete(:credentials)
      @proxy = options.delete(:proxy)
      @options = options

      parse_url_tokens
    end

    def perform
      RestClient.proxy = @proxy if @proxy

      case @method
        when :delete, :get, :head
          @logger.info "#{@method.to_s.upcase} #{url}" if @logger
          RestClient.send(@method, url)
        when :post, :put
          @logger.info "#{@method.to_s.upcase} #{url}\n#{query}" if @logger
          RestClient.send(@method, url, query)
      end
    end

    def url
      url = @url.gsub(/\:[a-z_]+/) do |name|
        @url_values[name[1..-1].to_sym]
      end

      uri = URI.parse(url)
      uri.query = query unless query.nil? || query.empty?
      uri.userinfo = @credentials.join(':') if @credentials
      uri.to_s
    end
    private :url

    def query
      @values.collect do |name, value|
        "#{name}=#{value}" if value || @options[:include_blank_values]
      end.compact.join('&')
    end
    private :query

    def parse_url_tokens
      tokens = @url.scan(/(?:\:)([a-z_]+)/).flatten
{'fraction_non_alphanumeric': 0.14143508917461634, 'fraction_numerical': 0.0016590626296142678, 'mean_word_length': 2.304109589041096, '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': '3790400', 'n_tokens_mistral': 787, 'n_tokens_neox': 775, 'n_words': 188}