twilio 2.4.0 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -24,13 +24,13 @@ by providing a Twilio Verb class.
24
24
 
25
25
  For example, in a Ruby on Rails application, you could do the following inside a controller class:
26
26
 
27
- Twilio::Verb.dial('415-123-4567')
27
+ Twilio::Verb.dial '415-123-4567'
28
28
 
29
29
  and you can nest multiple verbs inside a block:
30
30
 
31
- verb = Twilio::Verb.new { |v|
32
- v.say("The time is #{Time.now}")
33
- v.hangup
31
+ verb = Twilio::Verb.new {
32
+ say "The time is #{Time.now}"
33
+ hangup
34
34
  }
35
35
  verb.response
36
36
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 0
3
- :major: 2
4
2
  :minor: 4
3
+ :patch: 1
4
+ :major: 2
data/lib/twilio/verb.rb CHANGED
@@ -5,13 +5,13 @@ module Twilio
5
5
  #
6
6
  # If your response consists of a single verb, you can call a Verb class method:
7
7
  #
8
- # Twilio::Verb.say('The time is 9:35 PM.')
8
+ # Twilio::Verb.say 'The time is 9:35 PM.'
9
9
  #
10
10
  # But if you need to chain several verbs together, just wrap them in an instance block and call the 'response' attribute:
11
11
  #
12
- # verb = Twilio::Verb.new { |v|
13
- # v.dial('415-123-4567')
14
- # v.redirect('http://www.foo.com/nextInstructions')
12
+ # verb = Twilio::Verb.new {
13
+ # dial '415-123-4567'
14
+ # redirect 'http://www.foo.com/nextInstructions'
15
15
  # }
16
16
  # verb.response
17
17
  class Verb
@@ -31,32 +31,32 @@ module Twilio
31
31
 
32
32
  if block_given?
33
33
  @chain = true
34
- @response = @xml.Response { block.call(self) }
34
+ @response = @xml.Response { instance_eval(&block) }
35
35
  end
36
36
  end
37
-
37
+
38
38
  # The Say verb converts text to speech that is read back to the caller.
39
39
  # Say is useful for dynamic text that is difficult to prerecord.
40
40
  #
41
41
  # Examples:
42
- # Twilio::Verb.say('The time is 9:35 PM.')
43
- # Twilio::Verb.say('The time is 9:35 PM.', :loop => 3)
42
+ # Twilio::Verb.say 'The time is 9:35 PM.'
43
+ # Twilio::Verb.say 'The time is 9:35 PM.', :loop => 3
44
44
  #
45
45
  # With numbers, 12345 will be spoken as "twelve thousand three hundred forty five" while
46
46
  # 1 2 3 4 5 will be spoken as "one two three four five."
47
47
  #
48
- # Twilio::Verb.say('Your PIN is 1234', :loop => 4)
49
- # Twilio::Verb.say('Your PIN is 1 2 3 4', :loop => 4)
48
+ # Twilio::Verb.say 'Your PIN is 1234', :loop => 4
49
+ # Twilio::Verb.say 'Your PIN is 1 2 3 4', :loop => 4
50
50
  #
51
51
  # If you need a longer pause between each loop, instead of explicitly calling the Pause
52
52
  # verb within a block, you can set the convenient pause option:
53
53
  #
54
- # Twilio::Verb.say('Your PIN is 1 2 3 4', :loop => 4, :pause => true)
54
+ # Twilio::Verb.say 'Your PIN is 1 2 3 4', :loop => 4, :pause => true
55
55
  #
56
56
  # Options (see http://www.twilio.com/docs/api_reference/TwiML/say) are passed in as a hash:
57
57
  #
58
- # Twilio::Verb.say('The time is 9:35 PM.', :voice => 'woman')
59
- # Twilio::Verb.say('The time is 9:35 PM.', {:voice => 'woman', :language => 'es'})
58
+ # Twilio::Verb.say 'The time is 9:35 PM.', :voice => 'woman'
59
+ # Twilio::Verb.say 'The time is 9:35 PM.', :voice => 'woman', :language => 'es'
60
60
  def say(*args)
61
61
  options = {:voice => 'man', :language => 'en', :loop => 1}
62
62
  args.each do |arg|
@@ -83,13 +83,13 @@ module Twilio
83
83
 
84
84
  # The Play verb plays an audio URL back to the caller.
85
85
  # Examples:
86
- # Twilio::Verb.play('http://foo.com/cowbell.mp3')
87
- # Twilio::Verb.play('http://foo.com/cowbell.mp3', :loop => 3)
86
+ # Twilio::Verb.play 'http://foo.com/cowbell.mp3'
87
+ # Twilio::Verb.play 'http://foo.com/cowbell.mp3', :loop => 3
88
88
  #
89
89
  # If you need a longer pause between each loop, instead of explicitly calling the Pause
90
90
  # verb within a block, you can set the convenient pause option:
91
91
  #
92
- # Twilio::Verb.play('http://foo.com/cowbell.mp3', :loop => 3, :pause => true)
92
+ # Twilio::Verb.play 'http://foo.com/cowbell.mp3', :loop => 3, :pause => true
93
93
  #
94
94
  # Options (see http://www.twilio.com/docs/api_reference/TwiML/play) are passed in as a hash,
95
95
  # but only 'loop' is currently supported.
@@ -125,17 +125,17 @@ module Twilio
125
125
  #
126
126
  # Examples:
127
127
  # Twilio::Verb.gather
128
- # Twilio::Verb.gather(:action => 'http://foobar.com')
129
- # Twilio::Verb.gather(:finishOnKey => '*')
130
- # Twilio::Verb.gather(:action => 'http://foobar.com', :finishOnKey => '*')
128
+ # Twilio::Verb.gather :action => 'http://foobar.com'
129
+ # Twilio::Verb.gather :finishOnKey => '*'
130
+ # Twilio::Verb.gather :action => 'http://foobar.com', :finishOnKey => '*'
131
131
  #
132
132
  # Gather also lets you nest the Play, Say, and Pause verbs:
133
133
  #
134
- # verb = Twilio::Verb.new { |v|
135
- # v.gather(:action => '/process_gather', :method => 'GET) {
136
- # v.say('Please enter your account number followed by the pound sign')
134
+ # verb = Twilio::Verb.new {
135
+ # gather(:action => '/process_gather', :method => 'GET) {
136
+ # say 'Please enter your account number followed by the pound sign'
137
137
  # }
138
- # v.say("We didn't receive any input. Goodbye!")
138
+ # say "We didn't receive any input. Goodbye!"
139
139
  # }
140
140
  # verb.response # represents the final xml output
141
141
  def gather(*args, &block)
@@ -158,9 +158,9 @@ module Twilio
158
158
  #
159
159
  # Examples:
160
160
  # Twilio::Verb.record
161
- # Twilio::Verb.record(:action => 'http://foobar.com')
162
- # Twilio::Verb.record(:finishOnKey => '*')
163
- # Twilio::Verb.record(:transcribe => true, :transcribeCallback => '/handle_transcribe')
161
+ # Twilio::Verb.record :action => 'http://foobar.com'
162
+ # Twilio::Verb.record :finishOnKey => '*'
163
+ # Twilio::Verb.record :transcribe => true, :transcribeCallback => '/handle_transcribe'
164
164
  def record(*args)
165
165
  options = args.shift
166
166
  output { @xml.Record(options) }
@@ -179,17 +179,17 @@ module Twilio
179
179
  # Options (see http://www.twilio.com/docs/api_reference/TwiML/dial) are passed in as a hash
180
180
  #
181
181
  # Examples:
182
- # Twilio::Verb.dial('415-123-4567')
183
- # Twilio::Verb.dial('415-123-4567', :action => 'http://foobar.com')
184
- # Twilio::Verb.dial('415-123-4567', {:timeout => 10, :callerId => '858-987-6543'})
182
+ # Twilio::Verb.dial '415-123-4567'
183
+ # Twilio::Verb.dial '415-123-4567', :action => 'http://foobar.com'
184
+ # Twilio::Verb.dial '415-123-4567', :timeout => 10, :callerId => '858-987-6543'
185
185
  #
186
186
  # Twilio also supports an alternate form in which a Number object is nested inside Dial:
187
187
  #
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')
188
+ # verb = Twilio::Verb.new {
189
+ # dial {
190
+ # number '415-123-4567'
191
+ # number '415-123-4568'
192
+ # number '415-123-4569'
193
193
  # }
194
194
  # }
195
195
  # verb.response # represents the final xml output
@@ -222,10 +222,10 @@ module Twilio
222
222
  # Options (see http://www.twilio.com/docs/api_reference/TwiML/pause) are passed in as a hash
223
223
  #
224
224
  # Examples:
225
- # verb = Twilio::Verb.new { |v|
226
- # v.say('greetings')
227
- # v.pause(:length => 2)
228
- # v.say('have a nice day')
225
+ # verb = Twilio::Verb.new {
226
+ # say 'greetings'
227
+ # pause :length => 2
228
+ # say 'have a nice day'
229
229
  # }
230
230
  # verb.response
231
231
  def pause(*args)
@@ -239,9 +239,9 @@ module Twilio
239
239
  # Options (see http://www.twilio.com/docs/api_reference/TwiML/redirect) are passed in as a hash
240
240
  #
241
241
  # Examples:
242
- # verb = Twilio::Verb.new { |v|
243
- # v.dial('415-123-4567')
244
- # v.redirect('http://www.foo.com/nextInstructions')
242
+ # verb = Twilio::Verb.new {
243
+ # dial '415-123-4567'
244
+ # redirect 'http://www.foo.com/nextInstructions'
245
245
  # }
246
246
  # verb.response
247
247
  def redirect(*args)
@@ -270,9 +270,9 @@ module Twilio
270
270
  #
271
271
  # If your response is chained:
272
272
  #
273
- # verb = Twilio::Verb.new { |v|
274
- # v.say("The time is #{Time.now}")
275
- # v.hangup
273
+ # verb = Twilio::Verb.new {
274
+ # say "The time is #{Time.now}"
275
+ # hangup
276
276
  # }
277
277
  # verb.response
278
278
  def hangup
@@ -303,7 +303,7 @@ module Twilio
303
303
  def output
304
304
  @chain ? yield : @xml.Response { yield }
305
305
  end
306
-
306
+
307
307
  def loop_with_pause(loop_count, xml, &verb_action)
308
308
  last_iteration = loop_count-1
309
309
  loop_count.times do |i|
data/test/test_helper.rb CHANGED
@@ -14,6 +14,15 @@ def fixture(filename) #:nodoc:
14
14
  File.read path
15
15
  end
16
16
 
17
+ def stub_response(verb, fixture_name, options = {}) #:nodoc:
18
+ fake_response = fixture(fixture_name)
19
+ resource = options.delete(:resource)
20
+ options = { :body => fake_response }.merge(options)
21
+ FakeWeb.register_uri(verb, twilio_url(resource), options)
22
+
23
+ fake_response
24
+ end
25
+
17
26
  def twilio_url(url=nil) #:nodoc:
18
27
  "https://mysid:mytoken@api.twilio.com:443/2008-08-01/Accounts/mysid#{'/' + url if url}"
19
28
  end
@@ -7,15 +7,11 @@ class AccountTest < Test::Unit::TestCase #:nodoc: all
7
7
  end
8
8
 
9
9
  should "be retrievable" do
10
- fake_response = fixture(:account)
11
- FakeWeb.register_uri(:get, twilio_url, :string => fake_response)
12
- assert_equal Twilio::Account.get, fake_response
10
+ assert_equal stub_response(:get, :account), Twilio::Account.get
13
11
  end
14
12
 
15
13
  should "be able to update name" do
16
- fake_response = fixture(:account_renamed)
17
- FakeWeb.register_uri(:put, twilio_url, :string => fake_response)
18
- assert_equal Twilio::Account.update_name('Bubba'), fake_response
14
+ assert_equal stub_response(:put, :account_renamed), Twilio::Account.update_name('Bubba')
19
15
  end
20
16
 
21
17
  context "using deprecated API" do
@@ -25,11 +21,8 @@ class AccountTest < Test::Unit::TestCase #:nodoc: all
25
21
  end
26
22
 
27
23
  should "be retrievable" do
28
- fake_response = fixture(:account)
29
- FakeWeb.register_uri(:get, twilio_url, :string => fake_response)
30
- assert_equal @account.get, fake_response
24
+ assert_equal stub_response(:get, :account), @account.get
31
25
  end
32
26
  end
33
-
34
27
  end
35
28
  end
@@ -7,51 +7,42 @@ class CallTest < Test::Unit::TestCase #:nodoc: all
7
7
  end
8
8
 
9
9
  should "be retrievable as a list" do
10
- fake_response = fixture(:calls)
11
- FakeWeb.register_uri(:get, twilio_url('Calls'), :string => fake_response)
12
- assert_equal Twilio::Call.list, fake_response
10
+ assert_equal stub_response(:get, :calls, :resource => 'Calls'), Twilio::Call.list
13
11
  end
14
12
 
15
13
  should "be retrievable individually" do
16
- fake_response = fixture(:call)
17
- FakeWeb.register_uri(:get, twilio_url('Calls/CA42ed11f93dc08b952027ffbc406d0868'), :string => fake_response)
18
- assert_equal Twilio::Call.get('CA42ed11f93dc08b952027ffbc406d0868'), fake_response
14
+ assert_equal stub_response(:get, :call, :resource => 'Calls/CA42ed11f93dc08b952027ffbc406d0868'),
15
+ Twilio::Call.get('CA42ed11f93dc08b952027ffbc406d0868')
19
16
  end
20
17
 
21
18
  should "be made" do
22
- fake_response = fixture(:call_new)
23
- FakeWeb.register_uri(:post, twilio_url('Calls'), :string => fake_response)
24
- response = Twilio::Call.make('4158675309', '4155551212', 'http://test.local/call_handler')
25
- assert_equal response, fake_response
19
+ assert_equal stub_response(:post, :call_new, :resource => 'Calls'),
20
+ Twilio::Call.make('4158675309', '4155551212', 'http://test.local/call_handler')
26
21
  end
27
22
 
28
23
  context "with segments" do
29
24
  should "returns a list of Call resources that were segments created in the same call" do
30
- fake_response = fixture(:calls)
31
- FakeWeb.register_uri(:get, twilio_url('Calls/CA42ed11f93dc08b952027ffbc406d0868/Segments'), :string => fake_response)
32
- assert_equal Twilio::Call.segments('CA42ed11f93dc08b952027ffbc406d0868'), fake_response
25
+ assert_equal stub_response(:get, :calls, :resource => 'Calls/CA42ed11f93dc08b952027ffbc406d0868/Segments'),
26
+ Twilio::Call.segments('CA42ed11f93dc08b952027ffbc406d0868')
33
27
  end
34
28
 
35
29
  should "returns a single Call resource for the CallSid and CallSegmentSid provided" do
36
- fake_response = fixture(:calls)
37
- FakeWeb.register_uri(:get, twilio_url('Calls/CA42ed11f93dc08b952027ffbc406d0868/Segments/abc123'), :string => fake_response)
38
- assert_equal Twilio::Call.segments('CA42ed11f93dc08b952027ffbc406d0868', 'abc123'), fake_response
30
+ assert_equal stub_response(:get, :calls, :resource => 'Calls/CA42ed11f93dc08b952027ffbc406d0868/Segments/abc123'),
31
+ Twilio::Call.segments('CA42ed11f93dc08b952027ffbc406d0868', 'abc123')
39
32
  end
40
33
  end
41
34
 
42
35
  context "with recordings" do
43
36
  should "returns a list of recordings that were generated during the call" do
44
- fake_response = fixture(:recordings)
45
- FakeWeb.register_uri(:get, twilio_url('Calls/CA42ed11f93dc08b952027ffbc406d0868/Recordings'), :string => fake_response)
46
- assert_equal Twilio::Call.recordings('CA42ed11f93dc08b952027ffbc406d0868'), fake_response
37
+ assert_equal stub_response(:get, :recordings, :resource => 'Calls/CA42ed11f93dc08b952027ffbc406d0868/Recordings'),
38
+ Twilio::Call.recordings('CA42ed11f93dc08b952027ffbc406d0868')
47
39
  end
48
40
  end
49
41
 
50
42
  context "with notifications" do
51
43
  should "description" do
52
- fake_response = fixture(:notifications)
53
- FakeWeb.register_uri(:get, twilio_url('Calls/CA42ed11f93dc08b952027ffbc406d0868/Notifications'), :string => fake_response)
54
- assert_equal Twilio::Call.notifications('CA42ed11f93dc08b952027ffbc406d0868'), fake_response
44
+ assert_equal stub_response(:get, :notifications, :resource => 'Calls/CA42ed11f93dc08b952027ffbc406d0868/Notifications'),
45
+ Twilio::Call.notifications('CA42ed11f93dc08b952027ffbc406d0868')
55
46
  end
56
47
  end
57
48
 
@@ -62,11 +53,9 @@ class CallTest < Test::Unit::TestCase #:nodoc: all
62
53
  end
63
54
 
64
55
  should "be made" do
65
- fake_response = fixture(:call_new)
66
- FakeWeb.register_uri(:post, twilio_url('Calls'), :string => fake_response)
67
- assert_equal @call.make('4158675309', '4155551212', 'http://test.local/call_handler'), fake_response
56
+ assert_equal stub_response(:post, :call_new, :resource => 'Calls'),
57
+ @call.make('4158675309', '4155551212', 'http://test.local/call_handler')
68
58
  end
69
59
  end
70
-
71
60
  end
72
61
  end
@@ -21,6 +21,5 @@ class ConnectionTest < Test::Unit::TestCase #:nodoc: all
21
21
  assert_equal "#{Twilio::TWILIO_URL}/mysid", Twilio.base_uri
22
22
  end
23
23
  end
24
-
25
24
  end
26
25
  end
@@ -7,15 +7,13 @@ class IncomingPhoneNumberTest < Test::Unit::TestCase #:nodoc: all
7
7
  end
8
8
 
9
9
  should "be retrievable individually" do
10
- fake_response = fixture(:incoming_phone_number)
11
- FakeWeb.register_uri(:get, twilio_url('IncomingPhoneNumbers/PNe536dfda7c6184afab78d980cb8cdf43'), :string => fake_response)
12
- assert_equal Twilio::IncomingPhoneNumber.get('PNe536dfda7c6184afab78d980cb8cdf43'), fake_response
10
+ assert_equal stub_response(:get, :incoming_phone_number, :resource => 'IncomingPhoneNumbers/PNe536dfda7c6184afab78d980cb8cdf43'),
11
+ Twilio::IncomingPhoneNumber.get('PNe536dfda7c6184afab78d980cb8cdf43')
13
12
  end
14
13
 
15
14
  should "be retrievable as a list" do
16
- fake_response = fixture(:incoming_phone_numbers)
17
- FakeWeb.register_uri(:get, twilio_url('IncomingPhoneNumbers'), :string => fake_response)
18
- assert_equal Twilio::IncomingPhoneNumber.list, fake_response
15
+ assert_equal stub_response(:get, :incoming_phone_numbers, :resource => 'IncomingPhoneNumbers'),
16
+ Twilio::IncomingPhoneNumber.list
19
17
  end
20
18
 
21
19
  context "using deprecated API" do
@@ -25,11 +23,9 @@ class IncomingPhoneNumberTest < Test::Unit::TestCase #:nodoc: all
25
23
  end
26
24
 
27
25
  should "be retrievable individually" do
28
- fake_response = fixture(:incoming_phone_number)
29
- FakeWeb.register_uri(:get, twilio_url('IncomingPhoneNumbers/PNe536dfda7c6184afab78d980cb8cdf43'), :string => fake_response)
30
- assert_equal @incoming.get('PNe536dfda7c6184afab78d980cb8cdf43'), fake_response
26
+ assert_equal stub_response(:get, :incoming_phone_number, :resource => 'IncomingPhoneNumbers/PNe536dfda7c6184afab78d980cb8cdf43'),
27
+ @incoming.get('PNe536dfda7c6184afab78d980cb8cdf43')
31
28
  end
32
29
  end
33
-
34
30
  end
35
31
  end
@@ -7,15 +7,13 @@ class LocalPhoneNumberTest < Test::Unit::TestCase #:nodoc: all
7
7
  end
8
8
 
9
9
  should "be retrievable as a list" do
10
- fake_response = fixture(:incoming_phone_numbers)
11
- FakeWeb.register_uri(:get, twilio_url('IncomingPhoneNumbers/Local'), :string => fake_response)
12
- assert_equal Twilio::LocalPhoneNumber.list, fake_response
10
+ assert_equal stub_response(:get, :incoming_phone_numbers, :resource => 'IncomingPhoneNumbers/Local'),
11
+ Twilio::LocalPhoneNumber.list
13
12
  end
14
13
 
15
14
  should "be created" do
16
- fake_response = fixture(:incoming_phone_number)
17
- FakeWeb.register_uri(:post, twilio_url('IncomingPhoneNumbers/Local'), :string => fake_response)
18
- assert_equal Twilio::LocalPhoneNumber.create('http://test.local/call_handler'), fake_response
15
+ assert_equal stub_response(:post, :incoming_phone_number, :resource => 'IncomingPhoneNumbers/Local'),
16
+ Twilio::LocalPhoneNumber.create('http://test.local/call_handler')
19
17
  end
20
18
 
21
19
  context "using deprecated API" do
@@ -25,11 +23,9 @@ class LocalPhoneNumberTest < Test::Unit::TestCase #:nodoc: all
25
23
  end
26
24
 
27
25
  should "be retrievable as a list" do
28
- fake_response = fixture(:incoming_phone_numbers)
29
- FakeWeb.register_uri(:get, twilio_url('IncomingPhoneNumbers/Local'), :string => fake_response)
30
- assert_equal @local.list, fake_response
26
+ assert_equal stub_response(:get, :incoming_phone_numbers, :resource => 'IncomingPhoneNumbers/Local'),
27
+ @local.list
31
28
  end
32
29
  end
33
-
34
30
  end
35
31
  end
@@ -7,19 +7,17 @@ class NotificationTest < Test::Unit::TestCase #:nodoc: all
7
7
  end
8
8
 
9
9
  should "be retrievable as a list" do
10
- fake_response = fixture(:notifications)
11
- FakeWeb.register_uri(:get, twilio_url('Notifications'), :string => fake_response)
12
- assert_equal Twilio::Notification.list, fake_response
10
+ assert_equal stub_response(:get, :notifications, :resource => 'Notifications'), Twilio::Notification.list
13
11
  end
14
12
 
15
13
  should "be retrievable individually" do
16
- fake_response = fixture(:notification)
17
- FakeWeb.register_uri(:get, twilio_url('Notifications/NO1fb7086ceb85caed2265f17d7bf7981c'), :string => fake_response)
18
- assert_equal Twilio::Notification.get('NO1fb7086ceb85caed2265f17d7bf7981c'), fake_response
14
+ assert_equal stub_response(:get, :notification, :resource => 'Notifications/NO1fb7086ceb85caed2265f17d7bf7981c'),
15
+ Twilio::Notification.get('NO1fb7086ceb85caed2265f17d7bf7981c')
19
16
  end
20
17
 
21
18
  should "be deleted" do
22
- FakeWeb.register_uri(:delete, twilio_url('Notifications/NO1fb7086ceb85caed2265f17d7bf7981c'), :status => [ 204, "HTTPNoContent" ])
19
+ stub_response(:delete, :notification, { :resource => 'Notifications/NO1fb7086ceb85caed2265f17d7bf7981c',
20
+ :status => [ 204, "HTTPNoContent" ] })
23
21
  assert Twilio::Notification.delete('NO1fb7086ceb85caed2265f17d7bf7981c')
24
22
  end
25
23
 
@@ -30,11 +28,8 @@ class NotificationTest < Test::Unit::TestCase #:nodoc: all
30
28
  end
31
29
 
32
30
  should "be retrievable as a list" do
33
- fake_response = fixture(:notifications)
34
- FakeWeb.register_uri(:get, twilio_url('Notifications'), :string => fake_response)
35
- assert_equal @notification.list, fake_response
31
+ assert_equal stub_response(:get, :notifications, :resource => 'Notifications'), @notification.list
36
32
  end
37
33
  end
38
-
39
34
  end
40
35
  end
@@ -7,31 +7,27 @@ class OutgoingCallerIdTest < Test::Unit::TestCase #:nodoc: all
7
7
  end
8
8
 
9
9
  should "be retrievable as a list" do
10
- fake_response = fixture(:outgoing_caller_ids)
11
- FakeWeb.register_uri(:get, twilio_url('OutgoingCallerIds'), :string => fake_response)
12
- assert_equal Twilio::OutgoingCallerId.list, fake_response
10
+ assert_equal stub_response(:get, :outgoing_caller_ids, :resource => 'OutgoingCallerIds'), Twilio::OutgoingCallerId.list
13
11
  end
14
12
 
15
13
  should "be retrievable individually" do
16
- fake_response = fixture(:outgoing_caller_id)
17
- FakeWeb.register_uri(:get, twilio_url('OutgoingCallerIds/PNe536dfda7c6184afab78d980cb8cdf43'), :string => fake_response)
18
- assert_equal Twilio::OutgoingCallerId.get('PNe536dfda7c6184afab78d980cb8cdf43'), fake_response
14
+ assert_equal stub_response(:get, :outgoing_caller_id, :resource => 'OutgoingCallerIds/PNe536dfda7c6184afab78d980cb8cdf43'),
15
+ Twilio::OutgoingCallerId.get('PNe536dfda7c6184afab78d980cb8cdf43')
19
16
  end
20
17
 
21
18
  should "be created" do
22
- fake_response = fixture(:outgoing_caller_id_new)
23
- FakeWeb.register_uri(:post, twilio_url('OutgoingCallerIds'), :string => fake_response)
24
- assert_equal Twilio::OutgoingCallerId.create('4158675309', 'My Home Phone'), fake_response
19
+ assert_equal stub_response(:post, :outgoing_caller_id_new, :resource => 'OutgoingCallerIds'),
20
+ Twilio::OutgoingCallerId.create('4158675309', 'My Home Phone')
25
21
  end
26
22
 
27
23
  should "be able to update name" do
28
- fake_response = fixture(:outgoing_caller_id)
29
- FakeWeb.register_uri(:put, twilio_url('OutgoingCallerIds/PNe536dfda7c6184afab78d980cb8cdf43'), :string => fake_response)
30
- assert_equal Twilio::OutgoingCallerId.update_name('PNe536dfda7c6184afab78d980cb8cdf43', 'My office line'), fake_response
24
+ assert_equal stub_response(:put, :outgoing_caller_id, :resource => 'OutgoingCallerIds/PNe536dfda7c6184afab78d980cb8cdf43'),
25
+ Twilio::OutgoingCallerId.update_name('PNe536dfda7c6184afab78d980cb8cdf43', 'My office line')
31
26
  end
32
27
 
33
28
  should "be deleted" do
34
- FakeWeb.register_uri(:delete, twilio_url('OutgoingCallerIds/PNe536dfda7c6184afab78d980cb8cdf43'), :status => [ 204, "HTTPNoContent" ])
29
+ stub_response(:delete, :outgoing_caller_id, :resource => 'OutgoingCallerIds/PNe536dfda7c6184afab78d980cb8cdf43',
30
+ :status => [ 204, "HTTPNoContent" ])
35
31
  assert Twilio::OutgoingCallerId.delete('PNe536dfda7c6184afab78d980cb8cdf43')
36
32
  end
37
33
 
@@ -42,9 +38,7 @@ class OutgoingCallerIdTest < Test::Unit::TestCase #:nodoc: all
42
38
  end
43
39
 
44
40
  should "be retrievable as a list" do
45
- fake_response = fixture(:outgoing_caller_ids)
46
- FakeWeb.register_uri(:get, twilio_url('OutgoingCallerIds'), :string => fake_response)
47
- assert_equal @caller_id.list, fake_response
41
+ assert_equal stub_response(:get, :outgoing_caller_ids, :resource => 'OutgoingCallerIds'), @caller_id.list
48
42
  end
49
43
  end
50
44
  end
@@ -7,33 +7,29 @@ class RecordingTest < Test::Unit::TestCase #:nodoc: all
7
7
  end
8
8
 
9
9
  should "be retrievable as a list" do
10
- fake_response = fixture(:recordings)
11
- FakeWeb.register_uri(:get, twilio_url('Recordings'), :string => fake_response)
12
- assert_equal Twilio::Recording.list, fake_response
10
+ assert_equal stub_response(:get, :recordings, :resource => 'Recordings'), Twilio::Recording.list
13
11
  end
14
12
 
15
13
  should "be retrievable individually" do
16
- fake_response = fixture(:recording)
17
- FakeWeb.register_uri(:get, twilio_url('Recordings/RE41331862605f3d662488fdafda2e175f'), :string => fake_response)
18
- assert_equal Twilio::Recording.get('RE41331862605f3d662488fdafda2e175f'), fake_response
14
+ assert_equal stub_response(:get, :recording, :resource => 'Recordings/RE41331862605f3d662488fdafda2e175f'),
15
+ Twilio::Recording.get('RE41331862605f3d662488fdafda2e175f')
19
16
  end
20
17
 
21
18
  should "be deleted" do
22
- FakeWeb.register_uri(:delete, twilio_url('Recordings/RE41331862605f3d662488fdafda2e175f'), :status => [ 204, "HTTPNoContent" ])
19
+ stub_response(:delete, :recording, :resource => 'Recordings/RE41331862605f3d662488fdafda2e175f',
20
+ :status => [ 204, "HTTPNoContent" ])
23
21
  assert Twilio::Recording.delete('RE41331862605f3d662488fdafda2e175f')
24
22
  end
25
23
 
26
24
  context "with transcriptions" do
27
25
  should "be retrievable as a list" do
28
- fake_response = fixture(:transcriptions)
29
- FakeWeb.register_uri(:get, twilio_url('Recordings/RE41331862605f3d662488fdafda2e175f/Transcriptions'), :string => fake_response)
30
- assert_equal Twilio::Recording.transcriptions('RE41331862605f3d662488fdafda2e175f'), fake_response
26
+ assert_equal stub_response(:get, :transcriptions, :resource => 'Recordings/RE41331862605f3d662488fdafda2e175f/Transcriptions'),
27
+ Twilio::Recording.transcriptions('RE41331862605f3d662488fdafda2e175f')
31
28
  end
32
29
 
33
30
  should "be retrievable individually" do
34
- fake_response = fixture(:transcription)
35
- FakeWeb.register_uri(:get, twilio_url('Recordings/RE41331862605f3d662488fdafda2e175f/Transcriptions/TRbdece5b75f2cd8f6ef38e0a10f5c4447'), :string => fake_response)
36
- assert_equal Twilio::Recording.transcriptions('RE41331862605f3d662488fdafda2e175f', 'TRbdece5b75f2cd8f6ef38e0a10f5c4447'), fake_response
31
+ assert_equal stub_response(:get, :transcription, :resource => 'Recordings/RE41331862605f3d662488fdafda2e175f/Transcriptions/TRbdece5b75f2cd8f6ef38e0a10f5c4447'),
32
+ Twilio::Recording.transcriptions('RE41331862605f3d662488fdafda2e175f', 'TRbdece5b75f2cd8f6ef38e0a10f5c4447')
37
33
  end
38
34
  end
39
35
 
@@ -44,9 +40,7 @@ class RecordingTest < Test::Unit::TestCase #:nodoc: all
44
40
  end
45
41
 
46
42
  should "be retrievable as a list" do
47
- fake_response = fixture(:recordings)
48
- FakeWeb.register_uri(:get, twilio_url('Recordings'), :string => fake_response)
49
- assert_equal @recording.list, fake_response
43
+ assert_equal stub_response(:get, :recordings, :resource => 'Recordings'), @recording.list
50
44
  end
51
45
  end
52
46
  end
@@ -7,15 +7,13 @@ class TollFreePhoneNumberTest < Test::Unit::TestCase #:nodoc: all
7
7
  end
8
8
 
9
9
  should "be retrievable as a list" do
10
- fake_response = fixture(:incoming_phone_numbers)
11
- FakeWeb.register_uri(:get, twilio_url('IncomingPhoneNumbers/TollFree'), :string => fake_response)
12
- assert_equal Twilio::TollFreePhoneNumber.list, fake_response
10
+ assert_equal stub_response(:get, :incoming_phone_numbers, :resource => 'IncomingPhoneNumbers/TollFree'),
11
+ Twilio::TollFreePhoneNumber.list
13
12
  end
14
13
 
15
14
  should "be created" do
16
- fake_response = fixture(:incoming_phone_number)
17
- FakeWeb.register_uri(:post, twilio_url('IncomingPhoneNumbers/TollFree'), :string => fake_response)
18
- assert_equal Twilio::TollFreePhoneNumber.create('http://test.local/call_handler'), fake_response
15
+ assert_equal stub_response(:post, :incoming_phone_number, :resource => 'IncomingPhoneNumbers/TollFree'),
16
+ Twilio::TollFreePhoneNumber.create('http://test.local/call_handler')
19
17
  end
20
18
 
21
19
  context "using deprecated API" do
@@ -25,11 +23,9 @@ class TollFreePhoneNumberTest < Test::Unit::TestCase #:nodoc: all
25
23
  end
26
24
 
27
25
  should "be retrievable as a list" do
28
- fake_response = fixture(:incoming_phone_numbers)
29
- FakeWeb.register_uri(:get, twilio_url('IncomingPhoneNumbers/TollFree'), :string => fake_response)
30
- assert_equal @toll_free.list, fake_response
26
+ assert_equal stub_response(:get, :incoming_phone_numbers, :resource => 'IncomingPhoneNumbers/TollFree'),
27
+ @toll_free.list
31
28
  end
32
29
  end
33
-
34
30
  end
35
31
  end
@@ -14,7 +14,7 @@ class VerbTest < Test::Unit::TestCase #:nodoc: all
14
14
 
15
15
  should "say 'hola' in Spanish with female voice" do
16
16
  assert_match %r{<Say( loop="1"| language="es"| voice="woman"){3}>hola</Say>},
17
- Twilio::Verb.say('hola', {:voice => 'woman', :language => 'es'})
17
+ Twilio::Verb.say('hola', :voice => 'woman', :language => 'es')
18
18
  end
19
19
 
20
20
  should "say 'hi' three times" do
@@ -28,19 +28,19 @@ class VerbTest < Test::Unit::TestCase #:nodoc: all
28
28
  end
29
29
 
30
30
  should "say 'hi' with pause and say 'bye'" do
31
- verb = Twilio::Verb.new { |v|
32
- v.say('hi', :loop => 1)
33
- v.pause
34
- v.say('bye')
31
+ verb = Twilio::Verb.new {
32
+ say 'hi', :loop => 1
33
+ pause
34
+ say 'bye'
35
35
  }
36
36
  assert_match %r{<Say( loop="1"| language="en"| voice="man"){3}>hi</Say><Pause></Pause><Say( loop="1"| language="en"| voice="man"){3}>bye</Say>}, verb.response
37
37
  end
38
38
 
39
39
  should "say 'hi' with 2 second pause and say 'bye'" do
40
- verb = Twilio::Verb.new { |v|
41
- v.say('hi')
42
- v.pause(:length => 2)
43
- v.say('bye')
40
+ verb = Twilio::Verb.new {
41
+ say 'hi'
42
+ pause :length => 2
43
+ say 'bye'
44
44
  }
45
45
  assert_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>}, verb.response
46
46
  end
@@ -54,7 +54,8 @@ class VerbTest < Test::Unit::TestCase #:nodoc: all
54
54
  end
55
55
 
56
56
  should "play mp3 response two times with pause" do
57
- assert_equal verb_response(:play_mp3_two_times_with_pause), Twilio::Verb.play('http://foo.com/cowbell.mp3', :loop => 2, :pause => true)
57
+ assert_equal verb_response(:play_mp3_two_times_with_pause),
58
+ Twilio::Verb.play('http://foo.com/cowbell.mp3', :loop => 2, :pause => true)
58
59
  end
59
60
 
60
61
  should "gather" do
@@ -91,21 +92,21 @@ class VerbTest < Test::Unit::TestCase #:nodoc: all
91
92
  end
92
93
 
93
94
  should "gather and say instructions" do
94
- verb = Twilio::Verb.new { |v|
95
- v.gather {
96
- v.say('Please enter your account number followed by the pound sign')
95
+ verb = Twilio::Verb.new {
96
+ gather {
97
+ say 'Please enter your account number followed by the pound sign'
97
98
  }
98
- v.say("We didn't receive any input. Goodbye!")
99
+ say "We didn't receive any input. Goodbye!"
99
100
  }
100
101
  assert_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>}, verb.response
101
102
  end
102
103
 
103
104
  should "gather with timeout and say instructions" do
104
- verb = Twilio::Verb.new { |v|
105
- v.gather(:timeout => 10) {
106
- v.say('Please enter your account number followed by the pound sign')
105
+ verb = Twilio::Verb.new {
106
+ gather(:timeout => 10) {
107
+ say 'Please enter your account number followed by the pound sign'
107
108
  }
108
- v.say("We didn't receive any input. Goodbye!")
109
+ say "We didn't receive any input. Goodbye!"
109
110
  }
110
111
  assert_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>}, verb.response
111
112
  end
@@ -169,35 +170,32 @@ class VerbTest < Test::Unit::TestCase #:nodoc: all
169
170
 
170
171
  should "dial with timeout and caller id" do
171
172
  assert_match %r{<Dial( timeout="10"| callerId="858-987-6543"){2}>415-123-4567</Dial>},
172
- Twilio::Verb.dial('415-123-4567', {
173
- :timeout => 10,
174
- :callerId => '858-987-6543' }
175
- )
173
+ Twilio::Verb.dial('415-123-4567', :timeout => 10, :callerId => '858-987-6543')
176
174
  end
177
175
 
178
176
  should "dial with redirect" do
179
- verb = Twilio::Verb.new { |v|
180
- v.dial('415-123-4567')
181
- v.redirect('http://www.foo.com/nextInstructions')
177
+ verb = Twilio::Verb.new {
178
+ dial '415-123-4567'
179
+ redirect 'http://www.foo.com/nextInstructions'
182
180
  }
183
181
  assert_equal verb_response(:dial_with_redirect), verb.response
184
182
  end
185
183
 
186
184
  should "dial with number and send digits" do
187
- verb = Twilio::Verb.new { |v|
188
- v.dial {
189
- v.number('415-123-4567', :sendDigits => 'wwww1928')
185
+ verb = Twilio::Verb.new {
186
+ dial {
187
+ number('415-123-4567', :sendDigits => 'wwww1928')
190
188
  }
191
189
  }
192
190
  assert_equal verb_response(:dial_with_number_and_send_digits), verb.response
193
191
  end
194
192
 
195
193
  should "dial multiple numbers" do
196
- verb = Twilio::Verb.new { |v|
197
- v.dial {
198
- v.number('415-123-4567')
199
- v.number('415-123-4568')
200
- v.number('415-123-4569')
194
+ verb = Twilio::Verb.new {
195
+ dial {
196
+ number '415-123-4567'
197
+ number '415-123-4568'
198
+ number '415-123-4569'
201
199
  }
202
200
  }
203
201
  assert_equal verb_response(:dial_multiple_numbers), verb.response
@@ -208,13 +206,12 @@ class VerbTest < Test::Unit::TestCase #:nodoc: all
208
206
  end
209
207
 
210
208
  should "say hi and hangup" do
211
- verb = Twilio::Verb.new { |v|
212
- v.say('hi')
213
- v.hangup
209
+ verb = Twilio::Verb.new {
210
+ say 'hi'
211
+ hangup
214
212
  }
215
213
  assert_match %r{<Say( loop="1"| language="en"| voice="man"){3}>hi</Say><Hangup/>},
216
214
  verb.response
217
215
  end
218
216
  end
219
-
220
217
  end
data/twilio.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{twilio}
8
- s.version = "2.4.0"
8
+ s.version = "2.4.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Phil Misiowiec"]
12
- s.date = %q{2009-09-03}
12
+ s.date = %q{2009-11-03}
13
13
  s.email = %q{github@webficient.com}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twilio
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.4.1
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-09-03 00:00:00 -07:00
12
+ date: 2009-11-03 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency