<commit_before>require 'ics/commands/base'
require 'ics/request'

module ICS
  module Commands
    class Test < ICS::Command

      BANNER = "usage: ics test"
      HELP = <<EOF

Print diagnostic information on the API credentials being used by ics
and send a test request to Infochimps to make sure the API credentials
work.

EOF
      def path
        "api_accounts/#{ICS::CONFIG[:api_key]}"
      end
      
      def execute!
        puts "Reading identity file at #{CONFIG[:identity_file]}" if ICS.verbose?
        ICS::Request.new(path, :sign => true).get.print
      end

    end
  end
end
<commit_msg>Better response on 404 or 401 with ics test.<commit_after>require 'ics/commands/base'
require 'ics/request'

module ICS
  module Commands
    class Test < ICS::Command

      BANNER = "usage: ics test"
      HELP = <<EOF

Print diagnostic information on the API credentials being used by ics
and send a test request to Infochimps to make sure the API credentials
work.

EOF
      def path
        "api_accounts/#{ICS::CONFIG[:api_key]}"
      end
      
      def execute!
        puts "Reading identity file at #{CONFIG[:identity_file]}" if ICS.verbose?
        response = ICS::Request.new(path, :sign => true).get
        if response.error?
          case response.code
          when /404/ then puts "ERROR Unrecognized API key"
          when /401/ then puts "ERROR Signature does not match API key and query.  Is your secret key correct?"
          else
            nil                 # response gets printed anyway
          end
        end
        response.print
      end

    end
  end
end

{'fraction_non_alphanumeric': 0.07706650093225606, 'fraction_numerical': 0.0074580484773151025, 'mean_word_length': 2.3264462809917354, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '3481323', 'n_tokens_mistral': 476, 'n_tokens_neox': 453, 'n_words': 176}