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

class HodException < Exception

  def initialize(json)
    @json = json
  end

  def json
    @json
  end

end

def get(api, proxy_host, proxy_port, options = {})
  make_request(api, proxy_host, proxy_port, Net::HTTP::Get, options)
end

def post(api, proxy_host, proxy_port, options = {})
  make_request(api, proxy_host, proxy_port, Net::HTTP::Post, options)
  end

def put(api, proxy_host, proxy_port, options = {})
  make_request(api, proxy_host, proxy_port, Net::HTTP::Put, options)
end

def delete(api, proxy_host, proxy_port, options = {})
  make_request(api, proxy_host, proxy_port, Net::HTTP::Delete, options)
end

def make_request(api, proxy_host, proxy_port, request_method, options = {})
  uri = URI.parse("https://api.dev.idolondemand.com/2#{api}")

  if options[:params]
    uri.query = URI.encode_www_form(options[:params])
  end

  Net::HTTP::Proxy(proxy_host, proxy_port).start(uri.host, uri.port, :use_ssl => true) do |http|
    request = request_method.new(uri.request_uri)

    if options[:apikey]
      request.add_field('apikey', options[:apikey])
    end

    if options[:token]
      request.add_field('token', options[:token])
    end

    if options[:body]<commit_msg>Fix url in Ruby client<commit_after>require 'net/http'
require 'json'

class HodException < Exception

  def initialize(json)
    @json = json
  end

  def json
    @json
  end

end

def get(api, proxy_host, proxy_port, options = {})
  make_request(api, proxy_host, proxy_port, Net::HTTP::Get, options)
end

def post(api, proxy_host, proxy_port, options = {})
  make_request(api, proxy_host, proxy_port, Net::HTTP::Post, options)
  end

def put(api, proxy_host, proxy_port, options = {})
  make_request(api, proxy_host, proxy_port, Net::HTTP::Put, options)
end

def delete(api, proxy_host, proxy_port, options = {})
  make_request(api, proxy_host, proxy_port, Net::HTTP::Delete, options)
end

def make_request(api, proxy_host, proxy_port, request_method, options = {})
  uri = URI.parse("https://api.int.havenondemand.com/2#{api}")

  if options[:params]
    uri.query = URI.encode_www_form(options[:params])
  end

  Net::HTTP::Proxy(proxy_host, proxy_port).start(uri.host, uri.port, :use_ssl => true) do |http|
    request = request_method.new(uri.request_uri)

    if options[:apikey]
      request.add_field('apikey', options[:apikey])
    end

    if options[:token]
      request.add_field('token', options[:token])
    end

    if options[:body]
{'fraction_non_alphanumeric': 0.13873295910184444, 'fraction_numerical': 0.0008019246190858059, 'mean_word_length': 4.735632183908046, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '5361987', 'n_tokens_mistral': 864, 'n_tokens_neox': 860, 'n_words': 193}