<commit_before>require "net/http"
require "uri"

module Roar
  module Representer
    # Implements the (HTTP) transport interface with Net::HTTP.
    module Transport
      # Definitions: every call returns a Response object responding to #body.
      class NetHTTP
        class Request # TODO: implement me.
          def initialize(options)
            @uri  = parse_uri(options[:url]) # TODO: add :uri.
            @as   = options[:as]
            @body = options[:body]
          end

          def get
            call(Net::HTTP::Get)
          end

        private
          attr_reader :uri, :as, :body

          def parse_uri(url)
            uri = URI(url)
            raise "Incorrect URL `#{url}`. Maybe you forgot http://?" if uri.instance_of?(URI::Generic)
            uri
          end
        end



        # TODO: generically handle return codes.
        { :get    => Net::HTTP::Get,
          :post   => Net::HTTP::Post,
          :put    => Net::HTTP::Put,
          :delete => Net::HTTP::Delete,
          :patch  => Net::HTTP::Patch
        }.each do |method, mod|
          define_method("#{method}_uri") do |options, &block| # gives us #get_uri, #post_uri and friends.
            call(mod, options, &block)
          end
        end

      private
        def call(what, options, &block)<commit_msg>don't use define_method for #get_uri and friends, Patch is not defined in 1.8.<commit_after>require "net/http"
require "uri"

module Roar
  module Representer
    # Implements the (HTTP) transport interface with Net::HTTP.
    module Transport
      # Definitions: every call returns a Response object responding to #body.
      class NetHTTP
        class Request # TODO: implement me.
          def initialize(options)
            @uri  = parse_uri(options[:url]) # TODO: add :uri.
            @as   = options[:as]
            @body = options[:body]
          end

          def get
            call(Net::HTTP::Get)
          end

        private
          attr_reader :uri, :as, :body

          def parse_uri(url)
            uri = URI(url)
            raise "Incorrect URL `#{url}`. Maybe you forgot http://?" if uri.instance_of?(URI::Generic)
            uri
          end
        end

        def get_uri(options, &block)
          call(Net::HTTP::Get, options, &block)
        end

        def post_uri(options, &block)
          call(Net::HTTP::Post, options, &block)
        end

        def put_uri(options, &block)
          call(Net::HTTP::Put, options, &block)
        end

        def delete_uri(options, &block)
          call(Net::HTTP::Delete, options, &block)
        end

        def patch_uri(options, &block)
          call(Net::HTTP::Patch, options, &block)
        end

      private
        def call(what, options, &block)
          # TODO: generically handle return codes.
{'fraction_non_alphanumeric': 0.10910379029401346, 'fraction_numerical': 0.0007084661707403471, 'mean_word_length': 1.8439073514602216, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '6635175', 'n_tokens_mistral': 801, 'n_tokens_neox': 783, 'n_words': 239}