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

module Boxzooka
  # Run requests, construct + return responses.
  class Endpoint
    Error = Class.new(StandardError)

    def initialize(customer_id:, customer_key:, urls:, debug: false)
      @customer_access = Boxzooka::CustomerAccess.new(customer_id: customer_id, customer_key: customer_key)
      @urls = urls
      @debug = debug
    end

    # Run the request.
    def execute(request)
      request.customer_access ||= @customer_access

      request_xml       = serialize(request)
      endpoint_url      = url_for_request(request)
      http_response     = post(endpoint_url, request_xml)

      response_xml      = http_response.
                          body.
                          sub("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", '')

      if @debug
        puts "REQUEST XML"
        puts request_xml

        puts "RESPONSE CODE: #{http_response.code}"
        puts "RESPONSE XML"
        puts response_xml
      end
<commit_msg>Boxzooka::Endpoint - log to Logger object rather than puts.<commit_after>require 'uri'
require 'net/http'
require 'logger'

module Boxzooka
  # Run requests, construct + return responses.
  class Endpoint
    Error = Class.new(StandardError)

    def initialize(customer_id:, customer_key:, urls:, debug: false, logger: nil)
      @customer_access = Boxzooka::CustomerAccess.new(customer_id: customer_id, customer_key: customer_key)
      @urls = urls
      @debug = debug
      @logger = logger || Logger.new(STDOUT)
    end

    # Run the request.
    def execute(request)
      request.customer_access ||= @customer_access

      request_xml       = serialize(request)
      endpoint_url      = url_for_request(request)
      http_response     = post(endpoint_url, request_xml)

      response_xml      = http_response.
                          body.
                          sub("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", '')

      if @debug
        @logger.debug "REQUEST XML"
        @logger.debug request_xml

        @logger.debug "RESPONSE CODE: #{http_response.code}"
        @logger.debug "RESPONSE XML"
        @logger.debug response_xml
      end

{'fraction_non_alphanumeric': 0.10092165898617511, 'fraction_numerical': 0.0027649769585253456, 'mean_word_length': 2.435126582278481, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 2, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '5290866', 'n_tokens_mistral': 649, 'n_tokens_neox': 640, 'n_words': 150}