namespace :apikey do desc <<-DESC Reset your API key and generate a new one. The new key will be sent to you by e-mail. DESC task :reset do APIKey.put puts_title "API key reset" puts_long <<-MSG Your API key has been reset. You will receive an e-mail with your new API key shortly. After that, you will need to reconfigure this utility to use the new key, by running #{qcommand "apikey:switch"}. MSG end desc <<-DESC Change the current API key. You should use this task after #{qcommand "apikey:reset"} to use a newly generated API key. DESC task :switch do puts_title "API key" puts_long <<-MSG In order to use this utility, you must provide your API key that must have been sent to you in an e-mail after creating your account. Please paste it at the prompt below and press . MSG prompt_and_store_key end def prompt_and_store_key loop do puts print "API key: " entered = $stdin.gets.strip begin APIKey.site = APIAccess.site_with_api_key(entered) begin APIKey.get ensure APIKey.site = nil end rescue WebService::UnauthorizedAccess puts puts_long <<-MSG The key you entered apears to be invalid. Please double check it and retry, or let us help you: #{SUPPORT_EMAIL_ADDR}. MSG else Parameters.store(:api_key, entered) puts puts "* Key valid and saved." break end end end end