twilio-ruby 3.10.1 → 3.11.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.
Files changed (60) hide show
  1. data/AUTHORS.md +24 -0
  2. data/CHANGES +11 -0
  3. data/Makefile +13 -0
  4. data/README.md +28 -13
  5. data/docs/Makefile +130 -0
  6. data/docs/_themes/LICENSE +45 -0
  7. data/docs/_themes/README.rst +25 -0
  8. data/docs/_themes/flask_theme_support.py +86 -0
  9. data/docs/_themes/kr/layout.html +32 -0
  10. data/docs/_themes/kr/relations.html +19 -0
  11. data/docs/_themes/kr/static/flasky.css_t +469 -0
  12. data/docs/_themes/kr/static/small_flask.css +70 -0
  13. data/docs/_themes/kr/theme.conf +7 -0
  14. data/docs/_themes/kr_small/layout.html +22 -0
  15. data/docs/_themes/kr_small/static/flasky.css_t +287 -0
  16. data/docs/_themes/kr_small/theme.conf +10 -0
  17. data/docs/changelog.rst +1 -0
  18. data/docs/conf.py +266 -0
  19. data/docs/faq.rst +42 -0
  20. data/docs/getting-started.rst +91 -0
  21. data/docs/index.rst +108 -0
  22. data/docs/make.bat +170 -0
  23. data/docs/src/pip-delete-this-directory.txt +5 -0
  24. data/docs/usage/accounts.rst +89 -0
  25. data/docs/usage/applications.rst +108 -0
  26. data/docs/usage/basics.rst +81 -0
  27. data/docs/usage/caller-ids.rst +45 -0
  28. data/docs/usage/conferences.rst +108 -0
  29. data/docs/usage/messages.rst +110 -0
  30. data/docs/usage/notifications.rst +70 -0
  31. data/docs/usage/phone-calls.rst +168 -0
  32. data/docs/usage/phone-numbers.rst +159 -0
  33. data/docs/usage/queues.rst +112 -0
  34. data/docs/usage/recordings.rst +96 -0
  35. data/docs/usage/sip.rst +103 -0
  36. data/docs/usage/token-generation.rst +81 -0
  37. data/docs/usage/transcriptions.rst +31 -0
  38. data/docs/usage/twiml.rst +70 -0
  39. data/docs/usage/validation.rst +71 -0
  40. data/examples/examples.rb +8 -5
  41. data/lib/twilio-ruby.rb +10 -0
  42. data/lib/twilio-ruby/rest/accounts.rb +1 -1
  43. data/lib/twilio-ruby/rest/instance_resource.rb +2 -1
  44. data/lib/twilio-ruby/rest/list_resource.rb +4 -1
  45. data/lib/twilio-ruby/rest/media.rb +14 -0
  46. data/lib/twilio-ruby/rest/messages.rb +12 -0
  47. data/lib/twilio-ruby/rest/sip.rb +12 -0
  48. data/lib/twilio-ruby/rest/sip/credential_lists.rb +11 -0
  49. data/lib/twilio-ruby/rest/sip/credential_lists/credentials.rb +6 -0
  50. data/lib/twilio-ruby/rest/sip/domains.rb +12 -0
  51. data/lib/twilio-ruby/rest/sip/domains/credential_list_mappings.rb +6 -0
  52. data/lib/twilio-ruby/rest/sip/domains/ip_access_control_list_mappings.rb +6 -0
  53. data/lib/twilio-ruby/rest/sip/ip_access_control_lists.rb +11 -0
  54. data/lib/twilio-ruby/rest/sip/ip_access_control_lists/ip_addresses.rb +6 -0
  55. data/lib/twilio-ruby/rest/sms.rb +1 -1
  56. data/lib/twilio-ruby/rest/usage/records.rb +1 -1
  57. data/lib/twilio-ruby/rest/utils.rb +1 -1
  58. data/lib/twilio-ruby/version.rb +1 -1
  59. data/spec/rest/message_spec.rb +12 -0
  60. metadata +52 -2
@@ -0,0 +1,70 @@
1
+ .. module:: twilio.rest.resources
2
+
3
+ ====================
4
+ Notifications
5
+ ====================
6
+
7
+ For more information, see the `Notifications REST Resource
8
+ <http://www.twilio.com/docs/api/rest/notification>`_ documentation.
9
+
10
+
11
+ Listing Your Notifications
12
+ ----------------------------
13
+
14
+ The following code will print out additional information about each of your
15
+ current :class:`Notification` resources.
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
+ @client.notifications.list().each do |notification|:
28
+ puts notification.more_info
29
+
30
+ You can filter transcriptions by :attr:`log` and :attr:`message_date`.
31
+ The :attr:`log` value is 0 for `ERROR` and 1 for `WARNING`.
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
+ ERROR = 0
44
+
45
+ @client.notifications.list(log=ERROR).each do |notification|:
46
+ puts notification.error_code
47
+
48
+ .. note:: Due to the potentially voluminous amount of data in a notification,
49
+ the full HTTP request and response data is only returned in the
50
+ :class:`Notification` instance resource representation.
51
+
52
+
53
+ Deleting Notifications
54
+ ------------------------
55
+
56
+ Your account can sometimes generate an inordinate amount of
57
+ :class:`Notification` resources. The :class:`Notifications` resource allows
58
+ you to delete unnecessary notifications.
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
+ @client.notifications.get("NO123").delete()
70
+
@@ -0,0 +1,168 @@
1
+ .. module:: twilio.rest
2
+ .. _phone-calls:
3
+
4
+ =====================
5
+ Phone Calls
6
+ =====================
7
+
8
+ The :class:`Calls` resource manages all interaction with Twilio phone calls,
9
+ including the creation and termination of phone calls.
10
+
11
+
12
+ Making a Phone Call
13
+ -------------------
14
+
15
+ The :class:`Calls` resource allows you to make outgoing calls. Before a call
16
+ can be successfully started, you'll need a to set up a url endpoint which
17
+ outputs valid `TwiML <http://www.twilio.com/docs/api/twiml/>`_.
18
+
19
+ .. code-block:: ruby
20
+
21
+ require 'twilio-ruby'
22
+
23
+ # To find these visit https://www.twilio.com/user/account
24
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
25
+ auth_token = "YYYYYYYYYYYYYYYYYY"
26
+
27
+ @client = Twilio::REST::Client.new account_sid, auth_token
28
+ @call = @client.calls.create({:to => "9991231234",
29
+ :from => "9991231234",
30
+ :url => "http://foo.com/call.xml"})
31
+ puts @call.length
32
+ puts @call.sid
33
+
34
+
35
+ Retrieve a Call Record
36
+ -------------------------
37
+
38
+ If you already have a :class:`Call` sid,
39
+ you can use the client to retrieve that record.
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
+ sid = "CA12341234"
51
+ @call = @client.calls.get(sid)
52
+
53
+
54
+ Accessing Specific Call Resources
55
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
56
+
57
+ Each :class:`Call` resource also has access to its `notifications`,
58
+ `recordings`, and `transcriptions`.
59
+ These attributes are :class:`ListResources`,
60
+ just like the :class:`Calls` resource itself.
61
+
62
+ .. code-block:: ruby
63
+
64
+ require 'twilio-ruby'
65
+
66
+ # To find these visit https://www.twilio.com/user/account
67
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
68
+ auth_token = "YYYYYYYYYYYYYYYYYY"
69
+
70
+ @client = Twilio::REST::Client.new account_sid, auth_token
71
+ sid = "CA12341234"
72
+ @call = @client.calls.get(sid)
73
+
74
+ puts @call.notifications.list()
75
+ puts @call.recordings.list()
76
+ puts @call.transcriptions.list()
77
+
78
+ However, what if you only have a `CallSid`, and not the actual
79
+ :class:`Resource`? No worries, as :meth:`list` can be filter based on a given
80
+ `CallSid`.
81
+
82
+ .. code-block:: ruby
83
+
84
+ require 'twilio-ruby'
85
+
86
+ # To find these visit https://www.twilio.com/user/account
87
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
88
+ auth_token = "YYYYYYYYYYYYYYYYYY"
89
+
90
+ @client = Twilio::REST::Client.new account_sid, auth_token
91
+ sid = "CA24234"
92
+ puts @client.notifications.list({:call => sid})
93
+ puts @client.recordings.list({:call => sid})
94
+ puts @client.transcriptions.list({:call => sid})
95
+
96
+
97
+ Modifying Live Calls
98
+ --------------------
99
+
100
+ The :class:`Call` resource makes it easy to find current live calls and
101
+ redirect them as necessary
102
+
103
+ .. code-block:: python
104
+
105
+ .. code-block:: ruby
106
+
107
+ require 'twilio-ruby'
108
+
109
+ # To find these visit https://www.twilio.com/user/account
110
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
111
+ auth_token = "YYYYYYYYYYYYYYYYYY"
112
+
113
+ @client = Twilio::REST::Client.new account_sid, auth_token
114
+ @calls = @client.calls.list({:status => "in-progress")
115
+
116
+ @calls.each do |call|
117
+ call.redirect_to("http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient")
118
+ end
119
+
120
+
121
+ Ending all live calls is also possible
122
+
123
+ .. code-block:: ruby
124
+
125
+ require 'twilio-ruby'
126
+
127
+ # To find these visit https://www.twilio.com/user/account
128
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
129
+ auth_token = "YYYYYYYYYYYYYYYYYY"
130
+
131
+ @client = Twilio::REST::Client.new account_sid, auth_token
132
+ @calls = @client.calls.list({:status => "in-progress")
133
+
134
+ @calls.each do |call|
135
+ call.hangup()
136
+ end
137
+
138
+ Note that :meth:`hangup` will also cancel calls currently queued.
139
+
140
+ If you already have a :class:`Call` sid, you can use the :class:`Calls`
141
+ resource to update the record without having to use :meth:`get` first.
142
+
143
+ .. code-block:: ruby
144
+
145
+ require 'twilio-ruby'
146
+
147
+ # To find these visit https://www.twilio.com/user/account
148
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
149
+ auth_token = "YYYYYYYYYYYYYYYYYY"
150
+
151
+ @client = Twilio::REST::Client.new account_sid, auth_token
152
+ sid = "CA12341234"
153
+ @client.calls.get(sid).redirect_to("http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient")
154
+
155
+ Hanging up the call also works.
156
+
157
+ .. code-block:: ruby
158
+
159
+ require 'twilio-ruby'
160
+
161
+ # To find these visit https://www.twilio.com/user/account
162
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
163
+ auth_token = "YYYYYYYYYYYYYYYYYY"
164
+
165
+ @client = Twilio::REST::Client.new account_sid, auth_token
166
+ sid = "CA12341234"
167
+ @client.calls.get(sid).hangup()
168
+
@@ -0,0 +1,159 @@
1
+ .. module:: twilio.rest.resources
2
+
3
+ =================
4
+ Phone Numbers
5
+ =================
6
+
7
+ With Twilio you can search and buy real phone numbers, just using the API.
8
+
9
+ For more information, see the
10
+ `IncomingPhoneNumbers REST Resource
11
+ <http://www.twilio.com/docs/api/rest/incoming-phone-numbers>`_ documentation.
12
+
13
+
14
+ Searching and Buying a Number
15
+ --------------------------------
16
+
17
+ Finding numbers to buy couldn't be easier.
18
+ We first search for a number in area code 530.
19
+ Once we find one, we'll purchase it for our account.
20
+
21
+ .. code-block:: python
22
+
23
+ from twilio.rest import TwilioRestClient
24
+
25
+ # To find these visit https://www.twilio.com/user/account
26
+ ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
27
+ AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
28
+
29
+ client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
30
+ numbers = client.phone_numbers.search(area_code=530)
31
+
32
+ if numbers:
33
+ numbers[0].purchase()
34
+ else:
35
+ print "No numbers in 530 available"
36
+
37
+
38
+ Toll Free Numbers
39
+ ^^^^^^^^^^^^^^^^^^^^^^^^
40
+
41
+ By default, :meth:`PhoneNumbers.search` looks for local phone numbers. Add a
42
+ :data:`type` : ``tollfree`` parameter to search toll-free numbers instead.
43
+
44
+ .. code-block:: python
45
+
46
+ numbers = client.phone_numbers.search(type="tollfree")
47
+
48
+
49
+ Numbers Containing Words
50
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^
51
+
52
+ Phone number search also supports looking for words inside phone numbers.
53
+ The following example will find any phone number with "FOO" in it.
54
+
55
+ .. code-block:: python
56
+
57
+ numbers = client.phone_numbers.search(contains="FOO")
58
+
59
+ You can use the ''*'' wildcard to match any character. The following example finds any phone number that matches the pattern ''D*D''.
60
+
61
+ .. code-block:: python
62
+
63
+ numbers = client.phone_numbers.search(contains="D*D")
64
+
65
+
66
+ International Numbers
67
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^
68
+
69
+ By default, the client library will look for US numbers. Set the
70
+ :data:`country` keyword to a country code of your choice to search for
71
+ international numbers.
72
+
73
+ .. code-block:: python
74
+
75
+ numbers = client.phone_numbers.search(country="FR")
76
+
77
+
78
+ :meth:`PhoneNumbers.search` method has plenty of other options to augment your search :
79
+
80
+ - :data:`region`: When searching the US, show numbers in this state
81
+ - :data:`postal_code`: Only show numbers in this area code
82
+ - :data:`rate_center`: US only.
83
+ - :data:`near_lat_long`: Find numbers near this latitude and longitude.
84
+ - :data:`distance`: Search radius for a Near- query in miles.
85
+
86
+ The `AvailablePhoneNumbers REST Resource
87
+ <http://www.twilio.com/docs/api/rest/available-phone-numbers>`_ documentation
88
+ has more information on the various search options.
89
+
90
+
91
+ Buying a Number
92
+ ---------------
93
+
94
+ If you've found a phone number you want, you can purchase the number.
95
+
96
+ .. code-block:: python
97
+
98
+ from twilio.rest import TwilioRestClient
99
+
100
+ # To find these visit https://www.twilio.com/user/account
101
+ ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
102
+ AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
103
+
104
+ client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
105
+ number = client.phone_numbers.purchase(phone_number="+15305431234")
106
+
107
+ However, it's easier to purchase numbers after finding them using search (as
108
+ shown in the first example).
109
+
110
+
111
+ Updating Properties on a Number
112
+ -------------------------------
113
+
114
+ To update the properties on a phone number, call :meth:`update`
115
+ on the phone number object, with any of the parameters
116
+ listed in the `IncomingPhoneNumbers Resource documentation
117
+ <http://www.twilio.com/docs/api/rest/incoming-phone-numbers>`_
118
+
119
+ .. code-block:: python
120
+
121
+ from twilio.rest import TwilioRestClient
122
+
123
+ # To find these visit https://www.twilio.com/user/account
124
+ ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
125
+ AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
126
+
127
+ client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
128
+ for number in client.phone_numbers.list(api_version="2010-04-01"):
129
+ number.update(voice_url="http://twimlets.com/holdmusic?" +
130
+ "Bucket=com.twilio.music.ambient",
131
+ status_callback="http://example.com/callback")
132
+
133
+
134
+ Changing Applications
135
+ ----------------------
136
+
137
+ An :class:`Application` encapsulates all necessary URLs for use with phone numbers. Update an application on a phone number using :meth:`update`.
138
+
139
+ .. code-block:: python
140
+
141
+ from twilio.rest import TwilioRestClient
142
+
143
+ phone_sid = "PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
144
+
145
+ # To find these visit https://www.twilio.com/user/account
146
+ ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
147
+ AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
148
+
149
+ client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
150
+ number = client.phone_numbers.update(phone_sid, sms_application_sid="AP123")
151
+
152
+ See :doc:`/usage/applications` for instructions on updating and maintaining Applications.
153
+
154
+
155
+ Validate a Phone Number
156
+ -----------------------
157
+
158
+ See validation instructions here: :doc:`/usage/caller-ids`:
159
+
@@ -0,0 +1,112 @@
1
+ .. module:: twilio.rest.resources
2
+
3
+ ==============================
4
+ Queues and Members
5
+ ==============================
6
+
7
+ For more information, see the
8
+ `Queue REST Resource <http://www.twilio.com/docs/api/rest/queue>`_
9
+ and `Member REST Resource <http://www.twilio.com/docs/api/rest/member>`_
10
+ documentation.
11
+
12
+
13
+ Listing Queues
14
+ -----------------------
15
+
16
+ .. code-block:: ruby
17
+
18
+ require 'twilio-ruby'
19
+
20
+ # To find these visit https://www.twilio.com/user/account
21
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
22
+ auth_token = "YYYYYYYYYYYYYYYYYY"
23
+
24
+ @client = Twilio::REST::Client.new account_sid, auth_token
25
+ @queues = client.queues.list()
26
+
27
+ @queues.each do |queue|
28
+ puts queue.sid
29
+ end
30
+
31
+
32
+ Listing Queue Members
33
+ ----------------------
34
+
35
+ Each :class:`Queue` has a :attr:`members` instance which
36
+ represents all current calls in the queue.
37
+
38
+ .. code-block:: ruby
39
+
40
+ require 'twilio-ruby'
41
+
42
+ # To find these visit https://www.twilio.com/user/account
43
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
44
+ auth_token = "YYYYYYYYYYYYYYYYYY"
45
+
46
+ @client = Twilio::REST::Client.new account_sid, auth_token
47
+ @queue = @client.queues.get("QU123")
48
+
49
+ @queue.members.list().each do |member|
50
+ print member.call_sid
51
+ end
52
+
53
+
54
+ Getting a specific Queue Member
55
+ -------------------------------
56
+
57
+ To retrieve information about a specific member in the queue, each
58
+ :class:`Members` has a :attr:`get` method. :attr:`get` accepts one
59
+ argument. The argument can either be a `call_sid` thats in the queue,
60
+ in which case :attr:`get` will return a :class:`Member` instance
61
+ representing that call, or the argument can be 'Front', in which case
62
+ :attr:`Get` will return a :class:`Member` instance representing the
63
+ first call in the queue.
64
+
65
+ .. code-block:: ruby
66
+
67
+ require 'twilio-ruby'
68
+
69
+ # To find these visit https://www.twilio.com/user/account
70
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
71
+ auth_token = "YYYYYYYYYYYYYYYYYY"
72
+
73
+ @client = Twilio::REST::Client.new account_sid, auth_token
74
+
75
+ queue_sid = "QUAAAAAAAAAAAAA"
76
+ call_sid = "CAXXXXXXXXXXXXXX"
77
+
78
+ @members = @client.queues.get(queue_sid).members
79
+
80
+ # Get the first call in the queue
81
+ puts members.front.date_enqueued
82
+
83
+ # Get the call with the given call sid in the queue
84
+ puts members.get(call_sid).current_position
85
+
86
+
87
+ Dequeueing Queue Members
88
+ ------------------------
89
+
90
+ To dequeue a specific member from the queue, each
91
+ :class:`Members` has a :attr:`dequeue` method. :attr:`dequeue` accepts an
92
+ argument and two optional keyword arguments. The first argument is the
93
+ url of the twiml document to be executed when the member is
94
+ dequeued. The other two are :attr:`call_sid` and :attr:`method`, their
95
+ default values are 'Front' and 'GET'
96
+
97
+ .. code-block:: ruby
98
+
99
+ require 'twilio-ruby'
100
+
101
+ # To find these visit https://www.twilio.com/user/account
102
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
103
+ auth_token = "YYYYYYYYYYYYYYYYYY"
104
+
105
+ @client = Twilio::REST::Client.new account_sid, auth_token
106
+
107
+ queue_sid = "QUAAAAAAAAAAAAA"
108
+
109
+ @members = @client.queues.get(queue_sid).members
110
+
111
+ # Dequeue the first call in the queue
112
+ puts @members.dequeue('http://www.twilio.com/welcome/call')