lib/twilio/verb.rb in twilio-2.5.0 vs lib/twilio/verb.rb in twilio-2.6.0
- old
+ new
@@ -7,13 +7,13 @@
#
# Twilio::Verb.say 'The time is 9:35 PM.'
#
# 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
attr_reader :response
@@ -29,11 +29,11 @@
@xml = Builder::XmlMarkup.new
@xml.instruct!
if block_given?
@chain = true
- @response = @xml.Response { instance_eval(&block) }
+ @response = @xml.Response { block.call(self) }
end
end
# The Say verb converts text to speech that is read back to the caller.
# Say is useful for dynamic text that is difficult to prerecord.
@@ -129,22 +129,22 @@
# Twilio::Verb.gather :finishOnKey => '*'
# Twilio::Verb.gather :action => 'http://foobar.com', :finishOnKey => '*'
#
# 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
}
end
@@ -183,15 +183,15 @@
# Twilio::Verb.dial '415-123-4567', :action => 'http://foobar.com'
# Twilio::Verb.dial '415-123-4567', :timeout => 10, :callerId => '858-987-6543'
#
# 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
def dial(*args, &block)
number_to_dial = ''
@@ -222,13 +222,13 @@
# with the other callers who have also connected to that room.
#
# 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
def conference(*args)
conference_name = ''
@@ -251,14 +251,14 @@
# It is normally chained with other verbs.
#
# 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)
options = args.shift
output { @xml.Pause(options) }
@@ -268,13 +268,13 @@
# It is normally chained with other verbs.
#
# 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)
redirect_to_url = ''
options = {}
@@ -299,12 +299,12 @@
#
# Twilio::Verb.hangup
#
# 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
output { @xml.Hangup }
end
\ No newline at end of file