lib/twilio/verb.rb in webficient-twilio-2.1.0 vs lib/twilio/verb.rb in webficient-twilio-2.2.0
- old
+ new
@@ -1,24 +1,31 @@
module Twilio
# Twilio Verbs enable your application to respond to Twilio requests (to your app) with XML responses.
# There are 5 primary verbs (say, play, gather, record, dial) and 3 secondary (hangup, pause, redirect).
# Verbs can be chained and, in some cases, nested.
#
- # If your response consists of a single verb, you can use the inline form of a new verb instance:
+ # If your response consists of a single verb, you can call a Verb class method:
#
- # Twilio::Verb.new.say('The time is 9:35 PM.')
+ # Twilio::Verb.say('The time is 9:35 PM.')
#
- # But if you need to chain several verbs together, just wrap them in a block and call the 'response' attribute:
+ # 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 { |v|
# v.dial('415-123-4567')
# v.redirect('http://www.foo.com/nextInstructions')
# }
# verb.response
class Verb
attr_reader :response
+
+ class << self
+ def method_missing(method_id, *args) #:nodoc:
+ v = Verb.new
+ v.send(method_id, *args)
+ end
+ end
def initialize(&block)
@xml = Builder::XmlMarkup.new
@xml.instruct!
@@ -30,28 +37,28 @@
# 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.
#
# Examples:
- # Twilio::Verb.new.say('The time is 9:35 PM.')
- # Twilio::Verb.new.say('The time is 9:35 PM.', :loop => 3)
+ # Twilio::Verb.say('The time is 9:35 PM.')
+ # Twilio::Verb.say('The time is 9:35 PM.', :loop => 3)
#
# With numbers, 12345 will be spoken as "twelve thousand three hundred forty five" while
# 1 2 3 4 5 will be spoken as "one two three four five."
#
- # Twilio::Verb.new.say('Your PIN is 1234', :loop => 4)
- # Twilio::Verb.new.say('Your PIN is 1 2 3 4', :loop => 4)
+ # Twilio::Verb.say('Your PIN is 1234', :loop => 4)
+ # Twilio::Verb.say('Your PIN is 1 2 3 4', :loop => 4)
#
# If you need a longer pause between each loop, instead of explicitly calling the Pause
# verb within a block, you can set the convenient pause option:
#
- # Twilio::Verb.new.say('Your PIN is 1 2 3 4', :loop => 4, :pause => true)
+ # Twilio::Verb.say('Your PIN is 1 2 3 4', :loop => 4, :pause => true)
#
# Options (see http://www.twilio.com/docs/api_reference/TwiML/say) are passed in as a hash:
#
- # Twilio::Verb.new.say('The time is 9:35 PM.', :voice => 'woman')
- # Twilio::Verb.new.say('The time is 9:35 PM.', {:voice => 'woman', :language => 'es'})
+ # Twilio::Verb.say('The time is 9:35 PM.', :voice => 'woman')
+ # Twilio::Verb.say('The time is 9:35 PM.', {:voice => 'woman', :language => 'es'})
def say(*args)
options = {:voice => 'man', :language => 'en', :loop => 1}
args.each do |arg|
case arg
when String
@@ -74,17 +81,17 @@
}
end
# The Play verb plays an audio URL back to the caller.
# Examples:
- # Twilio::Verb.new.play('http://foo.com/cowbell.mp3')
- # Twilio::Verb.new.play('http://foo.com/cowbell.mp3', :loop => 3)
+ # Twilio::Verb.play('http://foo.com/cowbell.mp3')
+ # Twilio::Verb.play('http://foo.com/cowbell.mp3', :loop => 3)
#
# If you need a longer pause between each loop, instead of explicitly calling the Pause
# verb within a block, you can set the convenient pause option:
#
- # Twilio::Verb.new.play('http://foo.com/cowbell.mp3', :loop => 3, :pause => true)
+ # Twilio::Verb.play('http://foo.com/cowbell.mp3', :loop => 3, :pause => true)
#
# Options (see http://www.twilio.com/docs/api_reference/TwiML/play) are passed in as a hash,
# but only 'loop' is currently supported.
def play(*args)
options = {:loop => 1}
@@ -115,14 +122,14 @@
# as either a HTTP GET or POST request, just like a web browser submits data from an HTML form.
#
# Options (see http://www.twilio.com/docs/api_reference/TwiML/gather) are passed in as a hash
#
# Examples:
- # Twilio::Verb.new.gather
- # Twilio::Verb.new.gather(:action => 'http://foobar.com')
- # Twilio::Verb.new.gather(:finishOnKey => '*')
- # Twilio::Verb.new.gather(:action => 'http://foobar.com', :finishOnKey => '*')
+ # Twilio::Verb.gather
+ # Twilio::Verb.gather(:action => 'http://foobar.com')
+ # 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 { |v|
# v.gather(:action => '/process_gather', :method => 'GET) {
@@ -148,14 +155,14 @@
# containing the audio recording.
#
# Options (see http://www.twilio.com/docs/api_reference/TwiML/record) are passed in as a hash
#
# Examples:
- # Twilio::Verb.new.record
- # Twilio::Verb.new.record(:action => 'http://foobar.com')
- # Twilio::Verb.new.record(:finishOnKey => '*')
- # Twilio::Verb.new.record(:transcribe => true, :transcribeCallback => '/handle_transcribe')
+ # Twilio::Verb.record
+ # Twilio::Verb.record(:action => 'http://foobar.com')
+ # Twilio::Verb.record(:finishOnKey => '*')
+ # Twilio::Verb.record(:transcribe => true, :transcribeCallback => '/handle_transcribe')
def record(*args)
options = args.shift
output { @xml.Record(options) }
end
@@ -170,13 +177,13 @@
# current document URL if no action is provided.
#
# Options (see http://www.twilio.com/docs/api_reference/TwiML/dial) are passed in as a hash
#
# Examples:
- # Twilio::Verb.new.dial('415-123-4567')
- # Twilio::Verb.new.dial('415-123-4567', :action => 'http://foobar.com')
- # Twilio::Verb.new.dial('415-123-4567', {:timeout => 10, :callerId => '858-987-6543'})
+ # Twilio::Verb.dial('415-123-4567')
+ # 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 { |v|
# v.dial {
@@ -257,10 +264,10 @@
# The Hangup (secondary) verb ends the call.
#
# Examples:
# If your response is only a hangup:
#
- # Twilio::Verb.new.hangup
+ # Twilio::Verb.hangup
#
# If your response is chained:
#
# verb = Twilio::Verb.new { |v|
# v.say("The time is #{Time.now}")
\ No newline at end of file