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

module AzkabanScheduler
  class Client
    attr_reader :http

    def initialize(url, http_options = {}, client_headers={})
      uri = URI(url)
      @client_headers = client_headers

      @http = Net::HTTP.new(uri.host, uri.port)
      @http.use_ssl = uri.scheme == 'https'

      http_options.each do |key, value|
        @http.public_send(:"#{key}=", value)
      end
    end

    def get(path, params=nil, headers={})
      path += "?#{URI.encode_www_form(params)}" if params
      req = Net::HTTP::Get.new(path)
      send_request(req, @client_headers.merge(headers))
    end

    def post(path, params=nil, headers={})
      req = Net::HTTP::Post.new(path)
      req.set_form_data(params) if params
      send_request(req, @client_headers.merge(headers))
    end

    def multipart_post(path, params, headers={})
      req = Net::HTTP::Post::Multipart.new(path, params)
      send_request(req, @client_headers.merge(headers))
    end

    private

    def send_request(request, headers)
      request['Accept'] = 'application/json'
      headers = @client_headers.merge(headers)
      headers.each { |name, value| request[name] = value } if headers<commit_msg>increase read timeout from 1 -> 3 mins<commit_after>require 'net/http'
require 'json'

module AzkabanScheduler
  class Client
    attr_reader :http

    def initialize(url, http_options = {}, client_headers={})
      uri = URI(url)
      @client_headers = client_headers

      @http = Net::HTTP.new(uri.host, uri.port, read_timeout=180)
      @http.use_ssl = uri.scheme == 'https'

      http_options.each do |key, value|
        @http.public_send(:"#{key}=", value)
      end
    end

    def get(path, params=nil, headers={})
      path += "?#{URI.encode_www_form(params)}" if params
      req = Net::HTTP::Get.new(path)
      send_request(req, @client_headers.merge(headers))
    end

    def post(path, params=nil, headers={})
      req = Net::HTTP::Post.new(path)
      req.set_form_data(params) if params
      send_request(req, @client_headers.merge(headers))
    end

    def multipart_post(path, params, headers={})
      req = Net::HTTP::Post::Multipart.new(path, params)
      send_request(req, @client_headers.merge(headers))
    end

    private

    def send_request(request, headers)
      request['Accept'] = 'application/json'
      headers = @client_headers.merge(headers)
      headers.each { |name, value| request[name] = value } if headers
{'fraction_non_alphanumeric': 0.1371520774505849, 'fraction_numerical': 0.002016942315449778, 'mean_word_length': 3.335664335664336, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, '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': '7636075', 'n_tokens_mistral': 809, 'n_tokens_neox': 792, 'n_words': 170}