Permalink
Browse files

Added SMS Support

  • Loading branch information...
1 parent 940901b commit 800c90647038c503087866c06651438f28370ac7 Kyle Conroy committed Jan 11, 2010
Showing with 43 additions and 2 deletions.
  1. +11 −1 lib/twiliolib.rb
  2. +32 −1 tests/response_spec.rb
View
@@ -283,6 +283,10 @@ def addNumber(number, opts = {})
def addConference(room, opts = {})
append Twilio::Conference.new(room, opts)
end
+
+ def addSms(msg, opts = {})
+ append Twilio::Sms.new(msg, opts)
+ end
end
@@ -346,11 +350,17 @@ class Conference
include Twilio::Verb
attributes :muted, :beep, :startConferenceOnEnter, :endConferenceOnExit, :waitUrl, :waitMethod
end
+
+ class Sms
+ extend Twilio::Verb::ClassMethods
+ include Twilio::Verb
+ attributes :to, :from, :statusCallback, :action, :method
+ end
class Response
extend Twilio::Verb::ClassMethods
include Twilio::Verb
- allowed_verbs :say, :play, :gather, :record, :dial, :redirect, :pause, :hangup
+ allowed_verbs :say, :play, :gather, :record, :dial, :redirect, :pause, :hangup, :sms
end
# Twilio Utility function and Request Validation class
View
@@ -1,4 +1,4 @@
-require 'twiliolib'
+require '../lib/twiliolib.rb'
module AccountExampleHelperMethods
@@ -13,6 +13,8 @@ def bad_append(verb)
lambda {verb.append(Twilio::Hangup)}.should raise_error(ArgumentError)
lambda {verb.append(Twilio::Pause)}.should raise_error(ArgumentError)
lambda {verb.append(Twilio::Number)}.should raise_error(ArgumentError)
+ lambda {verb.append(Twilio::Sms)}.should raise_error(ArgumentError)
+ lambda {verb.append(Twilio::Conference)}.should raise_error(ArgumentError)
end
@@ -237,6 +239,35 @@ def bad_attr(verb)
end
+describe Twilio::Sms do
+ include AccountExampleHelperMethods
+
+ it "should send a sms message" do
+ @r = Twilio::Response.new
+ @r.append(Twilio::Sms.new("Hello, World"))
+ @r.respond.should == '<Response><Sms>Hello, World</Sms></Response>'
+ end
+
+ it "convenience: should send a sms message" do
+ @r = Twilio::Response.new
+ @r.addSms "Hello, World"
+ @r.respond.should == '<Response><Sms>Hello, World</Sms></Response>'
+ end
+
+ it "should raises exceptions for wrong appending" do
+ @r = Twilio::Response.new
+ @s = @r.append(Twilio::Sms.new("Hello World"))
+ bad_append @s
+ end
+
+ it "add attribute" do
+ @r = Twilio::Sms.new
+ @r.set :foo => 'bar'
+ @r.respond.should == '<Sms foo="bar"></Sms>'
+ end
+
+end
+
describe Twilio::Pause do
include AccountExampleHelperMethods

0 comments on commit 800c906

Please sign in to comment.