<commit_before>module SendWithUs
  class ApiInvalidEndpoint < StandardError; end
  class ApiConnectionRefused < StandardError; end
  class ApiBadRequest < StandardError; end
  class ApiInvalidKey < StandardError; end
  class ApiUnknownError < StandardError; end

  class ApiRequest
    attr_reader :response

    def initialize(configuration)
      @configuration = configuration
    end

    def post(endpoint, payload)
      request(Net::HTTP::Post, request_path(endpoint), payload)
    end

    def get(endpoint)
      request(Net::HTTP::Get, request_path(endpoint))
    end

    private

      def request_path(end_point)
        "/api/v#{@configuration.api_version}/#{end_point}"
      end

      def use_ssl?
        @configuration.protocol == 'https'
      end

      def request(method_klass, path, payload=nil)
        request = method_klass.new(path, initheader = {'Content-Type' =>'application/json'})
        request.add_field('X-SWU-API-KEY', @configuration.api_key)
        request.add_field('X-SWU-API-CLIENT', @configuration.client_stub)

        http          = Net::HTTP.new(@configuration.host, @configuration.port)
        http.use_ssl  = use_ssl?<commit_msg>Add DELETE method to ApiRequest<commit_after>module SendWithUs
  class ApiInvalidEndpoint < StandardError; end
  class ApiConnectionRefused < StandardError; end
  class ApiBadRequest < StandardError; end
  class ApiInvalidKey < StandardError; end
  class ApiUnknownError < StandardError; end

  class ApiRequest
    attr_reader :response

    def initialize(configuration)
      @configuration = configuration
    end

    def post(endpoint, payload)
      request(Net::HTTP::Post, request_path(endpoint), payload)
    end

    def get(endpoint)
      request(Net::HTTP::Get, request_path(endpoint))
    end
    
    def delete(endpoint)
      request(Net::HTTP::Delete, request_path(endpoint))
    end

    private

      def request_path(end_point)
        "/api/v#{@configuration.api_version}/#{end_point}"
      end

      def use_ssl?
        @configuration.protocol == 'https'
      end

      def request(method_klass, path, payload=nil)
        request = method_klass.new(path, initheader = {'Content-Type' =>'application/json'})
        request.add_field('X-SWU-API-KEY', @configuration.api_key)
        request.add_field('X-SWU-API-CLIENT', @configuration.client_stub)

        http          = Net::HTTP.new(@configuration.host, @configuration.port)
        http.use_ssl  = use_ssl?
{'fraction_non_alphanumeric': 0.10238769728854714, 'fraction_numerical': 0.0, 'mean_word_length': 3.3444639718804923, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, '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': '1859117', 'n_tokens_mistral': 715, 'n_tokens_neox': 721, 'n_words': 150}