Permalink
Browse files

add callback URL for sending SMS

  • Loading branch information...
Jeff Wigal
Jeff Wigal committed Mar 10, 2010
1 parent 0eaaebe commit 5e940fe3ee1c5ff4f577550922555af4e6fbb683
Showing with 23 additions and 3 deletions.
  1. +4 −3 lib/twilio/sms.rb
  2. +15 −0 test/fixtures/xml/sms_new_with_callback.xml
  3. +4 −0 test/twilio/sms_test.rb
View
@@ -4,9 +4,10 @@ module Twilio
class Sms < TwilioObject
# Example:
# Twilio.connect('my_twilio_sid', 'my_auth_token')
- # Twilio::Sms.message(CALLER_ID, user_number, 'This is my simple SMS message')
- def message(from, to, body)
- Twilio.post("/SMS/Messages", :body => {:From => from, :To => to, :Body => body})
+ # Twilio::Sms.message(CALLER_ID, user_number, 'This is my simple SMS message', 'http://example.com/sms_callback')
+ def message(from, to, body, callback_url=nil)
+ callback = callback_url ? {:StatusCallback => callback_url} : {}
+ Twilio.post("/SMS/Messages", :body => {:From => from, :To => to, :Body => body}.merge(callback))
end
def list(optional = {})
@@ -0,0 +1,15 @@
+<TwilioResponse>
+ <SMSMessage>
+ <Sid>SM872fb94e3b358913777cdb313f25b46f</Sid>
+ <DateCreated>Sun, 04 Oct 2009 03:48:08 -0700</DateCreated>
+ <DateUpdated>Sun, 04 Oct 2009 03:48:10 -0700</DateUpdated>
+ <DateSent>Sun, 04 Oct 2009 03:48:10 -0700</DateSent>
+ <AccountSid>AC5ea872f6da5a21de157d80997a64bd33</AccountSid>
+ <To>5558675309</To>
+ <From>4155551212</From>
+ <Body>Hi Jenny! Want to grab dinner?</Body>
+ <StatusCallback>http://example.com/callback</StatusCallback>
+ <Status>sent</Status>
+ <Flags>2</Flags>
+ </SMSMessage>
+</TwilioResponse>
View
@@ -10,6 +10,10 @@ class SmsTest < Test::Unit::TestCase #:nodoc: all
assert_equal stub_response(:post, :sms_new, :resource => 'SMS/Messages'),
Twilio::Sms.message('4155551212', '5558675309', 'Hi Jenny! Want to grab dinner?')
end
+ should "be messaged with a callback URL" do
+ assert_equal stub_response(:post, :sms_new_with_callback, :resource => 'SMS/Messages'),
+ Twilio::Sms.message('4155551212', '5558675309', 'Hi Jenny! Want to grab dinner?', 'http://example.com/callback')
+ end
should "be retrievable as a list" do
assert_equal stub_response(:get, :sms_messages, :resource => 'SMS/Messages'), Twilio::Sms.list

0 comments on commit 5e940fe

Please sign in to comment.