<commit_before>require 'json'
require 'net/http'
require 'ostruct'
require_relative 'core-ext/openstruct'
require_relative 'version'
require_relative 'exceptions'

module GdsApi::JsonUtils
  USER_AGENT = "GDS Api Client v. #{GdsApi::VERSION}"
  TIMEOUT = 0.5

  def do_request(url, &block)
    url = URI.parse(url)
    request = url.path
    request = request + "?" + url.query if url.query

    response = Net::HTTP.start(url.host, url.port) do |http|
      http.read_timeout = TIMEOUT
      yield http, request
    end

    if response.is_a?(Net::HTTPSuccess)
      JSON.parse(response.body)
    else
      nil
    end
  rescue Errno::ECONNREFUSED
    raise GdsApi::EndpointNotFound.new("Could not connect to #{url}")
  rescue Timeout::Error, Errno::ECONNRESET
    nil
  end<commit_msg>Make the timeout unit clear<commit_after>require 'json'
require 'net/http'
require 'ostruct'
require_relative 'core-ext/openstruct'
require_relative 'version'
require_relative 'exceptions'

module GdsApi::JsonUtils
  USER_AGENT = "GDS Api Client v. #{GdsApi::VERSION}"
  TIMEOUT_IN_SECONDS = 0.5

  def do_request(url, &block)
    url = URI.parse(url)
    request = url.path
    request = request + "?" + url.query if url.query

    response = Net::HTTP.start(url.host, url.port) do |http|
      http.read_timeout = TIMEOUT_IN_SECONDS
      yield http, request
    end

    if response.is_a?(Net::HTTPSuccess)
      JSON.parse(response.body)
    else
      nil
    end
  rescue Errno::ECONNREFUSED
    raise GdsApi::EndpointNotFound.new("Could not connect to #{url}")
  rescue Timeout::Error, Errno::ECONNRESET
    nil
  end
{'fraction_non_alphanumeric': 0.11166253101736973, 'fraction_numerical': 0.0024813895781637717, 'mean_word_length': 3.6753623188405795, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1327907', 'n_tokens_mistral': 547, 'n_tokens_neox': 552, 'n_words': 131}