<commit_before>require 'ethon/easy/http/putable'
require 'ethon/easy/http/postable'

module Ethon
  class Easy
    module Http
      # This module represents a Http Action and is a factory
      # for more real actions like GET, HEAD, POST and PUT.
      module Actionable

        # Create a new action.
        #
        # @example Create a new action.
        #   Action.new("www.example.com", {})
        #
        # @param [ String ] url The url.
        # @param [ Hash ] options The options.
        #
        # @return [ Action ] A new action.
        def initialize(url, options)
          @url = url
          @options = options.dup
        end

        # Return the url.
        #
        # @example Return url.
        #   action.url
        #
        # @return [ String ] The url.
        def url
          @url
        end

        # Return the options hash.
        #
        # @example Return options.
        #   action.options
        #
        # @return [ Hash ] The options.
        def options
          @options
        end

        # Return the params.
        #
        # @example Return params.
        #   action.params
        #
        # @return [ Params ] The params.
        def params
          @params ||= Params.new(@easy, options.delete(:params))
        end

        # Return the form.
        #
        # @example Return form.
        #   action.form
        #
        # @return [ Form ] The form.
        def form
          @form ||= Form.new(@easy, options.delete(:body))
        end

        # Setup everything necessary for a proper request.
        #
        # @example setup.
        #   action.setup(easy)
        #
        # @param [ easy ] easy the easy to setup.
        def setup(easy)
          @easy = easy

          if params.empty?
            # This is called here to have the side effect of removing
            # the :params_encoding key from options, to avoid forwarding
            # it to Curl later. FIXME.
            params_encoding
            easy.url = url
          else
            set_params(easy)
          end
          set_form(easy) unless form.empty?
          easy.set_attributes(options)
        end

        # Setup request with params.
        #
        # @example Setup nothing.
        #   action.set_params(easy)
        #
        # @param [ Easy ] easy The easy to setup.
        def set_params(easy)
          params.escape = true
          params.params_encoding = params_encoding

          base_url, base_params = url.split("?")
          base_params += "&" if base_params
          easy.url = "#{base_url}?#{base_params}#{params.to_s}"
        end

        # Get the requested array encoding. By default it's
        # :typhoeus, but it can also be set to :rack.
        #
        # @example Get encoding from options
        #   action.params_encoding
        #
        def params_encoding
          @params_encoding ||= options.delete(:params_encoding) || :typhoeus
        end

        # Setup request with form.
        #
        # @example Setup nothing.
        #   action.set_form(easy)
        #
        # @param [ Easy ] easy The easy to setup.
        def set_form(easy)
        end
      end
    end
  end
end
<commit_msg>Split Queryable options from Curl ones<commit_after>require 'ethon/easy/http/putable'
require 'ethon/easy/http/postable'

module Ethon
  class Easy
    module Http
      # This module represents a Http Action and is a factory
      # for more real actions like GET, HEAD, POST and PUT.
      module Actionable

        # Create a new action.
        #
        # @example Create a new action.
        #   Action.new("www.example.com", {})
        #
        # @param [ String ] url The url.
        # @param [ Hash ] options The options.
        #
        # @return [ Action ] A new action.
        def initialize(url, options)
          @url = url
          @options, @query_options = parse_options(options)
        end

        # Return the url.
        #
        # @example Return url.
        #   action.url
        #
        # @return [ String ] The url.
        def url
          @url
        end

        # Return the options hash.
        #
        # @example Return options.
        #   action.options
        #
        # @return [ Hash ] The options.
        def options
          @options
        end

        # Returns the query options hash.
        #
        # @example Return query options.
        #   action.query_options
        #
        # @return [ Hash ] The query options.
        def query_options
          @query_options
        end

        # Return the params.
        #
        # @example Return params.
        #   action.params
        #
        # @return [ Params ] The params.
        def params
          @params ||= Params.new(@easy, query_options.fetch(:params, nil))
        end

        # Return the form.
        #
        # @example Return form.
        #   action.form
        #
        # @return [ Form ] The form.
        def form
          @form ||= Form.new(@easy, query_options.fetch(:body, nil))
        end

        # Get the requested array encoding. By default it's
        # :typhoeus, but it can also be set to :rack.
        #
        # @example Get encoding from options
        #   action.params_encoding
        #
        def params_encoding
          @params_encoding ||= query_options.fetch(:params_encoding, :typhoeus)
        end

        # Setup everything necessary for a proper request.
        #
        # @example setup.
        #   action.setup(easy)
        #
        # @param [ easy ] easy the easy to setup.
        def setup(easy)
          @easy = easy

          if params.empty?
            # This is called here to have the side effect of removing
            # the :params_encoding key from options, to avoid forwarding
            # it to Curl later. FIXME.
            params_encoding
            easy.url = url
          else
            set_params(easy)
          end
          set_form(easy) unless form.empty?
          easy.set_attributes(options)
        end

        # Setup request with params.
        #
        # @example Setup nothing.
        #   action.set_params(easy)
        #
        # @param [ Easy ] easy The easy to setup.
        def set_params(easy)
          params.escape = true
          params.params_encoding = params_encoding

          base_url, base_params = url.split("?")
          base_params += "&" if base_params
          easy.url = "#{base_url}?#{base_params}#{params.to_s}"
        end

        # Setup request with form.
        #
        # @example Setup nothing.
        #   action.set_form(easy)
        #
        # @param [ Easy ] easy The easy to setup.
        def set_form(easy)
        end

        private

        def parse_options(options)
          query_options = {}
          options = options.dup

          [ :params, :body, :params_encoding ].each do |query_option|
            if options.key?(query_option)
              query_options[query_option] = options.delete(query_option)
            end
          end

          return options, query_options
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.08417366946778712, 'fraction_numerical': 0.0, 'mean_word_length': 1.415764546684709, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3608138', 'n_tokens_mistral': 1978, 'n_tokens_neox': 1921, 'n_words': 587}