bin/sms in clickatell-0.2.0 vs bin/sms in clickatell-0.3.0
- old
+ new
@@ -14,33 +14,41 @@
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
+begin
+ if options.show_balance
+ puts "Retrieving account balance..."
+ puts "You have #{connection.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)
+ puts "Status: #{Clickatell::API::MessageStatus[status]} (##{status})."
+ exit 0
+ else
puts "Sending '#{options.message}' to #{options.recipient}..."
- connection.send_message(options.recipient, options.message)
- puts "Done."
+ additional_opts = {}
+ additional_opts[:from] = options.from if options.from
+ msg_id = connection.send_message(options.recipient, options.message, additional_opts)
+ puts "Message sent successfully (message id: #{msg_id})."
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
+
+rescue Clickatell::API::Error => e
+ case e.code
+ when '001', '002', '003', '005', '108'
+ 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
\ No newline at end of file