slayer-twilio 3.0.1

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.
Files changed (65) hide show
  1. data/.gitignore +8 -0
  2. data/CHANGELOG.rdoc +31 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +20 -0
  5. data/README.rdoc +63 -0
  6. data/Rakefile +9 -0
  7. data/lib/twilio.rb +53 -0
  8. data/lib/twilio/account.rb +12 -0
  9. data/lib/twilio/available_phone_numbers.rb +56 -0
  10. data/lib/twilio/call.rb +37 -0
  11. data/lib/twilio/conference.rb +35 -0
  12. data/lib/twilio/incoming_phone_number.rb +30 -0
  13. data/lib/twilio/notification.rb +20 -0
  14. data/lib/twilio/outgoing_caller_id.rb +33 -0
  15. data/lib/twilio/recording.rb +24 -0
  16. data/lib/twilio/sms.rb +22 -0
  17. data/lib/twilio/twilio_object.rb +19 -0
  18. data/lib/twilio/verb.rb +387 -0
  19. data/lib/twilio/version.rb +3 -0
  20. data/spec/fixtures/xml/account.xml +23 -0
  21. data/spec/fixtures/xml/account_renamed.xml +11 -0
  22. data/spec/fixtures/xml/available_phone_numbers_local.xml +26 -0
  23. data/spec/fixtures/xml/available_phone_numbers_local_search.xml +15 -0
  24. data/spec/fixtures/xml/available_phone_numbers_toll_free.xml +14 -0
  25. data/spec/fixtures/xml/available_phone_numbers_toll_free_search.xml +10 -0
  26. data/spec/fixtures/xml/call.xml +18 -0
  27. data/spec/fixtures/xml/call_new.xml +14 -0
  28. data/spec/fixtures/xml/call_redirected.xml +15 -0
  29. data/spec/fixtures/xml/calls.xml +36 -0
  30. data/spec/fixtures/xml/conference.xml +10 -0
  31. data/spec/fixtures/xml/conference_participant.xml +12 -0
  32. data/spec/fixtures/xml/conference_participant_muted.xml +12 -0
  33. data/spec/fixtures/xml/conference_participants.xml +24 -0
  34. data/spec/fixtures/xml/conferences.xml +12 -0
  35. data/spec/fixtures/xml/incoming_phone_number.xml +12 -0
  36. data/spec/fixtures/xml/incoming_phone_numbers.xml +24 -0
  37. data/spec/fixtures/xml/notification.xml +19 -0
  38. data/spec/fixtures/xml/notifications.xml +32 -0
  39. data/spec/fixtures/xml/outgoing_caller_id.xml +10 -0
  40. data/spec/fixtures/xml/outgoing_caller_id_new.xml +7 -0
  41. data/spec/fixtures/xml/outgoing_caller_ids.xml +20 -0
  42. data/spec/fixtures/xml/recording.xml +10 -0
  43. data/spec/fixtures/xml/recordings.xml +20 -0
  44. data/spec/fixtures/xml/sms.xml +14 -0
  45. data/spec/fixtures/xml/sms_messages.xml +29 -0
  46. data/spec/fixtures/xml/sms_new.xml +14 -0
  47. data/spec/fixtures/xml/sms_new_with_callback.xml +15 -0
  48. data/spec/fixtures/xml/transcription.xml +13 -0
  49. data/spec/fixtures/xml/transcriptions.xml +26 -0
  50. data/spec/fixtures/yml/verb_responses.yml +86 -0
  51. data/spec/spec_helper.rb +17 -0
  52. data/spec/support/twilio_helpers.rb +52 -0
  53. data/spec/twilio/account_spec.rb +21 -0
  54. data/spec/twilio/available_phone_numbers_spec.rb +53 -0
  55. data/spec/twilio/call_spec.rb +64 -0
  56. data/spec/twilio/conference_spec.rb +58 -0
  57. data/spec/twilio/incoming_phone_number_spec.rb +42 -0
  58. data/spec/twilio/live_connection_spec.rb +21 -0
  59. data/spec/twilio/notification_spec.rb +29 -0
  60. data/spec/twilio/outgoing_caller_id_spec.rb +43 -0
  61. data/spec/twilio/recording_spec.rb +44 -0
  62. data/spec/twilio/sms_spec.rb +36 -0
  63. data/spec/twilio/verb_spec.rb +253 -0
  64. data/twilio.gemspec +30 -0
  65. metadata +258 -0
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Incoming Phone Number" do
4
+ before(:all) do
5
+ Twilio.connect('mysid', 'mytoken')
6
+ @incoming_sid = 'PNe536dfda7c6184afab78d980cb8cdf43'
7
+ end
8
+
9
+ it "gets a specific phone number" do
10
+ response, url = stub_get(:incoming_phone_number, "IncomingPhoneNumbers/#{@incoming_sid}")
11
+
12
+ Twilio::IncomingPhoneNumber.get(@incoming_sid).should == response
13
+ WebMock.should have_requested(:get, url)
14
+ end
15
+
16
+ it "gets a list of phone numbers" do
17
+ response, url = stub_get(:incoming_phone_numbers, 'IncomingPhoneNumbers')
18
+
19
+ Twilio::IncomingPhoneNumber.list.should == response
20
+ WebMock.should have_requested(:get, url)
21
+ end
22
+
23
+ context "creating" do
24
+ it "is created" do
25
+ response, url = stub_post(:incoming_phone_number, 'IncomingPhoneNumbers')
26
+
27
+ Twilio::IncomingPhoneNumber.create(:PhoneNumber => '8055551212').should == response
28
+ WebMock.should have_requested(:post, url)
29
+ end
30
+
31
+ it "raises an exception if PhoneNumber or AreaCode are not set" do
32
+ expect { Twilio::IncomingPhoneNumber.create(:FriendlyName => 'Booyah') }.to raise_exception
33
+ end
34
+ end
35
+
36
+ it "is deleted" do
37
+ response, url = stub_delete(:incoming_phone_number, "IncomingPhoneNumbers/#{@incoming_sid}")
38
+
39
+ Twilio::IncomingPhoneNumber.delete(@incoming_sid).should == response
40
+ WebMock.should have_requested(:delete, url)
41
+ end
42
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ # uncomment and add your own tests here
4
+ =begin
5
+ describe "testing with a live connection" do
6
+ before(:all) do
7
+ WebMock.allow_net_connect!
8
+ @sid = 'abc123'
9
+ @token = '123'
10
+ Twilio.connect(@sid, @token)
11
+ end
12
+
13
+ after(:all) do
14
+ WebMock.disable_net_connect!
15
+ end
16
+
17
+ it "gets real account" do
18
+ Twilio::Account.get.should include("TwilioResponse")
19
+ end
20
+ end
21
+ =end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Notification" do
4
+ before(:all) do
5
+ Twilio.connect('mysid', 'mytoken')
6
+ @notification_sid = 'NO1fb7086ceb85caed2265f17d7bf7981c'
7
+ end
8
+
9
+ it "gets a list of notifications" do
10
+ response, url = stub_get(:notifications, 'Notifications')
11
+
12
+ Twilio::Notification.list.should == response
13
+ WebMock.should have_requested(:get, url)
14
+ end
15
+
16
+ it "gets a specific notification" do
17
+ response, url = stub_get(:notification, "Notifications/#{@notification_sid}")
18
+
19
+ Twilio::Notification.get(@notification_sid).should == response
20
+ WebMock.should have_requested(:get, url)
21
+ end
22
+
23
+ it "is deleted" do
24
+ response, url = stub_delete(:notification, "Notifications/#{@notification_sid}")
25
+
26
+ Twilio::Notification.delete(@notification_sid).should == response
27
+ WebMock.should have_requested(:delete, url)
28
+ end
29
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Outgoing Caller ID" do
4
+ before(:all) do
5
+ Twilio.connect('mysid', 'mytoken')
6
+ @callerid_sid = 'PNe536dfda7c6184afab78d980cb8cdf43'
7
+ end
8
+
9
+ it "gets a list of caller id's" do
10
+ response, url = stub_get(:outgoing_caller_ids, 'OutgoingCallerIds')
11
+
12
+ Twilio::OutgoingCallerId.list.should == response
13
+ WebMock.should have_requested(:get, url)
14
+ end
15
+
16
+ it "gets a specific caller id" do
17
+ response, url = stub_get(:outgoing_caller_id, "OutgoingCallerIds/#{@callerid_sid}")
18
+
19
+ Twilio::OutgoingCallerId.get(@callerid_sid).should == response
20
+ WebMock.should have_requested(:get, url)
21
+ end
22
+
23
+ it "is created" do
24
+ response, url = stub_post(:outgoing_caller_id_new, 'OutgoingCallerIds')
25
+
26
+ Twilio::OutgoingCallerId.create('4158675309', 'My Home Phone').should == response
27
+ WebMock.should have_requested(:post, url)
28
+ end
29
+
30
+ it "is deleted" do
31
+ response, url = stub_delete(:outgoing_caller_id, "OutgoingCallerIds/#{@callerid_sid}")
32
+
33
+ Twilio::OutgoingCallerId.delete(@callerid_sid).should == response
34
+ WebMock.should have_requested(:delete, url)
35
+ end
36
+
37
+ it "updates name" do
38
+ response, url = stub_put(:outgoing_caller_id, "OutgoingCallerIds/#{@callerid_sid}")
39
+
40
+ Twilio::OutgoingCallerId.update_name(@callerid_sid, 'My office line').should == response
41
+ WebMock.should have_requested(:put, url)
42
+ end
43
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Recording" do
4
+ before(:all) do
5
+ Twilio.connect('mysid', 'mytoken')
6
+ @recording_sid = 'RE41331862605f3d662488fdafda2e175f'
7
+ @transcription_sid = 'TRbdece5b75f2cd8f6ef38e0a10f5c4447'
8
+ end
9
+
10
+ it "gets a list of recordings" do
11
+ response, url = stub_get(:recordings, 'Recordings')
12
+
13
+ Twilio::Recording.list.should == response
14
+ WebMock.should have_requested(:get, url)
15
+ end
16
+
17
+ it "gets a specific recording" do
18
+ response, url = stub_get(:recording, "Recordings/#{@recording_sid}")
19
+
20
+ Twilio::Recording.get(@recording_sid).should == response
21
+ WebMock.should have_requested(:get, url)
22
+ end
23
+
24
+ it "is deleted" do
25
+ response, url = stub_delete(:recording, "Recordings/#{@recording_sid}")
26
+
27
+ Twilio::Recording.delete(@recording_sid).should == response
28
+ WebMock.should have_requested(:delete, url)
29
+ end
30
+
31
+ it "gets a list of transcriptions" do
32
+ response, url = stub_get(:transcriptions, "Recordings/#{@recording_sid}/Transcriptions")
33
+
34
+ Twilio::Recording.transcriptions(@recording_sid).should == response
35
+ WebMock.should have_requested(:get, url)
36
+ end
37
+
38
+ it "gets a specific transcription" do
39
+ response, url = stub_get(:transcriptions, "Recordings/#{@recording_sid}/Transcriptions/#{@transcription_sid}")
40
+
41
+ Twilio::Recording.transcriptions(@recording_sid, @transcription_sid).should == response
42
+ WebMock.should have_requested(:get, url)
43
+ end
44
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe "SMS" do
4
+ before(:all) do
5
+ Twilio.connect('mysid', 'mytoken')
6
+ @sms_sid = 'SM872fb94e3b358913777cdb313f25b46f'
7
+ end
8
+
9
+ it "gets a list of SMS messages" do
10
+ response, url = stub_get(:sms_messages, 'SMS/Messages')
11
+
12
+ Twilio::Sms.list.should == response
13
+ WebMock.should have_requested(:get, url)
14
+ end
15
+
16
+ it "gets a specific SMS message" do
17
+ response, url = stub_get(:sms, "SMS/Messages/#{@sms_sid}")
18
+
19
+ Twilio::Sms.get(@sms_sid).should == response
20
+ WebMock.should have_requested(:get, url)
21
+ end
22
+
23
+ it "is created" do
24
+ response, url = stub_post(:sms_new, "SMS/Messages")
25
+
26
+ Twilio::Sms.message('4155551212', '5558675309', 'Hi Jenny! Want to grab dinner?').should == response
27
+ WebMock.should have_requested(:post, url)
28
+ end
29
+
30
+ it "is created with a callback URL" do
31
+ response, url = stub_post(:sms_new_with_callback, "SMS/Messages")
32
+
33
+ Twilio::Sms.message('4155551212', '5558675309', 'Hi Jenny! Want to grab dinner?', 'http://example.com/callback').should == response
34
+ WebMock.should have_requested(:post, url)
35
+ end
36
+ end
@@ -0,0 +1,253 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Verb" do
4
+
5
+ context "Say" do
6
+ it "says 'hi'" do
7
+ Twilio::Verb.say('hi').should match %r{<Say( loop="1"| language="en"| voice="man"){3}>hi</Say>}
8
+ end
9
+
10
+ it "says 'hi' with female voice" do
11
+ Twilio::Verb.say('hi', :voice => 'woman').should match %r{<Say( loop="1"| language="en"| voice="woman"){3}>hi</Say>}
12
+ end
13
+
14
+ it "says 'hola' in Spanish with female voice" do
15
+ Twilio::Verb.say('hola', :voice => 'woman', :language => 'es').should match %r{<Say( loop="1"| language="es"| voice="woman"){3}>hola</Say>}
16
+ end
17
+
18
+ it "says 'hi' three times" do
19
+ Twilio::Verb.say('hi', :loop => 3).should match %r{<Say( loop="3"| language="en"| voice="man"){3}>hi</Say>}
20
+ end
21
+
22
+ it "says 'hi' three times with pause" do
23
+ Twilio::Verb.say('hi', :loop => 3, :pause => true).should match %r{<Say( language="en"| voice="man"){2}>hi</Say><Pause/><Say( language="en"| voice="man"){2}>hi</Say><Pause/><Say( language="en"| voice="man"){2}>hi</Say>}
24
+ end
25
+
26
+ it "says 'hi' with pause and say 'bye'" do
27
+ verb = Twilio::Verb.new { |v|
28
+ v.say 'hi', :loop => 1
29
+ v.pause
30
+ v.say 'bye'
31
+ }.response.should match %r{<Say( loop="1"| language="en"| voice="man"){3}>hi</Say><Pause></Pause><Say( loop="1"| language="en"| voice="man"){3}>bye</Say>}
32
+ end
33
+
34
+ it "says 'hi' with 2 second pause and say 'bye'" do
35
+ verb = Twilio::Verb.new { |v|
36
+ v.say 'hi'
37
+ v.pause :length => 2
38
+ v.say 'bye'
39
+ }.response.should match %r{<Say( loop="1"| language="en"| voice="man"){3}>hi</Say><Pause length="2"/><Say( loop="1"| language="en"| voice="man"){3}>bye</Say>}
40
+ end
41
+ end
42
+
43
+ context "Play" do
44
+ it "plays mp3 response" do
45
+ Twilio::Verb.play('http://foo.com/cowbell.mp3').should == verb_response(:play_mp3)
46
+ end
47
+
48
+ it "plays mp3 response two times" do
49
+ Twilio::Verb.play('http://foo.com/cowbell.mp3', :loop => 2).should == verb_response(:play_mp3_two_times)
50
+ end
51
+
52
+ it "plays mp3 response two times with pause" do
53
+ Twilio::Verb.play('http://foo.com/cowbell.mp3', :loop => 2, :pause => true).should == verb_response(:play_mp3_two_times_with_pause)
54
+ end
55
+ end
56
+
57
+ context "Gather" do
58
+ it "gathers" do
59
+ Twilio::Verb.gather.should == verb_response(:gather)
60
+ end
61
+
62
+ it "gathers with action" do
63
+ Twilio::Verb.gather(:action => 'http://foobar.com').should == verb_response(:gather_with_action)
64
+ end
65
+
66
+ it "gathers with GET method" do
67
+ Twilio::Verb.gather(:method => 'GET').should == verb_response(:gather_with_get_method)
68
+ end
69
+
70
+ it "gathers with timeout" do
71
+ Twilio::Verb.gather(:timeout => 10).should == verb_response(:gather_with_timeout)
72
+ end
73
+
74
+ it "gathers with finish key" do
75
+ Twilio::Verb.gather(:finishOnKey => '*').should == verb_response(:gather_with_finish_key)
76
+ end
77
+
78
+ it "gathers with num digits" do
79
+ Twilio::Verb.gather(:numDigits => 5).should == verb_response(:gather_with_num_digits)
80
+ end
81
+
82
+ it "gathers with all options set" do
83
+ Twilio::Verb.gather(:action => 'http://foobar.com',
84
+ :finishOnKey => '*',
85
+ :method => 'GET',
86
+ :numDigits => 5,
87
+ :timeout => 10).should match %r{<Gather( finishOnKey="\*"| action="http://foobar.com"| method="GET"| numDigits="5"| timeout="10"){5}/>}
88
+ end
89
+
90
+ it "gathers and says instructions" do
91
+ verb = Twilio::Verb.new { |v|
92
+ v.gather {
93
+ v.say 'Please enter your account number followed by the pound sign'
94
+ }
95
+ v.say "We didn't receive any input. Goodbye!"
96
+ }.response.should match %r{<Gather><Say( loop="1"| language="en"| voice="man"){3}>Please enter your account number followed by the pound sign</Say></Gather><Say( loop="1"| language="en"| voice="man"){3}>We didn't receive any input. Goodbye!</Say>}
97
+ end
98
+
99
+ it "gathers with timeout and says instructions" do
100
+ verb = Twilio::Verb.new { |v|
101
+ v.gather(:timeout => 10) {
102
+ v.say 'Please enter your account number followed by the pound sign'
103
+ }
104
+ v.say "We didn't receive any input. Goodbye!"
105
+ }.response.should match %r{<Gather timeout="10"><Say( loop="1"| language="en"| voice="man"){3}>Please enter your account number followed by the pound sign</Say></Gather><Say( loop="1"| language="en"| voice="man"){3}>We didn't receive any input. Goodbye!</Say>}
106
+ end
107
+ end
108
+
109
+ context "Record" do
110
+ it "records" do
111
+ Twilio::Verb.record.should == verb_response(:record)
112
+ end
113
+
114
+ it "records with action" do
115
+ Twilio::Verb.record(:action => 'http://foobar.com').should == verb_response(:record_with_action)
116
+ end
117
+
118
+ it "records with GET method" do
119
+ Twilio::Verb.record(:method => 'GET').should == verb_response(:record_with_get_method)
120
+ end
121
+
122
+ it "records with timeout" do
123
+ Twilio::Verb.record(:timeout => 10).should == verb_response(:record_with_timeout)
124
+ end
125
+
126
+ it "records with finish key" do
127
+ Twilio::Verb.record(:finishOnKey => '*').should == verb_response(:record_with_finish_key)
128
+ end
129
+
130
+ it "records with max length" do
131
+ Twilio::Verb.record(:maxLength => 1800).should == verb_response(:record_with_max_length)
132
+ end
133
+
134
+ it "records with transcribe" do
135
+ Twilio::Verb.record(:transcribe => true, :transcribeCallback => '/handle_transcribe').should match %r{<Record( transcribe="true"| transcribeCallback="/handle_transcribe"){2}/>}
136
+ end
137
+ end
138
+
139
+ context "Dial" do
140
+ it "dials" do
141
+ Twilio::Verb.dial('415-123-4567').should == verb_response(:dial)
142
+ end
143
+
144
+ it "dials with action" do
145
+ Twilio::Verb.dial('415-123-4567', :action => 'http://foobar.com').should == verb_response(:dial_with_action)
146
+ end
147
+
148
+ it "dials with GET method" do
149
+ Twilio::Verb.dial('415-123-4567', :method => 'GET').should == verb_response(:dial_with_get_method)
150
+ end
151
+
152
+ it "dials with timeout" do
153
+ Twilio::Verb.dial('415-123-4567', :timeout => 10).should == verb_response(:dial_with_timeout)
154
+ end
155
+
156
+ it "dials with hangup on star" do
157
+ Twilio::Verb.dial('415-123-4567', :hangupOnStar => true).should == verb_response(:dial_with_hangup_on_star)
158
+ end
159
+
160
+ it "dials with time limit" do
161
+ Twilio::Verb.dial('415-123-4567', :timeLimit => 3600).should == verb_response(:dial_with_time_limit)
162
+ end
163
+
164
+ it "dials with caller id" do
165
+ Twilio::Verb.dial('415-123-4567', :callerId => '858-987-6543').should == verb_response(:dial_with_caller_id)
166
+ end
167
+
168
+ it "dials with timeout and caller id" do
169
+ Twilio::Verb.dial('415-123-4567', :timeout => 10, :callerId => '858-987-6543').should match %r{<Dial( timeout="10"| callerId="858-987-6543"){2}>415-123-4567</Dial>}
170
+ end
171
+
172
+ it "dials with redirect" do
173
+ verb = Twilio::Verb.new { |v|
174
+ v.dial '415-123-4567'
175
+ v.redirect 'http://www.foo.com/nextInstructions'
176
+ }.response.should == verb_response(:dial_with_redirect)
177
+ end
178
+
179
+ it "dials with number and send digits" do
180
+ verb = Twilio::Verb.new { |v|
181
+ v.dial {
182
+ v.number('415-123-4567', :sendDigits => 'wwww1928')
183
+ }
184
+ }.response.should == verb_response(:dial_with_number_and_send_digits)
185
+ end
186
+
187
+ it "dials multiple numbers" do
188
+ verb = Twilio::Verb.new { |v|
189
+ v.dial {
190
+ v.number '415-123-4567'
191
+ v.number '415-123-4568'
192
+ v.number '415-123-4569'
193
+ }
194
+ }.response.should == verb_response(:dial_multiple_numbers)
195
+ end
196
+
197
+ it "dials a conference" do
198
+ verb = Twilio::Verb.new { |v|
199
+ v.dial {
200
+ v.conference 'MyRoom'
201
+ }
202
+ }.response.should == verb_response(:dial_conference)
203
+ end
204
+
205
+ it "dials a muted conference" do
206
+ verb = Twilio::Verb.new { |v|
207
+ v.dial {
208
+ v.conference 'MyRoom', :mute => :true
209
+ }
210
+ }.response.should == verb_response(:dial_muted_conference)
211
+ end
212
+ end
213
+
214
+ context "Hang Up" do
215
+ it "hangs up" do
216
+ Twilio::Verb.hangup.should == verb_response(:hangup)
217
+ end
218
+
219
+ it "says hi and hangs up" do
220
+ verb = Twilio::Verb.new { |v|
221
+ v.say 'hi'
222
+ v.hangup
223
+ }.response.should match %r{<Say( loop="1"| language="en"| voice="man"){3}>hi</Say><Hangup/>}
224
+ end
225
+ end
226
+
227
+ context "Reject" do
228
+ it "rejects" do
229
+ Twilio::Verb.reject.should == verb_response(:reject)
230
+ end
231
+
232
+ it "just rejects incoming call" do
233
+ verb = Twilio::Verb.new { |v|
234
+ v.reject
235
+ }.response.should match %r{<Reject/>}
236
+ end
237
+
238
+ it "just rejects incoming call with 'busy' status" do
239
+ verb = Twilio::Verb.new { |v|
240
+ v.reject :reason => 'busy'
241
+ }.response.should match %r{<Reject reason="busy"/>}
242
+ end
243
+ end
244
+
245
+ context "SMS" do
246
+ it "sends a simple SMS message" do
247
+ verb = Twilio::Verb.new { |v|
248
+ v.sms 'Join us at the bar', :to => "8005554321", :from => "9006661111", :action => "/smsService", :method => "GET"
249
+ }.response.should match %r{<Sms( to="8005554321"| from="9006661111"| action="/smsService"| method="GET"){4}>Join us at the bar</Sms>}
250
+ end
251
+ end
252
+
253
+ end