<commit_before>module Pina
  class RestAdapter
    include ActiveSupport::JSON

    class << self
      def get(resource, id_or_params = nil)
        net_http_for(:get, resource, id_or_params)
      end

      def post(resource, payload)
        net_http_for(:post, resource, nil, payload)
      end

      def patch(resource, id, payload)
        net_http_for(:patch, resource, id, payload)
      end

      def delete(resource, id = nil)
        net_http_for(:delete, resource, id)
      end

      private

      def net_http_for(method, resource, id, payload = nil)
        fail ConfigurationNotSet unless Pina.configuration

        uri = URI(url(resource, id))

        request = net_http_class_for(method).new(uri)
        headers.each do |k, v|
          request[k] = v
        end
        request.body = payload.to_json if payload

        response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
          http.request(request)
        end

        Response.new(response.code.to_i, response.body)
      end

      def net_http_class_for(method)
        Kernel.const_get("Net::HTTP::#{method.capitalize}")
      end

      def headers
        {
          'Authorization' => 'Basic ' + Base64
          .strict_encode64("#{Pina.configuration.email}:#{Pina.configuration.api_token}"),
          'Accept-Encoding' => 'application/json',
          'Content-Type' =>  'application/json'
        }
      end

      def url(resource, id_or_params)
        if id_or_params.is_a? Hash
          params = prepare_params_for_request(id_or_params)
          Pina.configuration.base_url + "#{resource}?#{params}"
        else
          Pina.configuration.base_url + "#{resource}/#{id_or_params}"
        end
      end

      def prepare_params_for_request(params)
        params.map { |key, value| "#{URI::escape(key.to_s)}=#{URI::escape(value.to_s)}" }.join('&')
      end
    end

    class Response
      attr_accessor :body, :status_code

      def initialize(status_code, body)
        @status_code = status_code
        @body        = body
      end

      def ok?
        status_code == 200 || status_code == 201
      end

      def to_hash
        ActiveSupport::JSON.decode(body)
      end
    end
  end
end
<commit_msg>Hotfix movement to puma<commit_after>module Pina
  class RestAdapter
    include ActiveSupport::JSON

    class << self
      def get(resource, id_or_params = nil)
        net_http_for(:get, resource, id_or_params)
      end

      def post(resource, payload)
        net_http_for(:post, resource, nil, payload)
      end

      def patch(resource, id, payload)
        net_http_for(:patch, resource, id, payload)
      end

      def delete(resource, id = nil)
        net_http_for(:delete, resource, id)
      end

      private

      def net_http_for(method, resource, id, payload = nil)
        fail ConfigurationNotSet unless Pina.configuration

        uri = URI(url(resource, id))

        request = net_http_class_for(method).new(uri)
        headers.each do |k, v|
          request[k] = v
        end
        request.body = payload.to_json if payload

        response = Net::HTTP.start(uri.hostname, uri.port,
                                   use_ssl: true,
                                   verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
          http.request(request)
        end

        Response.new(response.code.to_i, response.body)
      end

      def net_http_class_for(method)
        Kernel.const_get("Net::HTTP::#{method.capitalize}")
      end

      def headers
        {
          'Authorization' => 'Basic ' + Base64
          .strict_encode64("#{Pina.configuration.email}:#{Pina.configuration.api_token}"),
          'Accept-Encoding' => 'application/json',
          'Content-Type' =>  'application/json'
        }
      end

      def url(resource, id_or_params)
        if id_or_params.is_a? Hash
          params = prepare_params_for_request(id_or_params)
          Pina.configuration.base_url + "#{resource}?#{params}"
        else
          Pina.configuration.base_url + "#{resource}/#{id_or_params}"
        end
      end

      def prepare_params_for_request(params)
        params.map { |key, value| "#{URI::escape(key.to_s)}=#{URI::escape(value.to_s)}" }.join('&')
      end
    end

    class Response
      attr_accessor :body, :status_code

      def initialize(status_code, body)
        @status_code = status_code
        @body        = body
      end

      def ok?
        status_code == 200 || status_code == 201
      end

      def to_hash
        ActiveSupport::JSON.decode(body)
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.10585683297180043, 'fraction_numerical': 0.004338394793926247, 'mean_word_length': 2.1495901639344264, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6505558', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1387, 'n_words': 297}