webficient-twilio 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -8,17 +8,14 @@ For an overview of the Twilio Gem and a sample use case, check out http://www.we
8
8
 
9
9
  == Calling the Twilio REST API
10
10
 
11
- First create a connection object:
11
+ First set your credentials by calling the connect method:
12
12
 
13
- c = Twilio::Connection.new('my_twilio_sid', 'my_auth_token')
13
+ Twilio.connect('my_twilio_sid', 'my_auth_token')
14
14
 
15
- Now instantiate other objects by passing in the connection:
15
+ Now call any of the Twilio classes:
16
16
 
17
- call = Twilio::Call.new(c)
18
- call.make('1234567890', '9876543210', 'http://mysite.com/connected_call')
19
-
20
- recording = Twilio::Recording.new(c)
21
- recording.list
17
+ Twilio::Call.make('1234567890', '9876543210', 'http://mysite.com/connected_call')
18
+ Twilio::Recording.list
22
19
 
23
20
  == Responding to Twilio
24
21
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :patch: 0
3
3
  :major: 2
4
- :minor: 2
4
+ :minor: 3
@@ -2,11 +2,11 @@ module Twilio
2
2
  # The Account resource represents your Twilio Account.
3
3
  class Account < TwilioObject
4
4
  def get
5
- self.connection.class.get('')
5
+ Twilio.get('')
6
6
  end
7
7
 
8
8
  def update_name(name)
9
- self.connection.class.put('', :body => {:FriendlyName => name})
9
+ Twilio.put('', :body => {:FriendlyName => name})
10
10
  end
11
11
  end
12
12
  end
data/lib/twilio/call.rb CHANGED
@@ -4,31 +4,30 @@ module Twilio
4
4
  # initiates the call, either via the REST API, or during a call via the Dial Verb.
5
5
  class Call < TwilioObject
6
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')
7
+ # Twilio.connect('my_twilio_sid', 'my_auth_token')
8
+ # Twilio::Call.make(CALLER_ID, user_number, 'http://myapp.com/twilio_response_handler')
10
9
  def make(caller, called, url, optional = {})
11
- self.connection.class.post("/Calls", :body => {:Caller => caller, :Called => called, :Url => url}.merge(optional))
10
+ Twilio.post("/Calls", :body => {:Caller => caller, :Called => called, :Url => url}.merge(optional))
12
11
  end
13
12
 
14
13
  def list(optional = {})
15
- self.connection.class.get("/Calls", :query => optional)
14
+ Twilio.get("/Calls", :query => optional)
16
15
  end
17
16
 
18
17
  def get(call_sid)
19
- self.connection.class.get("/Calls/#{call_sid}")
18
+ Twilio.get("/Calls/#{call_sid}")
20
19
  end
21
20
 
22
21
  def segments(call_sid, call_segment_sid = nil)
23
- self.connection.class.get("/Calls/#{call_sid}/Segments#{ '/' + call_segment_sid if call_segment_sid }")
22
+ Twilio.get("/Calls/#{call_sid}/Segments#{ '/' + call_segment_sid if call_segment_sid }")
24
23
  end
25
24
 
26
25
  def recordings(call_sid)
27
- self.connection.class.get("/Calls/#{call_sid}/Recordings")
26
+ Twilio.get("/Calls/#{call_sid}/Recordings")
28
27
  end
29
28
 
30
29
  def notifications(call_sid)
31
- self.connection.class.get("/Calls/#{call_sid}/Notifications")
30
+ Twilio.get("/Calls/#{call_sid}/Notifications")
32
31
  end
33
32
  end
34
33
  end
@@ -1,10 +1,16 @@
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.
5
- #
6
- # Example:
7
- # c = Twilio::Connection.new('my_twilio_sid', 'my_auth_token')
2
+ include HTTParty
3
+ TWILIO_URL = "https://api.twilio.com/2008-08-01/Accounts"
4
+
5
+ # The connect method caches your Twilio account id and authentication token
6
+ # Example:
7
+ # Twilio.connect('AC309475e5fede1b49e100272a8640f438', '3a2630a909aadbf60266234756fb15a0')
8
+ def self.connect(account_sid, auth_token)
9
+ self.base_uri "#{TWILIO_URL}/#{account_sid}"
10
+ self.basic_auth account_sid, auth_token
11
+ end
12
+
13
+ # DEPRECATED - use Twilio.connect
8
14
  class Connection
9
15
  include HTTParty
10
16
  TWILIO_URL = "https://api.twilio.com/2008-08-01/Accounts"
@@ -14,4 +20,5 @@ module Twilio
14
20
  self.class.basic_auth account_sid, auth_token
15
21
  end
16
22
  end
23
+
17
24
  end
@@ -1,13 +1,16 @@
1
1
  module Twilio
2
2
  # An IncomingPhoneNumber resource represents a phone number given to you by
3
3
  # Twilio to receive incoming phone calls.
4
+ # Example:
5
+ # Twilio.connect('my_twilio_sid', 'my_auth_token')
6
+ # Twilio::IncomingPhoneNumber.list
4
7
  class IncomingPhoneNumber < TwilioObject
5
8
  def list(optional = {})
6
- self.connection.class.get("/IncomingPhoneNumbers", :query => optional)
9
+ Twilio.get("/IncomingPhoneNumbers", :query => optional)
7
10
  end
8
11
 
9
12
  def get(incoming_sid)
10
- self.connection.class.get("/IncomingPhoneNumbers/#{incoming_sid}")
13
+ Twilio.get("/IncomingPhoneNumbers/#{incoming_sid}")
11
14
  end
12
15
  end
13
16
  end
@@ -1,9 +1,12 @@
1
1
  module Twilio
2
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.
3
+ # Also allows you to request a new local phone number be added to your account.
4
+ # Example:
5
+ # Twilio.connect('my_twilio_sid', 'my_auth_token')
6
+ # Twilio::LocalPhoneNumber.list
4
7
  class LocalPhoneNumber < TwilioObject
5
8
  def create(url, area_code = nil, method = 'POST', friendly_name = nil)
6
- self.connection.class.post("/IncomingPhoneNumbers/Local", :body => {
9
+ Twilio.post("/IncomingPhoneNumbers/Local", :body => {
7
10
  :Url => url,
8
11
  :AreaCode => area_code,
9
12
  :Method => method,
@@ -12,7 +15,7 @@ module Twilio
12
15
  end
13
16
 
14
17
  def list
15
- self.connection.class.get("/IncomingPhoneNumbers/Local")
18
+ Twilio.get("/IncomingPhoneNumbers/Local")
16
19
  end
17
20
  end
18
21
  end
@@ -1,17 +1,20 @@
1
1
  module Twilio
2
2
  # A Notification represenents a log entry made by Twilio in the course of handling
3
3
  # your calls or using the REST API.
4
+ # Example:
5
+ # Twilio.connect('my_twilio_sid', 'my_auth_token')
6
+ # Twilio::Notification.list
4
7
  class Notification < TwilioObject
5
8
  def list(optional = {})
6
- self.connection.class.get('/Notifications', :query => optional)
9
+ Twilio.get('/Notifications', :query => optional)
7
10
  end
8
11
 
9
12
  def get(notification_sid)
10
- self.connection.class.get("/Notifications/#{notification_sid}")
13
+ Twilio.get("/Notifications/#{notification_sid}")
11
14
  end
12
15
 
13
16
  def delete(notification_sid)
14
- self.connection.class.delete("/Notifications/#{notification_sid}")
17
+ Twilio.delete("/Notifications/#{notification_sid}")
15
18
  end
16
19
  end
17
20
  end
@@ -1,9 +1,12 @@
1
1
  module Twilio
2
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.
3
+ # registered with Twilio for use when making an outgoing call or using the Dial Verb.
4
+ # Example:
5
+ # Twilio.connect('my_twilio_sid', 'my_auth_token')
6
+ # Twilio::OutgoingCallerId.list
4
7
  class OutgoingCallerId < TwilioObject
5
8
  def create(phone_number, friendly_name = phone_number, call_delay = 0)
6
- self.connection.class.post("/OutgoingCallerIds", :body => {
9
+ Twilio.post("/OutgoingCallerIds", :body => {
7
10
  :PhoneNumber => phone_number,
8
11
  :FriendlyName => friendly_name,
9
12
  :CallDelay => call_delay
@@ -11,19 +14,19 @@ module Twilio
11
14
  end
12
15
 
13
16
  def list(optional = {})
14
- self.connection.class.get("/OutgoingCallerIds", :query => optional)
17
+ Twilio.get("/OutgoingCallerIds", :query => optional)
15
18
  end
16
19
 
17
20
  def get(callerid_sid)
18
- self.connection.class.get("/OutgoingCallerIds/#{callerid_sid}")
21
+ Twilio.get("/OutgoingCallerIds/#{callerid_sid}")
19
22
  end
20
23
 
21
24
  def update_name(callerid_sid, name)
22
- self.connection.class.put("/OutgoingCallerIds/#{callerid_sid}", :body => {:FriendlyName => name})
25
+ Twilio.put("/OutgoingCallerIds/#{callerid_sid}", :body => {:FriendlyName => name})
23
26
  end
24
27
 
25
28
  def delete(callerid_sid)
26
- self.connection.class.delete("/OutgoingCallerIds/#{callerid_sid}")
29
+ Twilio.delete("/OutgoingCallerIds/#{callerid_sid}")
27
30
  end
28
31
  end
29
32
  end
@@ -1,21 +1,24 @@
1
1
  module Twilio
2
2
  # Recordings are generated when you use the Record Verb. Those recordings are
3
3
  # hosted on Twilio's REST API for you to access.
4
+ # Example:
5
+ # Twilio.connect('my_twilio_sid', 'my_auth_token')
6
+ # Twilio::Recording.list
4
7
  class Recording < TwilioObject
5
8
  def list(optional = {})
6
- self.connection.class.get("/Recordings", :query => optional)
9
+ Twilio.get("/Recordings", :query => optional)
7
10
  end
8
11
 
9
12
  def get(recording_sid)
10
- self.connection.class.get("/Recordings/#{recording_sid}")
13
+ Twilio.get("/Recordings/#{recording_sid}")
11
14
  end
12
15
 
13
16
  def delete(recording_sid)
14
- self.connection.class.delete("/Recordings/#{recording_sid}")
17
+ Twilio.delete("/Recordings/#{recording_sid}")
15
18
  end
16
19
 
17
20
  def transcriptions(recording_sid, transcription_sid = nil)
18
- self.connection.class.get("/Recordings/#{recording_sid}/Transcriptions#{ '/' + transcription_sid if transcription_sid }")
21
+ Twilio.get("/Recordings/#{recording_sid}/Transcriptions#{ '/' + transcription_sid if transcription_sid }")
19
22
  end
20
23
  end
21
24
  end
@@ -1,9 +1,12 @@
1
1
  module Twilio
2
2
  # This sub-resource represents only Toll Free phone numbers, or in other words, not local numbers.
3
3
  # Also allows you to request a new toll free phone number be added to your account.
4
+ # Example:
5
+ # Twilio.connect('my_twilio_sid', 'my_auth_token')
6
+ # Twilio::TollFreePhoneNumber.list
4
7
  class TollFreePhoneNumber < TwilioObject
5
8
  def create(url, area_code = nil, method = 'POST', friendly_name = nil)
6
- self.connection.class.post("/IncomingPhoneNumbers/TollFree", :body => {
9
+ Twilio.post("/IncomingPhoneNumbers/TollFree", :body => {
7
10
  :Url => url,
8
11
  :AreaCode => area_code,
9
12
  :Method => method,
@@ -12,7 +15,7 @@ module Twilio
12
15
  end
13
16
 
14
17
  def list
15
- self.connection.class.get("/IncomingPhoneNumbers/TollFree")
18
+ Twilio.get("/IncomingPhoneNumbers/TollFree")
16
19
  end
17
20
  end
18
21
  end
@@ -1,11 +1,16 @@
1
1
  module Twilio
2
- class TwilioObject #:nodoc: all
3
- include HTTParty
4
-
2
+ class TwilioObject #:nodoc: all
5
3
  attr_reader :connection
6
4
 
7
- def initialize(connection)
5
+ def initialize(connection = nil)
8
6
  @connection = connection
9
7
  end
8
+
9
+ class << self
10
+ def method_missing(method_id, *args) #:nodoc:
11
+ o = self.new
12
+ o.send(method_id, *args)
13
+ end
14
+ end
10
15
  end
11
16
  end
@@ -53,7 +53,7 @@ gather_with_num_digits:
53
53
  response: <?xml version="1.0" encoding="UTF-8"?><Response><Gather numDigits="5"/></Response>
54
54
 
55
55
  gather_with_all_options_set:
56
- response: <?xml version="1.0" encoding="UTF-8"?><Response><Gather action="http://foobar.com" numDigits="5" method="GET" timeout="10" finishOnKey="*"/></Response>
56
+ response: <?xml version="1.0" encoding="UTF-8"?><Response><Gather finishOnKey="*" action="http://foobar.com" method="GET" numDigits="5" timeout="10"/></Response>
57
57
 
58
58
  gather_and_say_instructions:
59
59
  response: <?xml version="1.0" encoding="UTF-8"?><Response><Gather><Say loop="1" language="en" voice="man">Please enter your account number followed by the pound sign</Say></Gather><Say loop="1" language="en" voice="man">We didn't receive any input. Goodbye!</Say></Response>
@@ -3,21 +3,33 @@ require File.dirname(__FILE__) + '/../test_helper'
3
3
  class AccountTest < Test::Unit::TestCase #:nodoc: all
4
4
  context "An account" do
5
5
  setup do
6
- @connection = Twilio::Connection.new('mysid', 'mytoken')
7
- @account = Twilio::Account.new(@connection)
6
+ Twilio.connect('mysid', 'mytoken')
8
7
  end
9
8
 
10
9
  should "be retrievable" do
11
10
  fake_response = fixture(:account)
12
11
  FakeWeb.register_uri(:get, twilio_url, :string => fake_response)
13
- assert_equal @account.get, fake_response
12
+ assert_equal Twilio::Account.get, fake_response
14
13
  end
15
14
 
16
15
  should "be able to update name" do
17
16
  fake_response = fixture(:account_renamed)
18
17
  FakeWeb.register_uri(:put, twilio_url, :string => fake_response)
19
- response = @account.update_name('Bubba')
20
- assert_equal response, fake_response
18
+ assert_equal Twilio::Account.update_name('Bubba'), fake_response
21
19
  end
20
+
21
+ context "using deprecated API" do
22
+ setup do
23
+ @connection = Twilio::Connection.new('mysid', 'mytoken')
24
+ @account = Twilio::Account.new(@connection)
25
+ end
26
+
27
+ 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
31
+ end
32
+ end
33
+
22
34
  end
23
35
  end
@@ -3,26 +3,25 @@ require File.dirname(__FILE__) + '/../test_helper'
3
3
  class CallTest < Test::Unit::TestCase #:nodoc: all
4
4
  context "A call" do
5
5
  setup do
6
- @connection = Twilio::Connection.new('mysid', 'mytoken')
7
- @call = Twilio::Call.new(@connection)
6
+ Twilio.connect('mysid', 'mytoken')
8
7
  end
9
8
 
10
9
  should "be retrievable as a list" do
11
10
  fake_response = fixture(:calls)
12
11
  FakeWeb.register_uri(:get, twilio_url('Calls'), :string => fake_response)
13
- assert_equal @call.list, fake_response
12
+ assert_equal Twilio::Call.list, fake_response
14
13
  end
15
14
 
16
15
  should "be retrievable individually" do
17
16
  fake_response = fixture(:call)
18
17
  FakeWeb.register_uri(:get, twilio_url('Calls/CA42ed11f93dc08b952027ffbc406d0868'), :string => fake_response)
19
- assert_equal @call.get('CA42ed11f93dc08b952027ffbc406d0868'), fake_response
18
+ assert_equal Twilio::Call.get('CA42ed11f93dc08b952027ffbc406d0868'), fake_response
20
19
  end
21
20
 
22
21
  should "be made" do
23
22
  fake_response = fixture(:call_new)
24
23
  FakeWeb.register_uri(:post, twilio_url('Calls'), :string => fake_response)
25
- response = @call.make('4158675309', '4155551212', 'http://test.local/call_handler')
24
+ response = Twilio::Call.make('4158675309', '4155551212', 'http://test.local/call_handler')
26
25
  assert_equal response, fake_response
27
26
  end
28
27
 
@@ -30,13 +29,13 @@ class CallTest < Test::Unit::TestCase #:nodoc: all
30
29
  should "returns a list of Call resources that were segments created in the same call" do
31
30
  fake_response = fixture(:calls)
32
31
  FakeWeb.register_uri(:get, twilio_url('Calls/CA42ed11f93dc08b952027ffbc406d0868/Segments'), :string => fake_response)
33
- assert_equal @call.segments('CA42ed11f93dc08b952027ffbc406d0868'), fake_response
32
+ assert_equal Twilio::Call.segments('CA42ed11f93dc08b952027ffbc406d0868'), fake_response
34
33
  end
35
34
 
36
35
  should "returns a single Call resource for the CallSid and CallSegmentSid provided" do
37
36
  fake_response = fixture(:calls)
38
37
  FakeWeb.register_uri(:get, twilio_url('Calls/CA42ed11f93dc08b952027ffbc406d0868/Segments/abc123'), :string => fake_response)
39
- assert_equal @call.segments('CA42ed11f93dc08b952027ffbc406d0868', 'abc123'), fake_response
38
+ assert_equal Twilio::Call.segments('CA42ed11f93dc08b952027ffbc406d0868', 'abc123'), fake_response
40
39
  end
41
40
  end
42
41
 
@@ -44,7 +43,7 @@ class CallTest < Test::Unit::TestCase #:nodoc: all
44
43
  should "returns a list of recordings that were generated during the call" do
45
44
  fake_response = fixture(:recordings)
46
45
  FakeWeb.register_uri(:get, twilio_url('Calls/CA42ed11f93dc08b952027ffbc406d0868/Recordings'), :string => fake_response)
47
- assert_equal @call.recordings('CA42ed11f93dc08b952027ffbc406d0868'), fake_response
46
+ assert_equal Twilio::Call.recordings('CA42ed11f93dc08b952027ffbc406d0868'), fake_response
48
47
  end
49
48
  end
50
49
 
@@ -52,8 +51,22 @@ class CallTest < Test::Unit::TestCase #:nodoc: all
52
51
  should "description" do
53
52
  fake_response = fixture(:notifications)
54
53
  FakeWeb.register_uri(:get, twilio_url('Calls/CA42ed11f93dc08b952027ffbc406d0868/Notifications'), :string => fake_response)
55
- assert_equal @call.notifications('CA42ed11f93dc08b952027ffbc406d0868'), fake_response
54
+ assert_equal Twilio::Call.notifications('CA42ed11f93dc08b952027ffbc406d0868'), fake_response
56
55
  end
57
56
  end
57
+
58
+ context "using deprecated API" do
59
+ setup do
60
+ @connection = Twilio::Connection.new('mysid', 'mytoken')
61
+ @call = Twilio::Call.new(@connection)
62
+ end
63
+
64
+ 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
68
+ end
69
+ end
70
+
58
71
  end
59
72
  end
@@ -11,5 +11,16 @@ class ConnectionTest < Test::Unit::TestCase #:nodoc: all
11
11
  assert_equal "#{Twilio::Connection::TWILIO_URL}/mysid", @connection.class.base_uri
12
12
  end
13
13
  end
14
+
15
+ context "when invoked as class method" do
16
+ setup do
17
+ Twilio.connect('mysid', 'mytoken')
18
+ end
19
+
20
+ should "have correct url" do
21
+ assert_equal "#{Twilio::TWILIO_URL}/mysid", Twilio.base_uri
22
+ end
23
+ end
24
+
14
25
  end
15
26
  end
@@ -3,20 +3,33 @@ require File.dirname(__FILE__) + '/../test_helper'
3
3
  class IncomingPhoneNumberTest < Test::Unit::TestCase #:nodoc: all
4
4
  context "An incoming phone number" do
5
5
  setup do
6
- @connection = Twilio::Connection.new('mysid', 'mytoken')
7
- @incoming = Twilio::IncomingPhoneNumber.new(@connection)
6
+ Twilio.connect('mysid', 'mytoken')
8
7
  end
9
8
 
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
13
+ end
14
+
10
15
  should "be retrievable as a list" do
11
16
  fake_response = fixture(:incoming_phone_numbers)
12
17
  FakeWeb.register_uri(:get, twilio_url('IncomingPhoneNumbers'), :string => fake_response)
13
- assert_equal @incoming.list, fake_response
18
+ assert_equal Twilio::IncomingPhoneNumber.list, fake_response
14
19
  end
15
20
 
16
- should "be retrievable individually" do
17
- fake_response = fixture(:incoming_phone_number)
18
- FakeWeb.register_uri(:get, twilio_url('IncomingPhoneNumbers/PNe536dfda7c6184afab78d980cb8cdf43'), :string => fake_response)
19
- assert_equal @incoming.get('PNe536dfda7c6184afab78d980cb8cdf43'), fake_response
21
+ context "using deprecated API" do
22
+ setup do
23
+ @connection = Twilio::Connection.new('mysid', 'mytoken')
24
+ @incoming = Twilio::IncomingPhoneNumber.new(@connection)
25
+ end
26
+
27
+ 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
31
+ end
20
32
  end
33
+
21
34
  end
22
35
  end
@@ -3,21 +3,33 @@ require File.dirname(__FILE__) + '/../test_helper'
3
3
  class LocalPhoneNumberTest < Test::Unit::TestCase #:nodoc: all
4
4
  context "A local phone number" do
5
5
  setup do
6
- @connection = Twilio::Connection.new('mysid', 'mytoken')
7
- @local = Twilio::LocalPhoneNumber.new(@connection)
6
+ Twilio.connect('mysid', 'mytoken')
8
7
  end
9
8
 
10
9
  should "be retrievable as a list" do
11
10
  fake_response = fixture(:incoming_phone_numbers)
12
11
  FakeWeb.register_uri(:get, twilio_url('IncomingPhoneNumbers/Local'), :string => fake_response)
13
- assert_equal @local.list, fake_response
12
+ assert_equal Twilio::LocalPhoneNumber.list, fake_response
14
13
  end
15
14
 
16
15
  should "be created" do
17
16
  fake_response = fixture(:incoming_phone_number)
18
17
  FakeWeb.register_uri(:post, twilio_url('IncomingPhoneNumbers/Local'), :string => fake_response)
19
- response = @local.create('http://test.local/call_handler')
20
- assert_equal response, fake_response
18
+ assert_equal Twilio::LocalPhoneNumber.create('http://test.local/call_handler'), fake_response
21
19
  end
20
+
21
+ context "using deprecated API" do
22
+ setup do
23
+ @connection = Twilio::Connection.new('mysid', 'mytoken')
24
+ @local = Twilio::LocalPhoneNumber.new(@connection)
25
+ end
26
+
27
+ 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
31
+ end
32
+ end
33
+
22
34
  end
23
35
  end
@@ -3,26 +3,38 @@ require File.dirname(__FILE__) + '/../test_helper'
3
3
  class NotificationTest < Test::Unit::TestCase #:nodoc: all
4
4
  context "A recording" do
5
5
  setup do
6
- @connection = Twilio::Connection.new('mysid', 'mytoken')
7
- @notification = Twilio::Notification.new(@connection)
6
+ Twilio.connect('mysid', 'mytoken')
8
7
  end
9
8
 
10
9
  should "be retrievable as a list" do
11
10
  fake_response = fixture(:notifications)
12
11
  FakeWeb.register_uri(:get, twilio_url('Notifications'), :string => fake_response)
13
- assert_equal @notification.list, fake_response
12
+ assert_equal Twilio::Notification.list, fake_response
14
13
  end
15
14
 
16
15
  should "be retrievable individually" do
17
16
  fake_response = fixture(:notification)
18
17
  FakeWeb.register_uri(:get, twilio_url('Notifications/NO1fb7086ceb85caed2265f17d7bf7981c'), :string => fake_response)
19
- assert_equal @notification.get('NO1fb7086ceb85caed2265f17d7bf7981c'), fake_response
18
+ assert_equal Twilio::Notification.get('NO1fb7086ceb85caed2265f17d7bf7981c'), fake_response
20
19
  end
21
20
 
22
21
  should "be deleted" do
23
22
  FakeWeb.register_uri(:delete, twilio_url('Notifications/NO1fb7086ceb85caed2265f17d7bf7981c'), :status => [ 204, "HTTPNoContent" ])
24
- response = @notification.delete('NO1fb7086ceb85caed2265f17d7bf7981c')
25
- assert response
26
- end
23
+ assert Twilio::Notification.delete('NO1fb7086ceb85caed2265f17d7bf7981c')
24
+ end
25
+
26
+ context "using deprecated API" do
27
+ setup do
28
+ @connection = Twilio::Connection.new('mysid', 'mytoken')
29
+ @notification = Twilio::Notification.new(@connection)
30
+ end
31
+
32
+ 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
36
+ end
37
+ end
38
+
27
39
  end
28
40
  end
@@ -3,40 +3,49 @@ require File.dirname(__FILE__) + '/../test_helper'
3
3
  class OutgoingCallerIdTest < Test::Unit::TestCase #:nodoc: all
4
4
  context "An outgoing caller id" do
5
5
  setup do
6
- @connection = Twilio::Connection.new('mysid', 'mytoken')
7
- @caller_id = Twilio::OutgoingCallerId.new(@connection)
6
+ Twilio.connect('mysid', 'mytoken')
8
7
  end
9
8
 
10
9
  should "be retrievable as a list" do
11
10
  fake_response = fixture(:outgoing_caller_ids)
12
11
  FakeWeb.register_uri(:get, twilio_url('OutgoingCallerIds'), :string => fake_response)
13
- assert_equal @caller_id.list, fake_response
12
+ assert_equal Twilio::OutgoingCallerId.list, fake_response
14
13
  end
15
14
 
16
15
  should "be retrievable individually" do
17
16
  fake_response = fixture(:outgoing_caller_id)
18
17
  FakeWeb.register_uri(:get, twilio_url('OutgoingCallerIds/PNe536dfda7c6184afab78d980cb8cdf43'), :string => fake_response)
19
- assert_equal @caller_id.get('PNe536dfda7c6184afab78d980cb8cdf43'), fake_response
18
+ assert_equal Twilio::OutgoingCallerId.get('PNe536dfda7c6184afab78d980cb8cdf43'), fake_response
20
19
  end
21
20
 
22
21
  should "be created" do
23
22
  fake_response = fixture(:outgoing_caller_id_new)
24
23
  FakeWeb.register_uri(:post, twilio_url('OutgoingCallerIds'), :string => fake_response)
25
- response = @caller_id.create('4158675309', 'My Home Phone')
26
- assert_equal response, fake_response
24
+ assert_equal Twilio::OutgoingCallerId.create('4158675309', 'My Home Phone'), fake_response
27
25
  end
28
26
 
29
27
  should "be able to update name" do
30
28
  fake_response = fixture(:outgoing_caller_id)
31
29
  FakeWeb.register_uri(:put, twilio_url('OutgoingCallerIds/PNe536dfda7c6184afab78d980cb8cdf43'), :string => fake_response)
32
- response = @caller_id.update_name('PNe536dfda7c6184afab78d980cb8cdf43', 'My office line')
33
- assert_equal response, fake_response
30
+ assert_equal Twilio::OutgoingCallerId.update_name('PNe536dfda7c6184afab78d980cb8cdf43', 'My office line'), fake_response
34
31
  end
35
32
 
36
33
  should "be deleted" do
37
34
  FakeWeb.register_uri(:delete, twilio_url('OutgoingCallerIds/PNe536dfda7c6184afab78d980cb8cdf43'), :status => [ 204, "HTTPNoContent" ])
38
- response = @caller_id.delete('PNe536dfda7c6184afab78d980cb8cdf43')
39
- assert response
35
+ assert Twilio::OutgoingCallerId.delete('PNe536dfda7c6184afab78d980cb8cdf43')
36
+ end
37
+
38
+ context "using deprecated API" do
39
+ setup do
40
+ @connection = Twilio::Connection.new('mysid', 'mytoken')
41
+ @caller_id = Twilio::OutgoingCallerId.new(@connection)
42
+ end
43
+
44
+ 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
48
+ end
40
49
  end
41
50
  end
42
51
  end
@@ -3,39 +3,50 @@ require File.dirname(__FILE__) + '/../test_helper'
3
3
  class RecordingTest < Test::Unit::TestCase #:nodoc: all
4
4
  context "A recording" do
5
5
  setup do
6
- @connection = Twilio::Connection.new('mysid', 'mytoken')
7
- @recording = Twilio::Recording.new(@connection)
6
+ Twilio.connect('mysid', 'mytoken')
8
7
  end
9
8
 
10
9
  should "be retrievable as a list" do
11
10
  fake_response = fixture(:recordings)
12
11
  FakeWeb.register_uri(:get, twilio_url('Recordings'), :string => fake_response)
13
- assert_equal @recording.list, fake_response
12
+ assert_equal Twilio::Recording.list, fake_response
14
13
  end
15
14
 
16
15
  should "be retrievable individually" do
17
16
  fake_response = fixture(:recording)
18
17
  FakeWeb.register_uri(:get, twilio_url('Recordings/RE41331862605f3d662488fdafda2e175f'), :string => fake_response)
19
- assert_equal @recording.get('RE41331862605f3d662488fdafda2e175f'), fake_response
18
+ assert_equal Twilio::Recording.get('RE41331862605f3d662488fdafda2e175f'), fake_response
20
19
  end
21
20
 
22
21
  should "be deleted" do
23
22
  FakeWeb.register_uri(:delete, twilio_url('Recordings/RE41331862605f3d662488fdafda2e175f'), :status => [ 204, "HTTPNoContent" ])
24
- response = @recording.delete('RE41331862605f3d662488fdafda2e175f')
25
- assert response
23
+ assert Twilio::Recording.delete('RE41331862605f3d662488fdafda2e175f')
26
24
  end
27
25
 
28
26
  context "with transcriptions" do
29
27
  should "be retrievable as a list" do
30
28
  fake_response = fixture(:transcriptions)
31
29
  FakeWeb.register_uri(:get, twilio_url('Recordings/RE41331862605f3d662488fdafda2e175f/Transcriptions'), :string => fake_response)
32
- assert_equal @recording.transcriptions('RE41331862605f3d662488fdafda2e175f'), fake_response
30
+ assert_equal Twilio::Recording.transcriptions('RE41331862605f3d662488fdafda2e175f'), fake_response
33
31
  end
34
32
 
35
33
  should "be retrievable individually" do
36
34
  fake_response = fixture(:transcription)
37
35
  FakeWeb.register_uri(:get, twilio_url('Recordings/RE41331862605f3d662488fdafda2e175f/Transcriptions/TRbdece5b75f2cd8f6ef38e0a10f5c4447'), :string => fake_response)
38
- assert_equal @recording.transcriptions('RE41331862605f3d662488fdafda2e175f', 'TRbdece5b75f2cd8f6ef38e0a10f5c4447'), fake_response
36
+ assert_equal Twilio::Recording.transcriptions('RE41331862605f3d662488fdafda2e175f', 'TRbdece5b75f2cd8f6ef38e0a10f5c4447'), fake_response
37
+ end
38
+ end
39
+
40
+ context "using deprecated API" do
41
+ setup do
42
+ @connection = Twilio::Connection.new('mysid', 'mytoken')
43
+ @recording = Twilio::Recording.new(@connection)
44
+ end
45
+
46
+ 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
39
50
  end
40
51
  end
41
52
  end
@@ -3,21 +3,33 @@ require File.dirname(__FILE__) + '/../test_helper'
3
3
  class TollFreePhoneNumberTest < Test::Unit::TestCase #:nodoc: all
4
4
  context "A toll free phone number" do
5
5
  setup do
6
- @connection = Twilio::Connection.new('mysid', 'mytoken')
7
- @toll_free = Twilio::TollFreePhoneNumber.new(@connection)
6
+ Twilio.connect('mysid', 'mytoken')
8
7
  end
9
8
 
10
9
  should "be retrievable as a list" do
11
10
  fake_response = fixture(:incoming_phone_numbers)
12
11
  FakeWeb.register_uri(:get, twilio_url('IncomingPhoneNumbers/TollFree'), :string => fake_response)
13
- assert_equal @toll_free.list, fake_response
12
+ assert_equal Twilio::TollFreePhoneNumber.list, fake_response
14
13
  end
15
14
 
16
15
  should "be created" do
17
16
  fake_response = fixture(:incoming_phone_number)
18
17
  FakeWeb.register_uri(:post, twilio_url('IncomingPhoneNumbers/TollFree'), :string => fake_response)
19
- response = @toll_free.create('http://test.local/call_handler')
20
- assert_equal response, fake_response
18
+ assert_equal Twilio::TollFreePhoneNumber.create('http://test.local/call_handler'), fake_response
21
19
  end
20
+
21
+ context "using deprecated API" do
22
+ setup do
23
+ @connection = Twilio::Connection.new('mysid', 'mytoken')
24
+ @toll_free = Twilio::TollFreePhoneNumber.new(@connection)
25
+ end
26
+
27
+ 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
31
+ end
32
+ end
33
+
22
34
  end
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: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phil Misiowiec