Class: Chimps::Commands::Test

Inherits:
Chimps::Command show all
Defined in:
lib/chimps/commands/test.rb

Overview

A command to test whether API authentication with Infochimps is working.

Constant Summary collapse

"usage: chimps test"
HELP =
"\nPrint diagnostic information on the API credentials being used by chimps\nand send a test request to Infochimps to make sure the API credentials\nwork.\n\n"

Instance Attribute Summary

Attributes inherited from Chimps::Command

#argv

Instance Method Summary collapse

Methods inherited from Chimps::Command

#initialize, name, #name

Constructor Details

This class inherits a constructor from Chimps::Command

Instance Method Details

#execute!Object

Issue the request.



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/chimps/commands/test.rb', line 23

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

#pathObject

Path to submit test requests to.



18
19
20
# File 'lib/chimps/commands/test.rb', line 18

def path
  "api_accounts/#{Chimps::CONFIG[:site][:key]}"
end