twilio 1.4.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -1,23 +1,38 @@
1
- = twilio
1
+ = Twilio Gem
2
2
 
3
- This wrapper defines each of the interfaces currently supported by Twilio REST API.
3
+ The Twilio gem provides two major pieces of functionality: (1) a Ruby wrapper for the Twilio REST API and (2) response handlers based on the Twilio Markup XML (TwiML).
4
4
 
5
- Sample Usage:
5
+ See http://www.twilio.com/docs/index for Twilio's API documentation.
6
6
 
7
- First create a connection object:
7
+ For an overview of the Twilio Gem and a sample use case, check out http://www.webficient.com/2009/06/22/hello-this-is-your-rails-app-calling-you.
8
8
 
9
- c = Twilio::Connection.new('my_twilio_sid', 'my_auth_token')
10
-
11
- Now instantiate other objects by passing in the connection:
9
+ == Calling the Twilio REST API
10
+
11
+ First set your credentials by calling the connect method:
12
12
 
13
- a = Twilio::Account.new(c)
14
- a.update_name('sparky')
13
+ Twilio.connect('my_twilio_sid', 'my_auth_token')
14
+
15
+ Now call any of the Twilio classes:
16
+
17
+ Twilio::Call.make('1234567890', '9876543210', 'http://mysite.com/connected_call')
18
+ Twilio::Recording.list
15
19
 
16
- call = Twilio::Call.new(c)
17
- call.make('1234567890', '9876543210', 'http://mysite.com/connected_call')
20
+ == Responding to Twilio
21
+
22
+ When Twilio calls your application URL, your response must use the Twilio Markup XML (http://www.twilio.com/docs/api_reference/TwiML/). The Twilio gem makes this very easy
23
+ by providing a Twilio Verb class.
24
+
25
+ For example, in a Ruby on Rails application, you could do the following inside a controller class:
26
+
27
+ Twilio::Verb.dial('415-123-4567')
18
28
 
19
- recording = Twilio::Recording.new(c)
20
- recording.list
29
+ and you can nest multiple verbs inside a block:
30
+
31
+ verb = Twilio::Verb.new { |v|
32
+ v.say("The time is #{Time.now}")
33
+ v.hangup
34
+ }
35
+ verb.response
21
36
 
22
37
  == Copyright
23
38
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 4
3
2
  :patch: 0
4
- :major: 1
3
+ :major: 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