<commit_before># encoding: utf-8
module Ayadn
  class CNX

    def self.get_response_from(url)
      begin
        RestClient.get(url) do |response, request, result| #, :verify_ssl => OpenSSL::SSL::VERIFY_NONE
          check(response)
        end
      rescue SocketError => e
        puts "\nConnection error.".color(:red)
        Errors.global_error("cnx.rb/get", url, e)
      rescue SystemCallError => e
        puts "\nConnection error.".color(:red)
        Errors.global_error("cnx.rb/get", url, e)
      rescue => e
        Errors.global_error("cnx.rb/get", url, e)
      end
    end

    def self.check(response)
      case response.code
      when 200
        response
      when 204
        puts "\n'No content'".color(:red)
        Errors.global_error("cnx.rb", response.headers, "NO CONTENT")
      when 400
        puts "\n'Bad request'".color(:red)
        Errors.global_error("cnx.rb", response.headers, "BAD REQUEST")
      when 401
        puts "\n'Unauthorized'".color(:red)
        Errors.global_error("cnx.rb", response.headers, "UNAUTHORIZED")
      when 403
        puts "\n'Forbidden'".color(:red)
        Errors.global_error("cnx.rb", response.headers, "FORBIDDEN")
      when 405
        puts "\n'Method not allowed'".color(:red)
        Errors.global_error("cnx.rb", response.headers, "METHOD NOT ALLOWED")
      when 429
        puts "\n'Too many requests'".color(:red)
        puts "\n\nAyadn made too many requests to the App.net API. You should wait at least ".color(:cyan) + "#{response.headers[:retry_after]} ".color(:red) + "seconds before trying again. Maybe you launched a lot of Ayadn instances at the same time? That's no problem, but in this case you should increase the value of the scroll timer (do `ayadn set scroll timer 2.5` for example).".color(:cyan)
        Errors.global_error("cnx.rb", response.headers, "TOO MANY REQUESTS")
      when 500
        puts "\n'App.net server error'".color(:red)
        Errors.global_error("cnx.rb", response.headers, "APP.NET SERVER ERROR")
      when 507
        puts "\n'Insufficient storage'".color(:red)
        Errors.global_error("cnx.rb", response.headers, "INSUFFICIENT STORAGE")
      else
        response
      end
    end<commit_msg>better alert message if 429<commit_after># encoding: utf-8
module Ayadn
  class CNX

    def self.get_response_from(url)
      begin
        RestClient.get(url) do |response, request, result| #, :verify_ssl => OpenSSL::SSL::VERIFY_NONE
          check(response)
        end
      rescue SocketError => e
        puts "\nConnection error.".color(:red)
        Errors.global_error("cnx.rb/get", url, e)
      rescue SystemCallError => e
        puts "\nConnection error.".color(:red)
        Errors.global_error("cnx.rb/get", url, e)
      rescue => e
        Errors.global_error("cnx.rb/get", url, e)
      end
    end

    def self.check(response)
      case response.code
      when 200
        response
      when 204
        puts "\n'No content'".color(:red)
        Errors.global_error("cnx.rb", response.headers, "NO CONTENT")
      when 400
        puts "\n'Bad request'".color(:red)
        Errors.global_error("cnx.rb", response.headers, "BAD REQUEST")
      when 401
        puts "\n'Unauthorized'".color(:red)
        Errors.global_error("cnx.rb", response.headers, "UNAUTHORIZED")
      when 403
        puts "\n'Forbidden'".color(:red)
        Errors.global_error("cnx.rb", response.headers, "FORBIDDEN")
      when 405
        puts "\n'Method not allowed'".color(:red)
        Errors.global_error("cnx.rb", response.headers, "METHOD NOT ALLOWED")
      when 429
        puts "\n'Too many requests'".color(:red)
        puts "\n\nAyadn made too many requests to the App.net API. You should wait at least ".color(:cyan) + "#{response.headers[:retry_after]} ".color(:red) + "seconds before trying again. Maybe you launched a lot of Ayadn instances at the same time? That's no problem, but in this case you should increase the value of the scroll timer (with `ayadn set scroll timer 5` for example). App.net allows 5000 requests per hour per account maximum.".color(:cyan)
        Errors.global_error("cnx.rb", response.headers, "TOO MANY REQUESTS")
      when 500
        puts "\n'App.net server error'".color(:red)
        Errors.global_error("cnx.rb", response.headers, "APP.NET SERVER ERROR")
      when 507
        puts "\n'Insufficient storage'".color(:red)
        Errors.global_error("cnx.rb", response.headers, "INSUFFICIENT STORAGE")
      else
        response
      end
    end
{'fraction_non_alphanumeric': 0.12535927481759893, 'fraction_numerical': 0.01459208489940305, 'mean_word_length': 2.687041564792176, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '3168813', 'n_tokens_mistral': 1477, 'n_tokens_neox': 1406, 'n_words': 386}