twilio-ruby 3.10.1 → 3.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS.md +24 -0
- data/CHANGES +11 -0
- data/Makefile +13 -0
- data/README.md +28 -13
- data/docs/Makefile +130 -0
- data/docs/_themes/LICENSE +45 -0
- data/docs/_themes/README.rst +25 -0
- data/docs/_themes/flask_theme_support.py +86 -0
- data/docs/_themes/kr/layout.html +32 -0
- data/docs/_themes/kr/relations.html +19 -0
- data/docs/_themes/kr/static/flasky.css_t +469 -0
- data/docs/_themes/kr/static/small_flask.css +70 -0
- data/docs/_themes/kr/theme.conf +7 -0
- data/docs/_themes/kr_small/layout.html +22 -0
- data/docs/_themes/kr_small/static/flasky.css_t +287 -0
- data/docs/_themes/kr_small/theme.conf +10 -0
- data/docs/changelog.rst +1 -0
- data/docs/conf.py +266 -0
- data/docs/faq.rst +42 -0
- data/docs/getting-started.rst +91 -0
- data/docs/index.rst +108 -0
- data/docs/make.bat +170 -0
- data/docs/src/pip-delete-this-directory.txt +5 -0
- data/docs/usage/accounts.rst +89 -0
- data/docs/usage/applications.rst +108 -0
- data/docs/usage/basics.rst +81 -0
- data/docs/usage/caller-ids.rst +45 -0
- data/docs/usage/conferences.rst +108 -0
- data/docs/usage/messages.rst +110 -0
- data/docs/usage/notifications.rst +70 -0
- data/docs/usage/phone-calls.rst +168 -0
- data/docs/usage/phone-numbers.rst +159 -0
- data/docs/usage/queues.rst +112 -0
- data/docs/usage/recordings.rst +96 -0
- data/docs/usage/sip.rst +103 -0
- data/docs/usage/token-generation.rst +81 -0
- data/docs/usage/transcriptions.rst +31 -0
- data/docs/usage/twiml.rst +70 -0
- data/docs/usage/validation.rst +71 -0
- data/examples/examples.rb +8 -5
- data/lib/twilio-ruby.rb +10 -0
- data/lib/twilio-ruby/rest/accounts.rb +1 -1
- data/lib/twilio-ruby/rest/instance_resource.rb +2 -1
- data/lib/twilio-ruby/rest/list_resource.rb +4 -1
- data/lib/twilio-ruby/rest/media.rb +14 -0
- data/lib/twilio-ruby/rest/messages.rb +12 -0
- data/lib/twilio-ruby/rest/sip.rb +12 -0
- data/lib/twilio-ruby/rest/sip/credential_lists.rb +11 -0
- data/lib/twilio-ruby/rest/sip/credential_lists/credentials.rb +6 -0
- data/lib/twilio-ruby/rest/sip/domains.rb +12 -0
- data/lib/twilio-ruby/rest/sip/domains/credential_list_mappings.rb +6 -0
- data/lib/twilio-ruby/rest/sip/domains/ip_access_control_list_mappings.rb +6 -0
- data/lib/twilio-ruby/rest/sip/ip_access_control_lists.rb +11 -0
- data/lib/twilio-ruby/rest/sip/ip_access_control_lists/ip_addresses.rb +6 -0
- data/lib/twilio-ruby/rest/sms.rb +1 -1
- data/lib/twilio-ruby/rest/usage/records.rb +1 -1
- data/lib/twilio-ruby/rest/utils.rb +1 -1
- data/lib/twilio-ruby/version.rb +1 -1
- data/spec/rest/message_spec.rb +12 -0
- metadata +52 -2
@@ -0,0 +1,108 @@
|
|
1
|
+
.. module:: twilio.rest.resources
|
2
|
+
|
3
|
+
=================
|
4
|
+
Applications
|
5
|
+
=================
|
6
|
+
|
7
|
+
An application inside of Twilio is just a set of URLs and other configuration
|
8
|
+
data that tells Twilio how to behave when one of your Twilio numbers receives
|
9
|
+
a call or message.
|
10
|
+
|
11
|
+
For more information, see the `Application REST Resource
|
12
|
+
<http://www.twilio.com/docs/api/rest/applications>`_ documentation.
|
13
|
+
|
14
|
+
|
15
|
+
Listing Your Applications
|
16
|
+
--------------------------
|
17
|
+
|
18
|
+
The following code will print out the :attr:`friendly_name` for each :class:`Application`.
|
19
|
+
|
20
|
+
.. code-block:: ruby
|
21
|
+
|
22
|
+
require 'twilio-ruby'
|
23
|
+
|
24
|
+
# To find these visit https://www.twilio.com/user/account
|
25
|
+
account_sid = "ACXXXXXXXXXXXXXXXXX"
|
26
|
+
auth_token = "YYYYYYYYYYYYYYYYYY"
|
27
|
+
|
28
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
29
|
+
@client.applications.each do |app|
|
30
|
+
puts app.friendly_name
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
Filtering Applications
|
35
|
+
---------------------------
|
36
|
+
|
37
|
+
You can filter applications by FriendlyName
|
38
|
+
|
39
|
+
.. code-block:: ruby
|
40
|
+
|
41
|
+
require 'twilio-ruby'
|
42
|
+
|
43
|
+
# To find these visit https://www.twilio.com/user/account
|
44
|
+
account_sid = "ACXXXXXXXXXXXXXXXXX"
|
45
|
+
auth_token = "YYYYYYYYYYYYYYYYYY"
|
46
|
+
|
47
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
48
|
+
@client.applications.list({:friendly_name => 'FOO'})}.each do |app|
|
49
|
+
puts app.sid
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
Creating an Application
|
54
|
+
-------------------------
|
55
|
+
|
56
|
+
When creating an application, no fields are required. We create an application
|
57
|
+
with only a :attr:`friendly_name`. The :meth:`Applications.create()` method
|
58
|
+
accepts many other arguments for url configuration.
|
59
|
+
|
60
|
+
.. code-block:: ruby
|
61
|
+
|
62
|
+
require 'twilio-ruby'
|
63
|
+
|
64
|
+
# To find these visit https://www.twilio.com/user/account
|
65
|
+
account_sid = "ACXXXXXXXXXXXXXXXXX"
|
66
|
+
auth_token = "YYYYYYYYYYYYYYYYYY"
|
67
|
+
|
68
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
69
|
+
@application = @client.applications.create({:friendly_name => "My New App"})
|
70
|
+
|
71
|
+
|
72
|
+
Updating an Application
|
73
|
+
------------------------
|
74
|
+
|
75
|
+
.. code-block:: ruby
|
76
|
+
|
77
|
+
require 'twilio-ruby'
|
78
|
+
|
79
|
+
# To find these visit https://www.twilio.com/user/account
|
80
|
+
account_sid = "ACXXXXXXXXXXXXXXXXX"
|
81
|
+
auth_token = "YYYYYYYYYYYYYYYYYY"
|
82
|
+
|
83
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
84
|
+
|
85
|
+
url = "http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient"
|
86
|
+
app_sid = 'AP123' # the app you'd like to update
|
87
|
+
|
88
|
+
@application = @client.applications.get(app_sid)
|
89
|
+
@application.update({:voice_url => url})
|
90
|
+
|
91
|
+
|
92
|
+
Deleting an Application
|
93
|
+
-------------------------
|
94
|
+
|
95
|
+
.. code-block:: ruby
|
96
|
+
|
97
|
+
require 'twilio-ruby'
|
98
|
+
|
99
|
+
# To find these visit https://www.twilio.com/user/account
|
100
|
+
account_sid = "ACXXXXXXXXXXXXXXXXX"
|
101
|
+
auth_token = "YYYYYYYYYYYYYYYYYY"
|
102
|
+
|
103
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
104
|
+
|
105
|
+
app_sid = 'AP123' # the app you'd like to delete
|
106
|
+
@client.applications.get(app_sid)
|
107
|
+
@application.delete()
|
108
|
+
|
@@ -0,0 +1,81 @@
|
|
1
|
+
.. module:: twilio.rest
|
2
|
+
|
3
|
+
=========================
|
4
|
+
Accessing REST Resources
|
5
|
+
=========================
|
6
|
+
|
7
|
+
To access Twilio REST resources, you'll first need to instantiate a
|
8
|
+
:class:`TwilioRestClient`.
|
9
|
+
|
10
|
+
Authentication
|
11
|
+
--------------------------
|
12
|
+
|
13
|
+
The :class:`TwilioRestClient` needs your Twilio credentials. To get
|
14
|
+
your credentials, visit `your Twilio account portal
|
15
|
+
<https://www.twilio.com/user/account>`_. If you don't have a Twilio account
|
16
|
+
yet, go `here <https://www.twilio.com/try-twilio>`_ to get started.
|
17
|
+
|
18
|
+
Once you have your credentials, you can create create a new :class:`Client` and get started.
|
19
|
+
|
20
|
+
.. code-block:: ruby
|
21
|
+
|
22
|
+
require 'twilio-ruby'
|
23
|
+
|
24
|
+
# To find these visit https://www.twilio.com/user/account
|
25
|
+
account_sid = "ACXXXXXXXXXXXXXXXXX"
|
26
|
+
auth_token = "YYYYYYYYYYYYYYYYYY"
|
27
|
+
|
28
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
29
|
+
|
30
|
+
|
31
|
+
Listing Resources
|
32
|
+
-------------------
|
33
|
+
|
34
|
+
The :class:`Client` gives you access to various list resources.
|
35
|
+
:meth:`ListResource.list`, by default, returns the most recent 50 instance resources.
|
36
|
+
|
37
|
+
.. code-block:: ruby
|
38
|
+
|
39
|
+
require 'twilio-ruby'
|
40
|
+
|
41
|
+
# To find these visit https://www.twilio.com/user/account
|
42
|
+
account_sid = "ACXXXXXXXXXXXXXXXXX"
|
43
|
+
auth_token = "YYYYYYYYYYYYYYYYYY"
|
44
|
+
|
45
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
46
|
+
@calls = client.calls.list()
|
47
|
+
|
48
|
+
:meth:`ListResource.list` accepts paging arguments.
|
49
|
+
The following will return page 3 with page size of 25.
|
50
|
+
|
51
|
+
.. code-block:: python
|
52
|
+
|
53
|
+
require 'twilio-ruby'
|
54
|
+
|
55
|
+
# To find these visit https://www.twilio.com/user/account
|
56
|
+
account_sid = "ACXXXXXXXXXXXXXXXXX"
|
57
|
+
auth_token = "YYYYYYYYYYYYYYYYYY"
|
58
|
+
|
59
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
60
|
+
@calls = client.calls.list(page=3, page_size=25)
|
61
|
+
|
62
|
+
|
63
|
+
Get an Individual Resource
|
64
|
+
-----------------------------
|
65
|
+
|
66
|
+
To get an individual instance resource, use :meth:`ListResource.get`.
|
67
|
+
Provide the :attr:`sid` of the resource you'd like to get.
|
68
|
+
|
69
|
+
.. code-block:: ruby
|
70
|
+
|
71
|
+
require 'twilio-ruby'
|
72
|
+
|
73
|
+
# To find these visit https://www.twilio.com/user/account
|
74
|
+
account_sid = "ACXXXXXXXXXXXXXXXXX"
|
75
|
+
auth_token = "YYYYYYYYYYYYYYYYYY"
|
76
|
+
|
77
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
78
|
+
|
79
|
+
@call = @client.calls.get("CA123")
|
80
|
+
puts @call.to
|
81
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
.. module:: twilio.rest.resources
|
2
|
+
|
3
|
+
=================
|
4
|
+
Caller Ids
|
5
|
+
=================
|
6
|
+
|
7
|
+
|
8
|
+
Validate a Phone Number
|
9
|
+
-----------------------
|
10
|
+
|
11
|
+
Validating a phone number is quick and easy.
|
12
|
+
|
13
|
+
.. code-block:: ruby
|
14
|
+
|
15
|
+
require 'twilio-ruby'
|
16
|
+
|
17
|
+
# To find these visit https://www.twilio.com/user/account
|
18
|
+
account_sid = "ACXXXXXXXXXXXXXXXXX"
|
19
|
+
auth_token = "YYYYYYYYYYYYYYYYYY"
|
20
|
+
|
21
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
22
|
+
@response = @client.caller_ids.create("+44 9876543212")
|
23
|
+
puts @response.validation_code
|
24
|
+
|
25
|
+
Twilio will call the provided number and wait for the validation code to be
|
26
|
+
entered.
|
27
|
+
|
28
|
+
Delete a Phone Number
|
29
|
+
---------------------
|
30
|
+
|
31
|
+
Deleting a phone number is quick and easy.
|
32
|
+
|
33
|
+
.. code-block:: ruby
|
34
|
+
|
35
|
+
require 'twilio-ruby'
|
36
|
+
|
37
|
+
# To find these visit https://www.twilio.com/user/account
|
38
|
+
account_sid = "ACXXXXXXXXXXXXXXXXX"
|
39
|
+
auth_token = "YYYYYYYYYYYYYYYYYY"
|
40
|
+
|
41
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
42
|
+
|
43
|
+
@response = @client.caller_ids.list(phone_number="+15555555555")
|
44
|
+
@callerid = response[0]
|
45
|
+
@callerid.delete()
|
@@ -0,0 +1,108 @@
|
|
1
|
+
.. module:: twilio.rest.resources
|
2
|
+
|
3
|
+
==============================
|
4
|
+
Conferences and Participants
|
5
|
+
==============================
|
6
|
+
|
7
|
+
For more information, see the `Conference REST Resource <http://www.twilio.com/docs/api/rest/conference>`_
|
8
|
+
and `Participant REST Resource <http://www.twilio.com/docs/api/rest/participant>`_ documentation.
|
9
|
+
|
10
|
+
|
11
|
+
Listing Conferences
|
12
|
+
-----------------------
|
13
|
+
|
14
|
+
.. code-block:: ruby
|
15
|
+
|
16
|
+
require 'twilio-ruby'
|
17
|
+
|
18
|
+
# To find these visit https://www.twilio.com/user/account
|
19
|
+
account_sid = "ACXXXXXXXXXXXXXXXXX"
|
20
|
+
auth_token = "YYYYYYYYYYYYYYYYYY"
|
21
|
+
|
22
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
23
|
+
@conferences = @client.conferences.list()
|
24
|
+
|
25
|
+
@conferences.each do |conference|
|
26
|
+
puts conference.sid
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
Filtering Conferences
|
31
|
+
-----------------------
|
32
|
+
|
33
|
+
The :meth:`Twilio::REST::Conferences.list` method supports filtering on :attr:`status`,
|
34
|
+
:attr:`date_updated`, :attr:`date_created` and :attr:`friendly_name`. The following code
|
35
|
+
will return a list of all in-progress conferences and print their friendly name.
|
36
|
+
|
37
|
+
.. code-block:: ruby
|
38
|
+
|
39
|
+
require 'twilio-ruby'
|
40
|
+
|
41
|
+
# To find these visit https://www.twilio.com/user/account
|
42
|
+
account_sid = "ACXXXXXXXXXXXXXXXXX"
|
43
|
+
auth_token = "YYYYYYYYYYYYYYYYYY"
|
44
|
+
|
45
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
46
|
+
@conferences = @client.conferences.list({:status => "in-progress"})
|
47
|
+
|
48
|
+
@conference.each do |conference|
|
49
|
+
puts conference.friendly_name
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
Listing Participants
|
54
|
+
----------------------
|
55
|
+
|
56
|
+
Each :class:`Conference` has a :attr:`participants` instance which represents all current users in the conference
|
57
|
+
|
58
|
+
.. code-block:: ruby
|
59
|
+
|
60
|
+
require 'twilio-ruby'
|
61
|
+
|
62
|
+
# To find these visit https://www.twilio.com/user/account
|
63
|
+
account_sid = "ACXXXXXXXXXXXXXXXXX"
|
64
|
+
auth_token = "YYYYYYYYYYYYYYYYYY"
|
65
|
+
|
66
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
67
|
+
@conference = @client.conferences.get("CF123")
|
68
|
+
|
69
|
+
@conference.participants.list.each.do |paricipant|
|
70
|
+
puts participant.sid
|
71
|
+
end
|
72
|
+
|
73
|
+
:class:`Conferences` and :class:`Participants` are subclasses of :class:`ListResource`.
|
74
|
+
Therefore, their instances have the inherited methods such as :meth:`count`.
|
75
|
+
|
76
|
+
|
77
|
+
Managing Participants
|
78
|
+
----------------------
|
79
|
+
|
80
|
+
Each :class:`Conference` has a :attr:`participants` function that returns a
|
81
|
+
:class:`Participants` instance. This behavior differs from other list resources
|
82
|
+
because :class:`Participants` needs a participant sid AND a conference sid to
|
83
|
+
access the participants resource.
|
84
|
+
|
85
|
+
Participants can be either muted or kicked out of the conference. The following
|
86
|
+
code kicks out the first participant and mutes the rest.
|
87
|
+
|
88
|
+
.. code-block:: ruby
|
89
|
+
|
90
|
+
require 'twilio-ruby'
|
91
|
+
|
92
|
+
# To find these visit https://www.twilio.com/user/account
|
93
|
+
account_sid = "ACXXXXXXXXXXXXXXXXX"
|
94
|
+
auth_token = "YYYYYYYYYYYYYYYYYY"
|
95
|
+
|
96
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
97
|
+
@participants = @client.conferences.get("CF123").participants.list()
|
98
|
+
|
99
|
+
if @participants.empty?
|
100
|
+
return
|
101
|
+
|
102
|
+
# Kick the first person out
|
103
|
+
@participants.pop().kick()
|
104
|
+
|
105
|
+
# And mute the rest
|
106
|
+
@participants.each do |participant|
|
107
|
+
participant.mute()
|
108
|
+
|
@@ -0,0 +1,110 @@
|
|
1
|
+
.. module:: twilio.rest.resources.sms_messages
|
2
|
+
|
3
|
+
============
|
4
|
+
Messages
|
5
|
+
============
|
6
|
+
|
7
|
+
For more information, see the
|
8
|
+
`Message REST Resource <http://www.twilio.com/docs/api/rest/message>`_
|
9
|
+
documentation.
|
10
|
+
|
11
|
+
|
12
|
+
Sending a Text Message
|
13
|
+
----------------------
|
14
|
+
|
15
|
+
Send a text message in only a few lines of code.
|
16
|
+
|
17
|
+
.. code-block:: ruby
|
18
|
+
|
19
|
+
require 'twilio-ruby'
|
20
|
+
|
21
|
+
# To find these visit https://www.twilio.com/user/account
|
22
|
+
account_sid = "ACXXXXXXXXXXXXXXXXX"
|
23
|
+
auth_token = "YYYYYYYYYYYYYYYYYY"
|
24
|
+
|
25
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
26
|
+
|
27
|
+
@message = client.messages.create({:to => "+13216851234",
|
28
|
+
:from => "+15555555555",
|
29
|
+
:body => "Hello!"})
|
30
|
+
|
31
|
+
If you want to send a message from a `short code
|
32
|
+
<http://www.twilio.com/api/sms/short-codes>`_ on Twilio, just set :attr:`from`
|
33
|
+
to your short code's number.
|
34
|
+
|
35
|
+
|
36
|
+
Sending a Picture Message
|
37
|
+
-------------------------
|
38
|
+
|
39
|
+
To send a picture, set :attr:`media_url` to the url of the picture you wish to send.
|
40
|
+
|
41
|
+
.. code-block:: ruby
|
42
|
+
|
43
|
+
require 'twilio-ruby'
|
44
|
+
|
45
|
+
# To find these visit https://www.twilio.com/user/account
|
46
|
+
account_sid = "ACXXXXXXXXXXXXXXXXX"
|
47
|
+
auth_token = "YYYYYYYYYYYYYYYYYY"
|
48
|
+
|
49
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
50
|
+
|
51
|
+
@message = client.messages.create({:to => "+15558676309",
|
52
|
+
:from => "+15555555555",
|
53
|
+
:body => "Jenny I need you!",
|
54
|
+
:media_url => "http://twilio.com/heart.jpg"})
|
55
|
+
|
56
|
+
You can send multiple pictures in the same message by setting :attr:`media_url` to
|
57
|
+
an array of urls.
|
58
|
+
|
59
|
+
.. code-block:: ruby
|
60
|
+
|
61
|
+
@message = client.messages.create({:to => "+15558676309",
|
62
|
+
:from => "+15555555555",
|
63
|
+
:body => "Jenny I need you!",
|
64
|
+
:media_url => [
|
65
|
+
"http://twilio.com/heart.jpg",
|
66
|
+
"http://twilio.com/rose.jpg"
|
67
|
+
]})
|
68
|
+
|
69
|
+
|
70
|
+
Retrieving Sent Messages
|
71
|
+
-------------------------
|
72
|
+
|
73
|
+
.. code-block:: ruby
|
74
|
+
|
75
|
+
require 'twilio-ruby'
|
76
|
+
|
77
|
+
# To find these visit https://www.twilio.com/user/account
|
78
|
+
account_sid = "ACXXXXXXXXXXXXXXXXX"
|
79
|
+
auth_token = "YYYYYYYYYYYYYYYYYY"
|
80
|
+
|
81
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
82
|
+
|
83
|
+
@client.messages.each do |message|
|
84
|
+
puts message.body
|
85
|
+
|
86
|
+
|
87
|
+
Filtering Your Messages
|
88
|
+
-------------------------
|
89
|
+
|
90
|
+
The :meth:`list` methods supports filtering on :attr:`to`, :attr:`from`,
|
91
|
+
and :attr:`date_sent`.
|
92
|
+
The following will only show messages to "+5466758723" on January 1st, 2011.
|
93
|
+
|
94
|
+
.. code-block:: ruby
|
95
|
+
|
96
|
+
require 'twilio-ruby'
|
97
|
+
|
98
|
+
# To find these visit https://www.twilio.com/user/account
|
99
|
+
account_sid = "ACXXXXXXXXXXXXXXXXX"
|
100
|
+
auth_token = "YYYYYYYYYYYYYYYYYY"
|
101
|
+
|
102
|
+
@client = Twilio::REST::Client.new account_sid, auth_token
|
103
|
+
|
104
|
+
@messages = client.messages.list({:to => "+5466758723",
|
105
|
+
:date_sent => date(2011,1,1)})
|
106
|
+
|
107
|
+
@messages.each do |message|
|
108
|
+
puts message.body
|
109
|
+
|
110
|
+
|