<commit_before>module Hipbot
  module Http
    class Request < Struct.new(:url, :query, :method)
      DEFAULT_HEADERS     = { 'accept-encoding' => 'gzip, compressed' }.freeze
      CONNECTION_SETTINGS = { connect_timeout: 5, inactivity_timeout: 10 }.freeze
      ERROR_CALLBACK      = ->(error){ Hipbot.logger.error(error) }

      def initialize *args
        super
        Hipbot.logger.info("HTTP-REQUEST: #{url} #{query}")
      end

      def call &success_block
        http.errback(&ERROR_CALLBACK)
        http.callback do
          success(&success_block)
        end unless success_block.nil?
      end

      protected

      def success
        yield Http::Response.new(http)
      rescue => e
        Hipbot.logger.error(e)
        instance_exec(e, &Hipbot.exception_handler)
      end

      def http
        @http ||= connection.send(method, query: query.merge(head: DEFAULT_HEADERS))
      end

      def connection
        EM::HttpRequest.new(url, CONNECTION_SETTINGS)
      end
    end

    class Response < Struct.new(:raw_response)
      def initialize *args
        super
        Hipbot.logger.info("HTTP-RESPONSE: #{headers}")
      end

      def body
        raw_response.response
      end

      def code
        raw_response.response_header.status
      end

      def headers
        raw_response.response_header
      end

      def json
        @json ||= JSON.parse(body) || {}
      end
    end
  end
end<commit_msg>logging changes<commit_after>module Hipbot
  module Http
    class Request < Struct.new(:url, :query, :method)
      DEFAULT_HEADERS     = { 'accept-encoding' => 'gzip, compressed' }.freeze
      CONNECTION_SETTINGS = { connect_timeout: 5, inactivity_timeout: 10 }.freeze
      ERROR_CALLBACK      = ->(error){ Hipbot.logger.error(error) }

      def initialize *args
        super
        Hipbot.logger.info("HTTP-REQUEST: #{url} #{query}")
      end

      def call &success_block
        http.errback(&ERROR_CALLBACK)
        http.callback do
          success(&success_block)
        end unless success_block.nil?
      end

      protected

      def success
        yield Http::Response.new(http)
      rescue => e
        instance_exec(e, &Hipbot.exception_handler)
      end

      def http
        @http ||= connection.send(method, query: query.merge(head: DEFAULT_HEADERS))
      end

      def connection
        EM::HttpRequest.new(url, CONNECTION_SETTINGS)
      end
    end

    class Response < Struct.new(:raw_response)
      def initialize *args
        super
        Hipbot.logger.debug("HTTP-RESPONSE: #{body}")
      end

      def body
        raw_response.response
      end

      def code
        raw_response.response_header.status
      end

      def headers
        raw_response.response_header
      end

      def json
        @json ||= JSON.parse(body) || {}
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09284467713787085, 'fraction_numerical': 0.0020942408376963353, 'mean_word_length': 2.0983783783783783, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '3697121', 'n_tokens_mistral': 866, 'n_tokens_neox': 837, 'n_words': 193}