webficient-twilio 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
+ :minor: 2
2
3
  :patch: 0
3
4
  :major: 1
4
- :minor: 1
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, :loop => 1)
16
- xml.Pause unless i+1 == loop_count
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
- raise NotImplementedError.new 'Not yet implemented - coming soon'
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 loop="1" language="en" voice="woman">hi</Say><Pause/><Say loop="1" language="en" voice="woman">hi</Say><Pause/><Say loop="1" language="en" voice="woman">hi</Say></Response>
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
@@ -11,7 +11,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
11
11
  $LOAD_PATH.unshift(File.dirname(__FILE__))
12
12
  require 'twilio'
13
13
 
14
- class Test::Unit::TestCase
14
+ class Test::Unit::TestCase #:nodoc: all
15
15
  end
16
16
 
17
17
  def fixture(filename)
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
- class AccountTest < Test::Unit::TestCase
3
+ class AccountTest < Test::Unit::TestCase #:nodoc: all
4
4
  context "An account" 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 CallTest < Test::Unit::TestCase
3
+ class CallTest < Test::Unit::TestCase #:nodoc: all
4
4
  context "A call" 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 ConnectionTest < Test::Unit::TestCase
3
+ class ConnectionTest < Test::Unit::TestCase #:nodoc: all
4
4
  context "A Twilio connection" 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 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 NotificationTest < Test::Unit::TestCase
3
+ class NotificationTest < Test::Unit::TestCase #:nodoc: all
4
4
  context "A recording" 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 RecordingTest < Test::Unit::TestCase
3
+ class RecordingTest < Test::Unit::TestCase #:nodoc: all
4
4
  context "A recording" 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')
@@ -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 'Hi'" do
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 'Hi' three times" do
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 'Hi' three times with pause" do
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 "raise not implemented error with play" do
18
- assert_raise(NotImplementedError) { Twilio::Verb.play('something') }
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webficient-twilio
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phil Misiowiec