Browse files

Rolled back verb nesting via instance_eval. This change made it very …

…difficult to variablize parameters to nested calls.
  • Loading branch information...
1 parent 3dfd182 commit 552723561b7ce41bab9c4129a0794336dc706a6f @alexkwolfe alexkwolfe committed Jan 20, 2010
Showing with 66 additions and 66 deletions.
  1. +3 −3 README.rdoc
  2. +27 −27 lib/twilio/verb.rb
  3. +36 −36 test/twilio/verb_test.rb
View
6 README.rdoc
@@ -28,9 +28,9 @@ For example, in a Ruby on Rails application, you could do the following inside a
and you can nest multiple verbs inside a block:
- verb = Twilio::Verb.new {
- say "The time is #{Time.now}"
- hangup
+ verb = Twilio::Verb.new { |v|
+ v.say "The time is #{Time.now}"
+ v.hangup
}
verb.response
View
54 lib/twilio/verb.rb
@@ -9,9 +9,9 @@ module Twilio
#
# But if you need to chain several verbs together, just wrap them in an instance block and call the 'response' attribute:
#
- # verb = Twilio::Verb.new {
- # dial '415-123-4567'
- # redirect 'http://www.foo.com/nextInstructions'
+ # verb = Twilio::Verb.new { |v|
+ # v.dial '415-123-4567'
+ # v.redirect 'http://www.foo.com/nextInstructions'
# }
# verb.response
class Verb
@@ -31,7 +31,7 @@ def initialize(&block)
if block_given?
@chain = true
- @response = @xml.Response { instance_eval(&block) }
+ @response = @xml.Response { block.call(self) }
end
end
@@ -131,18 +131,18 @@ def play(*args)
#
# Gather also lets you nest the Play, Say, and Pause verbs:
#
- # verb = Twilio::Verb.new {
- # gather(:action => '/process_gather', :method => 'GET) {
- # say 'Please enter your account number followed by the pound sign'
+ # verb = Twilio::Verb.new { |v|
+ # v.gather(:action => '/process_gather', :method => 'GET) {
+ # v.say 'Please enter your account number followed by the pound sign'
# }
- # say "We didn't receive any input. Goodbye!"
+ # v.say "We didn't receive any input. Goodbye!"
# }
# verb.response # represents the final xml output
def gather(*args, &block)
options = args.shift || {}
output {
if block_given?
- @xml.Gather(options) { block.call }
+ @xml.Gather(options) { block.call}
else
@xml.Gather(options)
end
@@ -185,11 +185,11 @@ def record(*args)
#
# Twilio also supports an alternate form in which a Number object is nested inside Dial:
#
- # verb = Twilio::Verb.new {
- # dial {
- # number '415-123-4567'
- # number '415-123-4568'
- # number '415-123-4569'
+ # verb = Twilio::Verb.new { |v|
+ # v.dial { |v|
+ # v.number '415-123-4567'
+ # v.number '415-123-4568'
+ # v.number '415-123-4569'
# }
# }
# verb.response # represents the final xml output
@@ -224,9 +224,9 @@ def dial(*args, &block)
# Options (see http://www.twilio.com/docs/api_reference/TwiML/conference) are passed in as a hash
#
# Examples:
- # verb = Twilio::Verb.new {
- # dial {
- # conference 'MyRoom', :muted => true
+ # verb = Twilio::Verb.new { |v|
+ # v.dial {
+ # v.conference 'MyRoom', :muted => true
# }
# }
# verb.response
@@ -253,10 +253,10 @@ def conference(*args)
# Options (see http://www.twilio.com/docs/api_reference/TwiML/pause) are passed in as a hash
#
# Examples:
- # verb = Twilio::Verb.new {
- # say 'greetings'
- # pause :length => 2
- # say 'have a nice day'
+ # verb = Twilio::Verb.new { |v|
+ # v.say 'greetings'
+ # v.pause :length => 2
+ # v.say 'have a nice day'
# }
# verb.response
def pause(*args)
@@ -270,9 +270,9 @@ def pause(*args)
# Options (see http://www.twilio.com/docs/api_reference/TwiML/redirect) are passed in as a hash
#
# Examples:
- # verb = Twilio::Verb.new {
- # dial '415-123-4567'
- # redirect 'http://www.foo.com/nextInstructions'
+ # verb = Twilio::Verb.new { |v|
+ # v.dial '415-123-4567'
+ # v.redirect 'http://www.foo.com/nextInstructions'
# }
# verb.response
def redirect(*args)
@@ -301,9 +301,9 @@ def redirect(*args)
#
# If your response is chained:
#
- # verb = Twilio::Verb.new {
- # say "The time is #{Time.now}"
- # hangup
+ # verb = Twilio::Verb.new { |v|
+ # v.say "The time is #{Time.now}"
+ # v.hangup
# }
# verb.response
def hangup
View
72 test/twilio/verb_test.rb
@@ -28,19 +28,19 @@ class VerbTest < Test::Unit::TestCase #:nodoc: all
end
should "say 'hi' with pause and say 'bye'" do
- verb = Twilio::Verb.new {
- say 'hi', :loop => 1
- pause
- say 'bye'
+ verb = Twilio::Verb.new { |v|
+ v.say 'hi', :loop => 1
+ v.pause
+ v.say 'bye'
}
assert_match %r{<Say( loop="1"| language="en"| voice="man"){3}>hi</Say><Pause></Pause><Say( loop="1"| language="en"| voice="man"){3}>bye</Say>}, verb.response
end
should "say 'hi' with 2 second pause and say 'bye'" do
- verb = Twilio::Verb.new {
- say 'hi'
- pause :length => 2
- say 'bye'
+ verb = Twilio::Verb.new { |v|
+ v.say 'hi'
+ v.pause :length => 2
+ v.say 'bye'
}
assert_match %r{<Say( loop="1"| language="en"| voice="man"){3}>hi</Say><Pause length="2"/><Say( loop="1"| language="en"| voice="man"){3}>bye</Say>}, verb.response
end
@@ -92,21 +92,21 @@ class VerbTest < Test::Unit::TestCase #:nodoc: all
end
should "gather and say instructions" do
- verb = Twilio::Verb.new {
- gather {
- say 'Please enter your account number followed by the pound sign'
+ verb = Twilio::Verb.new { |v|
+ v.gather {
+ v.say 'Please enter your account number followed by the pound sign'
}
- say "We didn't receive any input. Goodbye!"
+ v.say "We didn't receive any input. Goodbye!"
}
assert_match %r{<Gather><Say( loop="1"| language="en"| voice="man"){3}>Please enter your account number followed by the pound sign</Say></Gather><Say( loop="1"| language="en"| voice="man"){3}>We didn't receive any input. Goodbye!</Say>}, verb.response
end
should "gather with timeout and say instructions" do
- verb = Twilio::Verb.new {
- gather(:timeout => 10) {
- say 'Please enter your account number followed by the pound sign'
+ verb = Twilio::Verb.new { |v|
+ v.gather(:timeout => 10) {
+ v.say 'Please enter your account number followed by the pound sign'
}
- say "We didn't receive any input. Goodbye!"
+ v.say "We didn't receive any input. Goodbye!"
}
assert_match %r{<Gather timeout="10"><Say( loop="1"| language="en"| voice="man"){3}>Please enter your account number followed by the pound sign</Say></Gather><Say( loop="1"| language="en"| voice="man"){3}>We didn't receive any input. Goodbye!</Say>}, verb.response
end
@@ -174,46 +174,46 @@ class VerbTest < Test::Unit::TestCase #:nodoc: all
end
should "dial with redirect" do
- verb = Twilio::Verb.new {
- dial '415-123-4567'
- redirect 'http://www.foo.com/nextInstructions'
+ verb = Twilio::Verb.new { |v|
+ v.dial '415-123-4567'
+ v.redirect 'http://www.foo.com/nextInstructions'
}
assert_equal verb_response(:dial_with_redirect), verb.response
end
should "dial with number and send digits" do
- verb = Twilio::Verb.new {
- dial {
- number('415-123-4567', :sendDigits => 'wwww1928')
+ verb = Twilio::Verb.new { |v|
+ v.dial {
+ v.number('415-123-4567', :sendDigits => 'wwww1928')
}
}
assert_equal verb_response(:dial_with_number_and_send_digits), verb.response
end
should "dial multiple numbers" do
- verb = Twilio::Verb.new {
- dial {
- number '415-123-4567'
- number '415-123-4568'
- number '415-123-4569'
+ verb = Twilio::Verb.new { |v|
+ v.dial {
+ v.number '415-123-4567'
+ v.number '415-123-4568'
+ v.number '415-123-4569'
}
}
assert_equal verb_response(:dial_multiple_numbers), verb.response
end
should "dial a conference" do
- verb = Twilio::Verb.new {
- dial {
- conference 'MyRoom'
+ verb = Twilio::Verb.new { |v|
+ v.dial {
+ v.conference 'MyRoom'
}
}
assert_equal verb_response(:dial_conference), verb.response
end
should "dial a muted conference" do
- verb = Twilio::Verb.new {
- dial {
- conference 'MyRoom', :mute => :true
+ verb = Twilio::Verb.new { |v|
+ v.dial {
+ v.conference 'MyRoom', :mute => :true
}
}
assert_equal verb_response(:dial_muted_conference), verb.response
@@ -224,9 +224,9 @@ class VerbTest < Test::Unit::TestCase #:nodoc: all
end
should "say hi and hangup" do
- verb = Twilio::Verb.new {
- say 'hi'
- hangup
+ verb = Twilio::Verb.new { |v|
+ v.say 'hi'
+ v.hangup
}
assert_match %r{<Say( loop="1"| language="en"| voice="man"){3}>hi</Say><Hangup/>},
verb.response

0 comments on commit 5527235

Please sign in to comment.