bin/sms in clickatell-0.3.0 vs bin/sms in clickatell-0.4.0

- old
+ new

@@ -11,28 +11,34 @@ require 'rubygems' require 'clickatell' require 'clickatell/utility' end +# parse command line options options = Clickatell::Utility::Options.parse(ARGV) -connection = Clickatell::Connection.new(options.api_key, options.username, options.password) +# enable debugging if specified +Clickatell::API.debug_mode = true if options.debugging_enabled + +# authenticate and load the API +api = Clickatell::API.authenticate(options.api_key, options.username, options.password) + begin if options.show_balance puts "Retrieving account balance..." - puts "You have #{connection.account_balance} credits remaining." + puts "You have #{api.account_balance} credits remaining." exit 0 elsif options.show_status puts "Getting status of message ##{options.message_id}." - status = connection.message_status(options.message_id) + status = api.message_status(options.message_id) puts "Status: #{Clickatell::API::MessageStatus[status]} (##{status})." exit 0 else puts "Sending '#{options.message}' to #{options.recipient}..." additional_opts = {} additional_opts[:from] = options.from if options.from - msg_id = connection.send_message(options.recipient, options.message, additional_opts) + msg_id = api.send_message(options.recipient, options.message, additional_opts) puts "Message sent successfully (message id: #{msg_id})." exit 0 end rescue Clickatell::API::Error => e @@ -49,6 +55,11 @@ 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 + +rescue Timeout::Error + puts "The connection the the Clickatell service timed out" + puts "Please check your network settings and try again." + exit 1 end \ No newline at end of file