webficient-twilio 1.0.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/lib/twilio/verb.rb +60 -6
- data/test/fixtures/yml/verb_responses.yml +14 -2
- data/test/test_helper.rb +1 -1
- data/test/twilio/account_test.rb +1 -1
- data/test/twilio/call_test.rb +1 -1
- data/test/twilio/connection_test.rb +1 -1
- data/test/twilio/incoming_phone_number_test.rb +1 -1
- data/test/twilio/local_phone_number_test.rb +1 -1
- data/test/twilio/notification_test.rb +1 -1
- data/test/twilio/outgoing_caller_id_test.rb +1 -1
- data/test/twilio/recording_test.rb +1 -1
- data/test/twilio/toll_free_phone_number_test.rb +1 -1
- data/test/twilio/verb_test.rb +18 -6
- metadata +1 -1
data/VERSION.yml
CHANGED
data/lib/twilio/verb.rb
CHANGED
@@ -1,19 +1,45 @@
|
|
1
1
|
module Twilio
|
2
|
+
# Twilio Verbs enable your application to respond to Twilio requests (to your app) with XML responses.
|
3
|
+
#
|
4
|
+
# In addition to the 5 verbs supported by Twilio (say, play, gather, record, dial),
|
5
|
+
# this class also implements dynamic interfaces that allow you to combine useful
|
6
|
+
# operations into a single call. See below methods for examples.
|
2
7
|
class Verb
|
3
8
|
class << self
|
9
|
+
# The Say verb converts text to speech that is read back to the caller.
|
10
|
+
# Say is useful for dynamic text that is difficult to prerecord.
|
11
|
+
#
|
12
|
+
# Examples:
|
13
|
+
# Twilio::Verb.say('The time is 9:35 PM.')
|
14
|
+
# Twilio::Verb.say_3_times('The time is 9:35 PM.')
|
15
|
+
#
|
16
|
+
# With numbers, 12345 will be spoken as "twelve thousand three hundred forty five" while
|
17
|
+
# 1 2 3 4 5 will be spoken as "one two three four five."
|
18
|
+
#
|
19
|
+
# Twilio::Verb.say_4_times('Your PIN is 1234')
|
20
|
+
# Twilio::Verb.say_4_times('Your PIN is 1 2 3 4')
|
21
|
+
#
|
22
|
+
# If you need a longer pause between each loop, use the pause form:
|
23
|
+
#
|
24
|
+
# Twilio::Verb.say_4_times_with_pause('Your PIN is 1 2 3 4')
|
25
|
+
#
|
26
|
+
# Optional params passed in as a hash (see http://www.twilio.com/docs/api_reference/TwiML/say):
|
27
|
+
# voice: (woman) man
|
28
|
+
# language: (en) es fr de
|
29
|
+
# loop: >= 0 (1)
|
4
30
|
def say(text, options = {})
|
5
31
|
voice = options[:voice] || 'woman'
|
6
|
-
language = options[:language] || 'en'
|
32
|
+
language = options[:language] || 'en'
|
7
33
|
loop_count = Integer(options[:loop] || 1)
|
8
34
|
pause = options[:pause]
|
9
35
|
|
10
36
|
xml = Builder::XmlMarkup.new
|
11
37
|
xml.instruct!
|
12
38
|
xml.Response {
|
13
|
-
if pause
|
39
|
+
if pause
|
14
40
|
loop_count.times do |i|
|
15
|
-
xml.Say(text, :voice => voice, :language => language
|
16
|
-
xml.Pause unless i
|
41
|
+
xml.Say(text, :voice => voice, :language => language)
|
42
|
+
xml.Pause unless i == loop_count-1
|
17
43
|
end
|
18
44
|
else
|
19
45
|
xml.Say(text, :voice => voice, :language => language, :loop => loop_count)
|
@@ -21,23 +47,51 @@ module Twilio
|
|
21
47
|
}
|
22
48
|
end
|
23
49
|
|
50
|
+
# The Play verb plays an audio URL back to the caller.
|
51
|
+
# Examples:
|
52
|
+
# Twilio::Verb.play('http://foo.com/cowbell.mp3')
|
53
|
+
# Twilio::Verb.play_3_times('http://foo.com/cowbell.mp3')
|
54
|
+
#
|
55
|
+
# If you need a longer pause between each loop, use the pause form:
|
56
|
+
#
|
57
|
+
# Twilio::Verb.play_3_times_with_pause('http://foo.com/cowbell.mp3')
|
58
|
+
#
|
59
|
+
# Optional params passed in as a hash (see http://www.twilio.com/docs/api_reference/TwiML/play):
|
60
|
+
# loop: >= 0 (1)
|
24
61
|
def play(audio_url, options = {})
|
25
|
-
|
62
|
+
loop_count = Integer(options[:loop] || 1)
|
63
|
+
pause = options[:pause]
|
64
|
+
|
65
|
+
xml = Builder::XmlMarkup.new
|
66
|
+
xml.instruct!
|
67
|
+
xml.Response {
|
68
|
+
if pause
|
69
|
+
loop_count.times do |i|
|
70
|
+
xml.Play(audio_url)
|
71
|
+
xml.Pause unless i == loop_count-1
|
72
|
+
end
|
73
|
+
else
|
74
|
+
xml.Play(audio_url, :loop => loop_count)
|
75
|
+
end
|
76
|
+
}
|
26
77
|
end
|
27
78
|
|
79
|
+
#Not yet implemented
|
28
80
|
def gather(options = {})
|
29
81
|
raise NotImplementedError.new 'Not yet implemented - coming soon'
|
30
82
|
end
|
31
83
|
|
84
|
+
#Not yet implemented
|
32
85
|
def record(options = {})
|
33
86
|
raise NotImplementedError.new 'Not yet implemented - coming soon'
|
34
87
|
end
|
35
88
|
|
89
|
+
#Not yet implemented
|
36
90
|
def dial(phone_number, options = {})
|
37
91
|
raise NotImplementedError.new 'Not yet implemented - coming soon'
|
38
92
|
end
|
39
93
|
|
40
|
-
def method_missing(method_id, *args)
|
94
|
+
def method_missing(method_id, *args) #:nodoc:
|
41
95
|
if match = /(say|play|gather|record|dial)_(\d+)_times(_with_pause$*)/.match(method_id.to_s)
|
42
96
|
verb = match.captures.first
|
43
97
|
how_many_times = match.captures[1]
|
@@ -1,8 +1,20 @@
|
|
1
1
|
say_hi:
|
2
2
|
response: <?xml version="1.0" encoding="UTF-8"?><Response><Say loop="1" language="en" voice="woman">hi</Say></Response>
|
3
|
-
|
3
|
+
|
4
|
+
say_hi_in_spanish_with_male_voice:
|
5
|
+
response: <?xml version="1.0" encoding="UTF-8"?><Response><Say loop="1" language="es" voice="man">hola</Say></Response>
|
6
|
+
|
4
7
|
say_hi_three_times:
|
5
8
|
response: <?xml version="1.0" encoding="UTF-8"?><Response><Say loop="3" language="en" voice="woman">hi</Say></Response>
|
6
9
|
|
7
10
|
say_hi_three_times_with_pause:
|
8
|
-
response: <?xml version="1.0" encoding="UTF-8"?><Response><Say
|
11
|
+
response: <?xml version="1.0" encoding="UTF-8"?><Response><Say language="en" voice="woman">hi</Say><Pause/><Say language="en" voice="woman">hi</Say><Pause/><Say language="en" voice="woman">hi</Say></Response>
|
12
|
+
|
13
|
+
play_mp3:
|
14
|
+
response: <?xml version="1.0" encoding="UTF-8"?><Response><Play loop="1">http://foo.com/cowbell.mp3</Play></Response>
|
15
|
+
|
16
|
+
play_mp3_two_times:
|
17
|
+
response: <?xml version="1.0" encoding="UTF-8"?><Response><Play loop="2">http://foo.com/cowbell.mp3</Play></Response>
|
18
|
+
|
19
|
+
play_mp3_two_times_with_pause:
|
20
|
+
response: <?xml version="1.0" encoding="UTF-8"?><Response><Play>http://foo.com/cowbell.mp3</Play><Pause/><Play>http://foo.com/cowbell.mp3</Play></Response>
|
data/test/test_helper.rb
CHANGED
data/test/twilio/account_test.rb
CHANGED
data/test/twilio/call_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
|
-
class IncomingPhoneNumberTest < Test::Unit::TestCase
|
3
|
+
class IncomingPhoneNumberTest < Test::Unit::TestCase #:nodoc: all
|
4
4
|
context "An incoming phone number" do
|
5
5
|
setup do
|
6
6
|
@connection = Twilio::Connection.new('mysid', 'mytoken')
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
|
-
class LocalPhoneNumberTest < Test::Unit::TestCase
|
3
|
+
class LocalPhoneNumberTest < Test::Unit::TestCase #:nodoc: all
|
4
4
|
context "A local phone number" do
|
5
5
|
setup do
|
6
6
|
@connection = Twilio::Connection.new('mysid', 'mytoken')
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
|
-
class OutgoingCallerIdTest < Test::Unit::TestCase
|
3
|
+
class OutgoingCallerIdTest < Test::Unit::TestCase #:nodoc: all
|
4
4
|
context "An outgoing caller id" do
|
5
5
|
setup do
|
6
6
|
@connection = Twilio::Connection.new('mysid', 'mytoken')
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
|
-
class TollFreePhoneNumberTest < Test::Unit::TestCase
|
3
|
+
class TollFreePhoneNumberTest < Test::Unit::TestCase #:nodoc: all
|
4
4
|
context "A toll free phone number" do
|
5
5
|
setup do
|
6
6
|
@connection = Twilio::Connection.new('mysid', 'mytoken')
|
data/test/twilio/verb_test.rb
CHANGED
@@ -1,23 +1,35 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
|
-
class VerbTest < Test::Unit::TestCase
|
3
|
+
class VerbTest < Test::Unit::TestCase #:nodoc: all
|
4
4
|
context "A Twilio Verb" do
|
5
|
-
should "say '
|
5
|
+
should "say 'hi'" do
|
6
6
|
assert_equal verb_response(:say_hi), Twilio::Verb.say('hi')
|
7
7
|
end
|
8
8
|
|
9
|
-
should "say '
|
9
|
+
should "say 'hola' in Spanish with male voice" do
|
10
|
+
assert_equal verb_response(:say_hi_in_spanish_with_male_voice), Twilio::Verb.say('hola', {:voice => 'man', :language => 'es'})
|
11
|
+
end
|
12
|
+
|
13
|
+
should "say 'hi' three times" do
|
10
14
|
assert_equal verb_response(:say_hi_three_times), Twilio::Verb.say_3_times('hi')
|
11
15
|
end
|
12
16
|
|
13
|
-
should "say '
|
17
|
+
should "say 'hi' three times with pause" do
|
14
18
|
assert_equal verb_response(:say_hi_three_times_with_pause), Twilio::Verb.say_3_times_with_pause('hi')
|
15
19
|
end
|
16
20
|
|
17
|
-
should "
|
18
|
-
|
21
|
+
should "play mp3 response" do
|
22
|
+
assert_equal verb_response(:play_mp3), Twilio::Verb.play('http://foo.com/cowbell.mp3')
|
19
23
|
end
|
20
24
|
|
25
|
+
should "play mp3 response two times" do
|
26
|
+
assert_equal verb_response(:play_mp3_two_times), Twilio::Verb.play_2_times('http://foo.com/cowbell.mp3')
|
27
|
+
end
|
28
|
+
|
29
|
+
should "play mp3 response two times with pause" do
|
30
|
+
assert_equal verb_response(:play_mp3_two_times_with_pause), Twilio::Verb.play_2_times_with_pause('http://foo.com/cowbell.mp3')
|
31
|
+
end
|
32
|
+
|
21
33
|
should "raise not implemented error with gather" do
|
22
34
|
assert_raise(NotImplementedError) { Twilio::Verb.gather('something') }
|
23
35
|
end
|