webficient-twilio 1.2.0 → 1.3.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/account.rb +1 -0
- data/lib/twilio/call.rb +7 -0
- data/lib/twilio/connection.rb +3 -3
- data/lib/twilio/incoming_phone_number.rb +2 -0
- data/lib/twilio/local_phone_number.rb +2 -0
- data/lib/twilio/notification.rb +2 -0
- data/lib/twilio/outgoing_caller_id.rb +2 -0
- data/lib/twilio/recording.rb +2 -0
- data/lib/twilio/toll_free_phone_number.rb +2 -0
- data/lib/twilio/twilio_object.rb +1 -1
- data/lib/twilio/verb.rb +63 -31
- data/test/fixtures/yml/verb_responses.yml +27 -6
- data/test/test_helper.rb +3 -3
- data/test/twilio/verb_test.rb +29 -5
- metadata +2 -2
data/VERSION.yml
CHANGED
data/lib/twilio/account.rb
CHANGED
data/lib/twilio/call.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
module Twilio
|
2
|
+
# A Call represenents a connection between a telephone and Twilio. This may be
|
3
|
+
# inbound, when a person calls your application, or outbound when your application
|
4
|
+
# initiates the call, either via the REST API, or during a call via the Dial Verb.
|
2
5
|
class Call < TwilioObject
|
6
|
+
# Example:
|
7
|
+
# c = Twilio::Connection.new('my_twilio_sid', 'my_auth_token')
|
8
|
+
# call = Twilio::Call.new(c)
|
9
|
+
# response = call.make(CALLER_ID, user_number, 'http://myapp.com/twilio_response_handler')
|
3
10
|
def make(caller, called, url, optional = {})
|
4
11
|
self.connection.class.post("/Calls", :body => {:Caller => caller, :Called => called, :Url => url}.merge(optional))
|
5
12
|
end
|
data/lib/twilio/connection.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Twilio
|
2
|
-
#The Connection class caches the Twilio API base path and authentication credentials.
|
3
|
-
#It is passed into the constructor of other TwilioObject's, avoiding the need to
|
4
|
-
#explicitly set credentials with each API call.
|
2
|
+
# The Connection class caches the Twilio API base path and authentication credentials.
|
3
|
+
# It is passed into the constructor of other TwilioObject's, avoiding the need to
|
4
|
+
# explicitly set credentials with each API call.
|
5
5
|
#
|
6
6
|
# Example:
|
7
7
|
# c = Twilio::Connection.new('my_twilio_sid', 'my_auth_token')
|
@@ -1,4 +1,6 @@
|
|
1
1
|
module Twilio
|
2
|
+
# An IncomingPhoneNumber resource represents a phone number given to you by
|
3
|
+
# Twilio to receive incoming phone calls.
|
2
4
|
class IncomingPhoneNumber < TwilioObject
|
3
5
|
def list(optional = {})
|
4
6
|
self.connection.class.get("/IncomingPhoneNumbers", :query => optional)
|
@@ -1,4 +1,6 @@
|
|
1
1
|
module Twilio
|
2
|
+
# This sub-resource represents only Local phone numbers, or in other words, not toll-free numbers.
|
3
|
+
# Also allows you to request a new local phone number be added to your account.
|
2
4
|
class LocalPhoneNumber < TwilioObject
|
3
5
|
def create(url, area_code = nil, method = 'POST', friendly_name = nil)
|
4
6
|
self.connection.class.post("/IncomingPhoneNumbers/Local", :body => {
|
data/lib/twilio/notification.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
module Twilio
|
2
|
+
# An OutgoingCallerId resource represents an outgoing Caller ID that you have
|
3
|
+
# registered with Twilio for use when making an outgoing call or using the Dial Verb.
|
2
4
|
class OutgoingCallerId < TwilioObject
|
3
5
|
def create(phone_number, friendly_name = phone_number, call_delay = 0)
|
4
6
|
self.connection.class.post("/OutgoingCallerIds", :body => {
|
data/lib/twilio/recording.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
module Twilio
|
2
|
+
# This sub-resource represents only Toll Free phone numbers, or in other words, not local numbers.
|
3
|
+
# Also allows you to request a new toll free phone number be added to your account.
|
2
4
|
class TollFreePhoneNumber < TwilioObject
|
3
5
|
def create(url, area_code = nil, method = 'POST', friendly_name = nil)
|
4
6
|
self.connection.class.post("/IncomingPhoneNumbers/TollFree", :body => {
|
data/lib/twilio/twilio_object.rb
CHANGED
data/lib/twilio/verb.rb
CHANGED
@@ -23,26 +23,32 @@ module Twilio
|
|
23
23
|
#
|
24
24
|
# Twilio::Verb.say_4_times_with_pause('Your PIN is 1 2 3 4')
|
25
25
|
#
|
26
|
-
# Optional params
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
def say(
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
26
|
+
# Optional params (see http://www.twilio.com/docs/api_reference/TwiML/say) are passed in as a hash:
|
27
|
+
#
|
28
|
+
# Twilio::Verb.say('The time is 9:35 PM.', :voice => 'woman')
|
29
|
+
# Twilio::Verb.say('The time is 9:35 PM.', {:voice => 'woman', :language => 'es'})
|
30
|
+
def say(*args, &block)
|
31
|
+
options = {:voice => 'man', :language => 'en', :loop => 1}
|
32
|
+
args.each do |arg|
|
33
|
+
case arg
|
34
|
+
when String
|
35
|
+
options[:text_to_speak] = arg
|
36
|
+
when Hash
|
37
|
+
options.merge!(arg)
|
38
|
+
else
|
39
|
+
raise ArgumentError, 'say expects String or Hash argument'
|
40
|
+
end
|
41
|
+
end
|
35
42
|
|
36
43
|
xml = Builder::XmlMarkup.new
|
37
44
|
xml.instruct!
|
38
45
|
xml.Response {
|
39
|
-
if pause
|
40
|
-
|
41
|
-
xml.Say(
|
42
|
-
xml.Pause unless i == loop_count-1
|
46
|
+
if options[:pause]
|
47
|
+
loop_with_pause(options[:loop], xml) do
|
48
|
+
xml.Say(options[:text_to_speak], :voice => options[:voice], :language => options[:language])
|
43
49
|
end
|
44
50
|
else
|
45
|
-
xml.Say(
|
51
|
+
xml.Say(options[:text_to_speak], :voice => options[:voice], :language => options[:language], :loop => options[:loop])
|
46
52
|
end
|
47
53
|
}
|
48
54
|
end
|
@@ -56,29 +62,43 @@ module Twilio
|
|
56
62
|
#
|
57
63
|
# Twilio::Verb.play_3_times_with_pause('http://foo.com/cowbell.mp3')
|
58
64
|
#
|
59
|
-
# Optional params
|
60
|
-
#
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
+
# Optional params (see http://www.twilio.com/docs/api_reference/TwiML/play) are passed in as a hash,
|
66
|
+
# however, since the Play verb only supports 'loop' as the current option, you can instead use the
|
67
|
+
# above form to keep things concise.
|
68
|
+
def play(*args, &block)
|
69
|
+
options = {:loop => 1}
|
70
|
+
args.each do |arg|
|
71
|
+
case arg
|
72
|
+
when String
|
73
|
+
options[:audio_url] = arg
|
74
|
+
when Hash
|
75
|
+
options.merge!(arg)
|
76
|
+
else
|
77
|
+
raise ArgumentError, 'play expects String or Hash argument'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
65
81
|
xml = Builder::XmlMarkup.new
|
66
82
|
xml.instruct!
|
67
83
|
xml.Response {
|
68
|
-
if pause
|
69
|
-
|
70
|
-
xml.Play(audio_url)
|
71
|
-
xml.Pause unless i == loop_count-1
|
84
|
+
if options[:pause]
|
85
|
+
loop_with_pause(options[:loop], xml) do
|
86
|
+
xml.Play(options[:audio_url])
|
72
87
|
end
|
73
88
|
else
|
74
|
-
xml.Play(audio_url, :loop =>
|
89
|
+
xml.Play(options[:audio_url], :loop => options[:loop])
|
75
90
|
end
|
76
91
|
}
|
77
92
|
end
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
93
|
+
|
94
|
+
def gather(*args, &block)
|
95
|
+
options = args.shift
|
96
|
+
|
97
|
+
xml = Builder::XmlMarkup.new
|
98
|
+
xml.instruct!
|
99
|
+
xml.Response {
|
100
|
+
xml.Gather(options)
|
101
|
+
}
|
82
102
|
end
|
83
103
|
|
84
104
|
#Not yet implemented
|
@@ -90,15 +110,27 @@ module Twilio
|
|
90
110
|
def dial(phone_number, options = {})
|
91
111
|
raise NotImplementedError.new 'Not yet implemented - coming soon'
|
92
112
|
end
|
93
|
-
|
113
|
+
|
94
114
|
def method_missing(method_id, *args) #:nodoc:
|
95
115
|
if match = /(say|play|gather|record|dial)_(\d+)_times(_with_pause$*)/.match(method_id.to_s)
|
96
116
|
verb = match.captures.first
|
97
117
|
how_many_times = match.captures[1]
|
98
118
|
pause = match.captures[2] == '_with_pause'
|
99
|
-
self.send(verb, args.first, { :loop => how_many_times, :pause => pause})
|
119
|
+
self.send(verb, args.first, { :loop => Integer(how_many_times), :pause => pause})
|
120
|
+
else
|
121
|
+
raise NoMethodError.new("Method --- #{method_id} --- not found")
|
100
122
|
end
|
101
123
|
end
|
124
|
+
|
125
|
+
private
|
126
|
+
|
127
|
+
def loop_with_pause(loop_count, xml, &verb_action)
|
128
|
+
last_iteration = loop_count-1
|
129
|
+
loop_count.times do |i|
|
130
|
+
yield verb_action
|
131
|
+
xml.Pause unless i == last_iteration
|
132
|
+
end
|
133
|
+
end
|
102
134
|
end
|
103
135
|
end
|
104
136
|
end
|
@@ -1,14 +1,17 @@
|
|
1
1
|
say_hi:
|
2
|
-
response: <?xml version="1.0" encoding="UTF-8"?><Response><Say loop="1" language="en" voice="
|
2
|
+
response: <?xml version="1.0" encoding="UTF-8"?><Response><Say loop="1" language="en" voice="man">hi</Say></Response>
|
3
3
|
|
4
|
-
|
5
|
-
response: <?xml version="1.0" encoding="UTF-8"?><Response><Say loop="1" language="
|
4
|
+
say_hi_with_female_voice:
|
5
|
+
response: <?xml version="1.0" encoding="UTF-8"?><Response><Say loop="1" language="en" voice="woman">hi</Say></Response>
|
6
|
+
|
7
|
+
say_hi_in_spanish_with_female_voice:
|
8
|
+
response: <?xml version="1.0" encoding="UTF-8"?><Response><Say loop="1" language="es" voice="woman">hola</Say></Response>
|
6
9
|
|
7
10
|
say_hi_three_times:
|
8
|
-
response: <?xml version="1.0" encoding="UTF-8"?><Response><Say loop="3" language="en" voice="
|
11
|
+
response: <?xml version="1.0" encoding="UTF-8"?><Response><Say loop="3" language="en" voice="man">hi</Say></Response>
|
9
12
|
|
10
13
|
say_hi_three_times_with_pause:
|
11
|
-
response: <?xml version="1.0" encoding="UTF-8"?><Response><Say language="en" voice="
|
14
|
+
response: <?xml version="1.0" encoding="UTF-8"?><Response><Say language="en" voice="man">hi</Say><Pause/><Say language="en" voice="man">hi</Say><Pause/><Say language="en" voice="man">hi</Say></Response>
|
12
15
|
|
13
16
|
play_mp3:
|
14
17
|
response: <?xml version="1.0" encoding="UTF-8"?><Response><Play loop="1">http://foo.com/cowbell.mp3</Play></Response>
|
@@ -17,4 +20,22 @@ play_mp3_two_times:
|
|
17
20
|
response: <?xml version="1.0" encoding="UTF-8"?><Response><Play loop="2">http://foo.com/cowbell.mp3</Play></Response>
|
18
21
|
|
19
22
|
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>
|
23
|
+
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>
|
24
|
+
|
25
|
+
gather:
|
26
|
+
response: <?xml version="1.0" encoding="UTF-8"?><Response><Gather></Gather></Response>
|
27
|
+
|
28
|
+
gather_with_action:
|
29
|
+
response: <?xml version="1.0" encoding="UTF-8"?><Response><Gather action="http://foobar.com"/></Response>
|
30
|
+
|
31
|
+
gather_with_get_method:
|
32
|
+
response: <?xml version="1.0" encoding="UTF-8"?><Response><Gather method="GET"/></Response>
|
33
|
+
|
34
|
+
gather_with_timeout:
|
35
|
+
response: <?xml version="1.0" encoding="UTF-8"?><Response><Gather timeout="10"/></Response>
|
36
|
+
|
37
|
+
gather_with_finish_key:
|
38
|
+
response: <?xml version="1.0" encoding="UTF-8"?><Response><Gather finishOnKey="*"/></Response>
|
39
|
+
|
40
|
+
gather_with_num_digits:
|
41
|
+
response: <?xml version="1.0" encoding="UTF-8"?><Response><Gather numDigits="5"/></Response>
|
data/test/test_helper.rb
CHANGED
@@ -14,16 +14,16 @@ require 'twilio'
|
|
14
14
|
class Test::Unit::TestCase #:nodoc: all
|
15
15
|
end
|
16
16
|
|
17
|
-
def fixture(filename)
|
17
|
+
def fixture(filename) #:nodoc:
|
18
18
|
path = File.join(File.dirname(__FILE__), "fixtures/xml/#{filename}.xml")
|
19
19
|
File.read path
|
20
20
|
end
|
21
21
|
|
22
|
-
def twilio_url(url=nil)
|
22
|
+
def twilio_url(url=nil) #:nodoc:
|
23
23
|
"https://mysid:mytoken@api.twilio.com:443/2008-08-01/Accounts/mysid#{'/' + url if url}"
|
24
24
|
end
|
25
25
|
|
26
|
-
def verb_response(verb)
|
26
|
+
def verb_response(verb) #:nodoc:
|
27
27
|
path = File.join(File.dirname(__FILE__), "fixtures/yml/verb_responses.yml")
|
28
28
|
YAML.load_file(path)[verb.to_s]['response']
|
29
29
|
end
|
data/test/twilio/verb_test.rb
CHANGED
@@ -5,9 +5,13 @@ class VerbTest < Test::Unit::TestCase #:nodoc: all
|
|
5
5
|
should "say 'hi'" do
|
6
6
|
assert_equal verb_response(:say_hi), Twilio::Verb.say('hi')
|
7
7
|
end
|
8
|
-
|
9
|
-
should "say '
|
10
|
-
assert_equal verb_response(:
|
8
|
+
|
9
|
+
should "say 'hi' with female voice" do
|
10
|
+
assert_equal verb_response(:say_hi_with_female_voice), Twilio::Verb.say('hi', :voice => 'woman')
|
11
|
+
end
|
12
|
+
|
13
|
+
should "say 'hola' in Spanish with female voice" do
|
14
|
+
assert_equal verb_response(:say_hi_in_spanish_with_female_voice), Twilio::Verb.say('hola', {:voice => 'woman', :language => 'es'})
|
11
15
|
end
|
12
16
|
|
13
17
|
should "say 'hi' three times" do
|
@@ -30,8 +34,28 @@ class VerbTest < Test::Unit::TestCase #:nodoc: all
|
|
30
34
|
assert_equal verb_response(:play_mp3_two_times_with_pause), Twilio::Verb.play_2_times_with_pause('http://foo.com/cowbell.mp3')
|
31
35
|
end
|
32
36
|
|
33
|
-
should "
|
34
|
-
|
37
|
+
should "gather" do
|
38
|
+
assert_equal verb_response(:gather), Twilio::Verb.gather
|
39
|
+
end
|
40
|
+
|
41
|
+
should "gather with action" do
|
42
|
+
assert_equal verb_response(:gather_with_action), Twilio::Verb.gather(:action => 'http://foobar.com')
|
43
|
+
end
|
44
|
+
|
45
|
+
should "gather with GET method" do
|
46
|
+
assert_equal verb_response(:gather_with_get_method), Twilio::Verb.gather(:method => 'GET')
|
47
|
+
end
|
48
|
+
|
49
|
+
should "gather with timeout" do
|
50
|
+
assert_equal verb_response(:gather_with_timeout), Twilio::Verb.gather(:timeout => 10)
|
51
|
+
end
|
52
|
+
|
53
|
+
should "gather with finish key" do
|
54
|
+
assert_equal verb_response(:gather_with_finish_key), Twilio::Verb.gather(:finishOnKey => '*')
|
55
|
+
end
|
56
|
+
|
57
|
+
should "gather with num digits" do
|
58
|
+
assert_equal verb_response(:gather_with_num_digits), Twilio::Verb.gather(:numDigits => 5)
|
35
59
|
end
|
36
60
|
|
37
61
|
should "raise not implemented error with record" do
|
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.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Phil Misiowiec
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-21 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|