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

module HttpRequest
  def self.json(key:, uri_string:)
    JSON.parse(get_request(key: key, uri_string: uri_string))
  end

  def self.get_request(key:, uri_string:)
    APICache.get(key, :cache => 60) do
      # http://stackoverflow.com/a/4581116/4765379
      url = URI.parse(uri_string)
      request = Net::HTTP::Get.new(url.to_s)
      response = Net::HTTP.start(url.host, url.port, :use_ssl => url.scheme == 'https') {|http|
        http.request(request)
      }
      if response.code.to_i >= 200 && response.code.to_i < 400
        response.body
      else
        raise APICache::InvalidResponse<commit_msg>Reduce cache time further<commit_after>require 'net/http'
require 'json'

module HttpRequest
  def self.json(key:, uri_string:)
    JSON.parse(get_request(key: key, uri_string: uri_string))
  end

  def self.get_request(key:, uri_string:)
    APICache.get(key, :cache => 30) do
      # http://stackoverflow.com/a/4581116/4765379
      url = URI.parse(uri_string)
      request = Net::HTTP::Get.new(url.to_s)
      response = Net::HTTP.start(url.host, url.port, :use_ssl => url.scheme == 'https') {|http|
        http.request(request)
      }
      if response.code.to_i >= 200 && response.code.to_i < 400
        response.body
      else
        raise APICache::InvalidResponse
{'fraction_non_alphanumeric': 0.13859910581222057, 'fraction_numerical': 0.03278688524590164, 'mean_word_length': 3.170807453416149, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6627604', 'n_tokens_mistral': 499, 'n_tokens_neox': 460, 'n_words': 88}