<commit_before>class LinkOracle
  class Request
    attr_reader :url

    def initialize(url)
      @url = url
    end

    def parsed_url
      validate_url
      validate_request
      results
    end

    def results
      {
        parsed_data: parsed_data,
        url: url
      }
    end

    def validate_request
      raise error_class if error_class
    end

    def validate_url
      !!URI.parse(url)
    rescue URI::InvalidURIError
      raise InvalidUrl, url
    end

    def response
      @response ||= request
    end

    def request
      c = ::Curl::Easy.new(url)
      c.follow_location = true
      begin
        c.perform
      rescue ::Curl::Err::SSLConnectError
        c.ssl_version = 3
        c.perform
      end
      c
    end

    def error_class
      return if response.response_code == 200
      {
        404 => PageNotFound,
        403 => PermissionDenied
      }[response.response_code] || BadThingsHappened
    end

    def parsed_data<commit_msg>[#70778774] set the max number of redirects so we dont get stuck<commit_after>class LinkOracle
  class Request
    attr_reader :url

    def initialize(url)
      @url = url
    end

    def parsed_url
      validate_url
      validate_request
      results
    end

    def results
      {
        parsed_data: parsed_data,
        url: url
      }
    end

    def validate_request
      raise error_class if error_class
    end

    def validate_url
      !!URI.parse(url)
    rescue URI::InvalidURIError
      raise InvalidUrl, url
    end

    def response
      @response ||= request
    end

    def request
      c = ::Curl::Easy.new(url)
      c.follow_location = true
      c.max_redirects = 100 #there will never ever be this many redirects unless it's looping. #sorrynotsorry
      begin
        c.perform
      rescue ::Curl::Err::SSLConnectError
        c.ssl_version = 3
        c.perform
      end
      c
    end

    def error_class
      return if response.response_code == 200
      {
        404 => PageNotFound,
        403 => PermissionDenied
      }[response.response_code] || BadThingsHappened
    end

    def parsed_data
{'fraction_non_alphanumeric': 0.06047819971870605, 'fraction_numerical': 0.014533520862634786, 'mean_word_length': 1.8876860622462788, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4008427', 'n_tokens_mistral': 667, 'n_tokens_neox': 620, 'n_words': 176}