#!/usr/bin/env ruby local_libs = [ File.join(File.dirname(__FILE__), *%w[../lib/clickatell]), File.join(File.dirname(__FILE__), *%w[../lib/clickatell/utility]) ] if File.exist?(local_libs.first) local_libs.each { |lib| require lib } else require 'rubygems' require 'clickatell' require 'clickatell/utility' end options = Clickatell::Utility::Options.parse(ARGV) connection = Clickatell::Connection.new(options.api_key, options.username, options.password) if options.show_balance puts "Retrieving account balance..." puts "You have #{connection.account_balance} credits remaining." exit 0 else begin puts "Sending '#{options.message}' to #{options.recipient}..." connection.send_message(options.recipient, options.message) puts "Done." exit 0 rescue Clickatell::API::Error => e case e.code when '001', '002', '003', '005' puts "Authentication failed. Please check your username, password and API key and try again." exit 1 when '004' puts "Your account has been frozen. Please contact Clickatell support." exit 1 when '007' puts "Requests for this API key are not permitted from this IP address." exit 1 else puts "Unexpected error occurred. #{e.message} (error code: #{e.code})." puts "Please contact the author (contact@lukeredpath.co.uk) with the above error." exit 1 end end end