<commit_before>require 'json/pure'
require 'coderay'
require 'curb'
module Whurl
  class Command
    def initialize(url, method, options = {})
      @method = method
      data = []
      if options[:param_keys]
        options[:param_keys].each_with_index do |key, i|
          data << "#{key}=#{options[:param_values][i]}" if key.present?
        end
      end

      @data = URI.encode(data.join("&"))
      @command = make_command(url, @data)
      case @method
        when "POST"
          @command.post_body = @data
        when "PUT"
          @command.put_data = @data
      end

      @command.useragent = "Whurl/1.0"

      if options[:header_keys]
        options[:header_keys].each_with_index do |key, i|
          @command.headers[key] = options[:header_values][i] if key.present?
        end
      end


    end

    def send_request
      acceptable_methods = ["GET", "POST", "PUT", "DELETE"]
      raise "Method not accepted" unless acceptable_methods.include?(@method)
      if @method == "PUT"
        @command.send("http_#{@method.downcase}", @data)
      else
        @command.send("http_#{@method.downcase}")
      end
    end

    def body_str
      @command.body_str
    end

    def response_html
      code_ray_options = {:line_numbers => :table}
      case @command.content_type
        when /xml/
          CodeRay.scan(@command.body_str, :xml).div(code_ray_options)
        when /html/
          CodeRay.scan(@command.body_str, :html).div(code_ray_options)
        else
          CodeRay.scan(JSON.pretty_generate(JSON.parse(@command.body_str)), :json).div(code_ray_options)
      end
    end

    def url
      @command.url
    end

    protected
    def make_command(url, data)
      if ["GET", "DELETE"].include?(@method)
        if url.include?("?")
          @command = Curl::Easy.new(url + "&" + data)
        else
          @command = Curl::Easy.new(url + "?" + data)
        end
      else
        @command = Curl::Easy.new(url)
      end
    end
  end
end<commit_msg>don't over escape parameters for post and put<commit_after>require 'json/pure'
require 'coderay'
require 'curb'
module Whurl
  class Command
    def initialize(url, method, options = {})
      @method = method
      data = []
      if options[:param_keys]
        options[:param_keys].each_with_index do |key, i|
          data << "#{key}=#{options[:param_values][i]}" if key.present?
        end
      end

      @data = data.join("&")
      @command = make_command(url, @data)
      case @method
        when "POST"
          @command.post_body = @data
        when "PUT"
          @command.put_data = @data
      end

      @command.useragent = "Whurl/1.0"

      if options[:header_keys]
        options[:header_keys].each_with_index do |key, i|
          @command.headers[key] = options[:header_values][i] if key.present?
        end
      end


    end

    def send_request
      acceptable_methods = ["GET", "POST", "PUT", "DELETE"]
      raise "Method not accepted" unless acceptable_methods.include?(@method)
      if @method == "PUT"
        @command.send("http_#{@method.downcase}", @data)
      else
        @command.send("http_#{@method.downcase}")
      end
    end

    def body_str
      @command.body_str
    end

    def response_html
      code_ray_options = {:line_numbers => :table}
      case @command.content_type
        when /xml/
          CodeRay.scan(@command.body_str, :xml).div(code_ray_options)
        when /html/
          CodeRay.scan(@command.body_str, :html).div(code_ray_options)
        else
          CodeRay.scan(JSON.pretty_generate(JSON.parse(@command.body_str)), :json).div(code_ray_options)
      end
    end

    def url
      @command.url
    end

    protected
    def make_command(url, data)
      if ["GET", "DELETE"].include?(@method)
        if url.include?("?")
          @command = Curl::Easy.new(url + "&" + URI.encode(data))
        else
          @command = Curl::Easy.new(url + "?" + URI.encode(data))
        end
      else
        @command = Curl::Easy.new(url)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.13172175629008387, 'fraction_numerical': 0.000986679822397632, 'mean_word_length': 2.251804330392943, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '4079007', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1286, 'n_words': 274}