(c) 2009 Jason Frame [firstname.lastname@example.org]
Like ActionMailer, but for (outgoing) SMS, featuring pluggable adapters for different SMS gateways. Currently only supports iTAGG but writing a new adapter for your new provider should be quick and easy.
Warning - it's a little rough round the edges.
TxtMachine.configure( :gateway => TxtMachine::Gateways::Itagg, :username => "username", :password => "password", :originator => "Captain Haddock" ) # Send a single message TxtMachine.send_message("Message body", :to => "07123456789") # Send a single message, alternative syntax TxtMachine.send_message(:to => "07123456789", :body => "Message body") # Send message to multiple recipients TxtMachine.send_message("Foobar", :to => [number1, number2, number3]) # Open a session if your adapter uses stateful connections TxtMachine.start do |tm| tm.send_message("Foobar", :to => some_number) tm.send_message("Bazbar", :to => some_other_number) tm.send_message("Bleem", :to => bob) end
Writing an adapter
TxtMachine::Gateways::Skeleton, it's probably easiest to extend this. Most
SMS gateways I've seen use HTTP so all you need to do is implement the
in your adapter to send in-place.
Like ActionMailer, TxtMachine has a test mode which pushes all delivered messages onto an array:
# Equivalent to: # TxtMachine[:gateway] = TxtMachine::Gateways::Test # TxtMachine.clear_deliveries! TxtMachine.test_mode! TxtMachine.send_message("my message", :to => [r1, r2]) assert_equal 1, TxtMachine.deliveries.length => true
Please do :) Fork away...