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 +28 -13
- data/VERSION.yml +2 -2
- data/lib/twilio/account.rb +2 -2
- data/lib/twilio/call.rb +8 -9
- data/lib/twilio/connection.rb +13 -6
- data/lib/twilio/incoming_phone_number.rb +5 -2
- data/lib/twilio/local_phone_number.rb +6 -3
- data/lib/twilio/notification.rb +6 -3
- data/lib/twilio/outgoing_caller_id.rb +9 -6
- data/lib/twilio/recording.rb +7 -4
- data/lib/twilio/toll_free_phone_number.rb +5 -2
- data/lib/twilio/twilio_object.rb +9 -4
- data/lib/twilio/verb.rb +292 -163
- data/test/fixtures/yml/verb_responses.yml +33 -3
- data/test/twilio/account_test.rb +17 -5
- data/test/twilio/call_test.rb +22 -9
- data/test/twilio/connection_test.rb +11 -0
- data/test/twilio/incoming_phone_number_test.rb +20 -7
- data/test/twilio/local_phone_number_test.rb +17 -5
- data/test/twilio/notification_test.rb +19 -7
- data/test/twilio/outgoing_caller_id_test.rb +19 -10
- data/test/twilio/recording_test.rb +19 -8
- data/test/twilio/toll_free_phone_number_test.rb +17 -5
- data/test/twilio/verb_test.rb +82 -4
- metadata +5 -3
data/README.rdoc
CHANGED
@@ -1,23 +1,38 @@
|
|
1
|
-
=
|
1
|
+
= Twilio Gem
|
2
2
|
|
3
|
-
|
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
|
-
|
5
|
+
See http://www.twilio.com/docs/index for Twilio's API documentation.
|
6
6
|
|
7
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
9
|
+
== Calling the Twilio REST API
|
10
|
+
|
11
|
+
First set your credentials by calling the connect method:
|
12
12
|
|
13
|
-
|
14
|
-
|
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
|
-
|
17
|
-
|
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
|
-
|
20
|
-
|
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
data/lib/twilio/account.rb
CHANGED
@@ -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
|
-
|
5
|
+
Twilio.get('')
|
6
6
|
end
|
7
7
|
|
8
8
|
def update_name(name)
|
9
|
-
|
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
|
-
#
|
8
|
-
#
|
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
|
-
|
10
|
+
Twilio.post("/Calls", :body => {:Caller => caller, :Called => called, :Url => url}.merge(optional))
|
12
11
|
end
|
13
12
|
|
14
13
|
def list(optional = {})
|
15
|
-
|
14
|
+
Twilio.get("/Calls", :query => optional)
|
16
15
|
end
|
17
16
|
|
18
17
|
def get(call_sid)
|
19
|
-
|
18
|
+
Twilio.get("/Calls/#{call_sid}")
|
20
19
|
end
|
21
20
|
|
22
21
|
def segments(call_sid, call_segment_sid = nil)
|
23
|
-
|
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
|
-
|
26
|
+
Twilio.get("/Calls/#{call_sid}/Recordings")
|
28
27
|
end
|
29
28
|
|
30
29
|
def notifications(call_sid)
|
31
|
-
|
30
|
+
Twilio.get("/Calls/#{call_sid}/Notifications")
|
32
31
|
end
|
33
32
|
end
|
34
33
|
end
|
data/lib/twilio/connection.rb
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
module Twilio
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
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
|
-
|
9
|
+
Twilio.get("/IncomingPhoneNumbers", :query => optional)
|
7
10
|
end
|
8
11
|
|
9
12
|
def get(incoming_sid)
|
10
|
-
|
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
|
-
|
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
|
-
|
18
|
+
Twilio.get("/IncomingPhoneNumbers/Local")
|
16
19
|
end
|
17
20
|
end
|
18
21
|
end
|
data/lib/twilio/notification.rb
CHANGED
@@ -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
|
-
|
9
|
+
Twilio.get('/Notifications', :query => optional)
|
7
10
|
end
|
8
11
|
|
9
12
|
def get(notification_sid)
|
10
|
-
|
13
|
+
Twilio.get("/Notifications/#{notification_sid}")
|
11
14
|
end
|
12
15
|
|
13
16
|
def delete(notification_sid)
|
14
|
-
|
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
|
-
|
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
|
-
|
17
|
+
Twilio.get("/OutgoingCallerIds", :query => optional)
|
15
18
|
end
|
16
19
|
|
17
20
|
def get(callerid_sid)
|
18
|
-
|
21
|
+
Twilio.get("/OutgoingCallerIds/#{callerid_sid}")
|
19
22
|
end
|
20
23
|
|
21
24
|
def update_name(callerid_sid, name)
|
22
|
-
|
25
|
+
Twilio.put("/OutgoingCallerIds/#{callerid_sid}", :body => {:FriendlyName => name})
|
23
26
|
end
|
24
27
|
|
25
28
|
def delete(callerid_sid)
|
26
|
-
|
29
|
+
Twilio.delete("/OutgoingCallerIds/#{callerid_sid}")
|
27
30
|
end
|
28
31
|
end
|
29
32
|
end
|
data/lib/twilio/recording.rb
CHANGED
@@ -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
|
-
|
9
|
+
Twilio.get("/Recordings", :query => optional)
|
7
10
|
end
|
8
11
|
|
9
12
|
def get(recording_sid)
|
10
|
-
|
13
|
+
Twilio.get("/Recordings/#{recording_sid}")
|
11
14
|
end
|
12
15
|
|
13
16
|
def delete(recording_sid)
|
14
|
-
|
17
|
+
Twilio.delete("/Recordings/#{recording_sid}")
|
15
18
|
end
|
16
19
|
|
17
20
|
def transcriptions(recording_sid, transcription_sid = nil)
|
18
|
-
|
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
|
-
|
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
|
-
|
18
|
+
Twilio.get("/IncomingPhoneNumbers/TollFree")
|
16
19
|
end
|
17
20
|
end
|
18
21
|
end
|
data/lib/twilio/twilio_object.rb
CHANGED
@@ -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
|