<commit_before>
module Nowa
module Api

  module Remote
    ENDPOINT = 'api.ingeniapi.com'
    API_VERSION = '1.0'

    attr_reader :port

    extend self

    def get(path, opts = {})
      check_params opts

      handle_request do
        uri = build_uri(path, opts)

        json = RestClient.get uri.to_s, :params => opts
        
        JSON.parse json
      end
    end

    def post(path, opts = {})
      check_params opts

      handle_request do
        uri = build_uri(path, opts)
        json = RestClient.post uri.to_s, opts

        JSON.parse json
      end
    end

    def put(path, opts = {})
      check_params opts

      handle_request do
        uri = build_uri(path, opts)
        json = RestClient.put uri.to_s, opts
        JSON.parse json
      end
    end

    def delete(path, opts = {})
      check_params opts

      handle_request do
        uri = build_uri(path, opts)
        json = RestClient.delete uri.to_s, opts
        JSON.parse json
      end
    end

    def endpoint=(str)
      if str[ ':' ]
        parts = str.split(':')
        @endpoint = parts[0]
        @port     = parts[1].to_i
        return str
      end

      @endpoint = str
    end

    def endpoint
      @endpoint || ENDPOINT

    end 

    private

    def check_params param_hash
      raise "missing API key" if (not param_hash.has_key?(:api_key)) || param_hash[:api_key].nil? || param_hash[:api_key].length == 0
    end

    def handle_request
      begin

        yield
      
      rescue RestClient::BadRequest => e
        if e.response.nil?
          { 'status' => 'error', 'message' => e.to_s }
        else
          JSON.parse e.response
        end

      rescue RestClient::UnprocessableEntity => e
        JSON.parse e.response

      rescue JSON::ParserError => e
        { 'status' => 'error', 'message' => e.to_s }

      end
    end

    def build_uri(path, opts = {})
      opts[:api_version] ||= API_VERSION
      
      url  = URI::HTTP.build( :host => endpoint, :path => path )
      url.port = port if port

      url
    end

  end

end
end
<commit_msg>fix to params check for delete<commit_after>
module Nowa
module Api

  module Remote
    ENDPOINT = 'api.ingeniapi.com'
    API_VERSION = '1.0'

    attr_reader :port

    extend self

    def get(path, opts = {})
      check_params opts

      handle_request do
        uri = build_uri(path, opts)

        json = RestClient.get uri.to_s, :params => opts
        
        JSON.parse json
      end
    end

    def post(path, opts = {})
      check_params opts

      handle_request do
        uri = build_uri(path, opts)
        json = RestClient.post uri.to_s, opts

        JSON.parse json
      end
    end

    def put(path, opts = {})
      check_params opts

      handle_request do
        uri = build_uri(path, opts)
        json = RestClient.put uri.to_s, opts
        JSON.parse json
      end
    end

    def delete(path, opts = {})
      handle_request do
        uri = build_uri(path, opts)
        json = RestClient.delete uri.to_s, opts
        JSON.parse json
      end
    end

    def endpoint=(str)
      if str[ ':' ]
        parts = str.split(':')
        @endpoint = parts[0]
        @port     = parts[1].to_i
        return str
      end

      @endpoint = str
    end

    def endpoint
      @endpoint || ENDPOINT

    end 

    private

    def check_params param_hash
      raise "missing API key" if (not param_hash.has_key?(:api_key)) || param_hash[:api_key].nil? || param_hash[:api_key].length == 0
    end

    def handle_request
      begin

        yield
      
      rescue RestClient::BadRequest => e
        if e.response.nil?
          { 'status' => 'error', 'message' => e.to_s }
        else
          JSON.parse e.response
        end

      rescue RestClient::UnprocessableEntity => e
        JSON.parse e.response

      rescue JSON::ParserError => e
        { 'status' => 'error', 'message' => e.to_s }

      end
    end

    def build_uri(path, opts = {})
      opts[:api_version] ||= API_VERSION
      
      url  = URI::HTTP.build( :host => endpoint, :path => path )
      url.port = port if port

      url
    end

  end

end
end

{'fraction_non_alphanumeric': 0.0973621103117506, 'fraction_numerical': 0.002398081534772182, 'mean_word_length': 1.7567746199603438, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '1839951', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1291, 'n_words': 353}