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.
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,96 @@
1
+ .. module:: twilio.rest.resources
2
+
3
+ ================
4
+ Recordings
5
+ ================
6
+
7
+ For more information, see the
8
+ `Recordings REST Resource <http://www.twilio.com/docs/api/rest/recording>`_
9
+ documentation.
10
+
11
+
12
+ Audio Formats
13
+ -----------------
14
+
15
+ Each :class:`Recording` has a few special methods. To get the url
16
+ for the wav format of this recording, use :meth:`Recording.wav`. For the
17
+ mp3 format, use :meth:`Recording.mp3`. To make requests for either of
18
+ these formats use the same method with a '!' appended. These methods
19
+ both take a block to be executed as soon as the response returns.
20
+
21
+
22
+ Listing Your Recordings
23
+ ----------------------------
24
+
25
+ The following code will print out the :attr:`duration`
26
+ for each :class:`Recording`.
27
+
28
+ .. code-block:: ruby
29
+
30
+ require 'twilio-ruby'
31
+
32
+ # To find these visit https://www.twilio.com/user/account
33
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
34
+ auth_token = "YYYYYYYYYYYYYYYYYY"
35
+
36
+ @client = Twilio::REST::Client.new account_sid, auth_token
37
+
38
+ @client.recordings.list().each do |recording|
39
+ puts recording.duration
40
+
41
+ You can filter recordings by CallSid by passing the Sid as :attr:`call`.
42
+ Filter recordings using :attr:`before` and :attr:`after` dates.
43
+
44
+ The following will only show recordings made before January 1, 2011.
45
+
46
+ .. code-block:: ruby
47
+
48
+ require 'twilio-ruby'
49
+
50
+ # To find these visit https://www.twilio.com/user/account
51
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
52
+ auth_token = "YYYYYYYYYYYYYYYYYY"
53
+
54
+ @client = Twilio::REST::Client.new account_sid, auth_token
55
+ @client.recordings.list(before=date(2011,1,1)).each do |recording|:
56
+ puts recording.duration
57
+
58
+
59
+ Deleting Recordings
60
+ ---------------------
61
+
62
+ The :class:`Recordings` resource allows you to delete unnecessary recordings.
63
+
64
+ .. code-block:: ruby
65
+
66
+ require 'twilio-ruby'
67
+
68
+ # To find these visit https://www.twilio.com/user/account
69
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
70
+ auth_token = "YYYYYYYYYYYYYYYYYY"
71
+
72
+ @client = Twilio::REST::Client.new account_sid, auth_token
73
+ @client.recordings.get("RC123").delete()
74
+
75
+
76
+ Accessing Related Transcptions
77
+ -------------------------------
78
+
79
+ The :class:`Recordings` allows you to retrieve associated transcriptions.
80
+ The following prints out the text for each of the transcriptions associated
81
+ with this recording.
82
+
83
+ .. code-block:: ruby
84
+
85
+ require 'twilio-ruby'
86
+
87
+ # To find these visit https://www.twilio.com/user/account
88
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
89
+ auth_token = "YYYYYYYYYYYYYYYYYY"
90
+
91
+ @client = Twilio::REST::Client.new account_sid, auth_token
92
+ @recording = @client.recordings.get("RC123")
93
+
94
+ @recording.transcriptions.list().each do |transcription|
95
+ puts transcription.transcription_text
96
+
@@ -0,0 +1,103 @@
1
+ =============
2
+ Sip In
3
+ =============
4
+
5
+ Getting started with Sip In
6
+ ===========================
7
+
8
+ If you're unfamiliar with SIP, please see the `SIP API Documentation
9
+ <https://www.twilio.com/docs/api/rest/sip>`_ on our website. If you want
10
+ to make a regular phone call, take a look at :doc:`phone-calls`.
11
+
12
+ Creating a Sip Domain
13
+ =====================
14
+
15
+ The :class:`Domains` resource allows you to create a new domain. To
16
+ create a new domain, you'll need to choose a unique domain that lives
17
+ under sip.twilio.com.
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
+
29
+ @domain = @client.sip.domains.create(
30
+ {:friendly_name => "The Office Domain",
31
+ :voice_url => "http://example.com/voice",
32
+ :domain_name => "dunder-mifflin-scranton.sip.twilio.com",}
33
+ )
34
+ puts @domain.sid
35
+
36
+ Creating a new IpAccessControlList
37
+ ==================================
38
+
39
+ To control access to your new domain, you'll need to explicitly grant access
40
+ to individual ip addresses. To do this, you'll first need to create an
41
+ :class:`IpAccessControlList` to hold the ip addresses you wish to allow.
42
+
43
+ .. code-block:: ruby
44
+
45
+ require 'twilio-ruby'
46
+
47
+ # To find these visit https://www.twilio.com/user/account
48
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
49
+ auth_token = "YYYYYYYYYYYYYYYYYY"
50
+
51
+ @client = Twilio::REST::Client.new account_sid, auth_token
52
+
53
+ @ip_acl = @client.sip.ip_access_control_lists.create(
54
+ {:friendly_name => "The Office IpAccessControlList",}
55
+ )
56
+ puts @ip_acl.sid
57
+
58
+ Adding a new IpAddress
59
+ =========================
60
+
61
+ Now it's time to add an :class:`IpAddress` to your new :class:`IpAccessControlList`.
62
+
63
+ .. code-block:: ruby
64
+
65
+ require 'twilio-ruby'
66
+
67
+ # To find these visit https://www.twilio.com/user/account
68
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
69
+ auth_token = "YYYYYYYYYYYYYYYYYY"
70
+
71
+ @client = Twilio::REST::Client.new account_sid, auth_token
72
+
73
+ @ip_address = @client.sip.ip_access_control_lists.get(
74
+ "AL456", # IpAccessControlList sid
75
+ ).ip_addresses.create(
76
+ {:friendly_name => "Dwights's Computer",
77
+ :ip_address => "192.168.1.42",}
78
+ )
79
+ puts @ip_address.sid
80
+
81
+ Adding an IpAccessControlList to a Domain
82
+ ===========================================
83
+
84
+ Once you've created a :class:`Domain` and an :class:`IpAccessControlList` you need to
85
+ associate them. To do this, create an :class:`IpAccessControlListMapping`.
86
+
87
+ .. code-block:: ruby
88
+
89
+ require 'twilio-ruby'
90
+
91
+ # To find these visit https://www.twilio.com/user/account
92
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
93
+ auth_token = "YYYYYYYYYYYYYYYYYY"
94
+
95
+ @client = Twilio::REST::Client.new account_sid, auth_token
96
+
97
+ @ip_acl_mapping = @client.sip.domains.get(
98
+ "SD456", # SIP Domain sid
99
+ ).ip_access_control_list_mappings.create(
100
+ {:ip_access_control_list_sid => "AL789"})
101
+
102
+ puts @ip_acl_mapping.sid
103
+
@@ -0,0 +1,81 @@
1
+ .. module:: twilio.util
2
+
3
+ ===========================
4
+ Generate Capability Tokens
5
+ ===========================
6
+
7
+ `Twilio Client <http://www.twilio.com/api/client>`_ allows you to make and
8
+ receive connections in the browser.
9
+ You can place a call to a phone on the PSTN network,
10
+ all without leaving your browser. See the `Twilio Client Quickstart
11
+ <http:/www.twilio.com/docs/quickstart/client>`_ to get up and running with
12
+ Twilio Client.
13
+
14
+ Capability tokens are used by `Twilio Client
15
+ <http://www.twilio.com/api/client>`_ to provide connection
16
+ security and authorization. The `Capability Token documentation
17
+ <http://www.twilio.com/docs/tokens>`_ explains in depth the purpose and
18
+ features of these tokens.
19
+
20
+ :class:`TwilioCapability` is responsible for the creation of these capability
21
+ tokens. You'll need your Twilio AccountSid and AuthToken.
22
+
23
+ .. code-block:: ruby
24
+
25
+ require 'twilio-ruby'
26
+
27
+ # Find these values at twilio.com/user/account
28
+ account_sid = "AC123123"
29
+ auth_token = "secret"
30
+
31
+ @capability = Twilio::Util::Capability.new account_sid, auth_token
32
+
33
+
34
+ Allow Incoming Connections
35
+ ==============================
36
+
37
+ Before a device running `Twilio Client <http://www.twilio.com/api/client>`_
38
+ can recieve incoming connections, the instance must first register a name
39
+ (such as "Alice" or "Bob").
40
+ The :meth:`allow_client_incoming` method adds the client name to the
41
+ capability token.
42
+
43
+ .. code-block:: ruby
44
+
45
+ @capability.allow_client_incoming("Alice")
46
+
47
+
48
+ Allow Outgoing Connections
49
+ ==============================
50
+
51
+ To make an outgoing connection from a
52
+ `Twilio Client <http://www.twilio.com/api/client>`_ device,
53
+ you'll need to choose a
54
+ `Twilio Application <http://www.twilio.com/docs/api/rest/applications>`_
55
+ to handle TwiML URLs. A Twilio Application is a collection of URLs responsible
56
+ for outputting valid TwiML to control phone calls and messages.
57
+
58
+ .. code-block:: ruby
59
+
60
+ # Twilio Application Sid
61
+ application_sid = "APabe7650f654fc34655fc81ae71caa3ff"
62
+ @capability.allow_client_outgoing(application_sid)
63
+
64
+
65
+ Generate a Token
66
+ ==================
67
+
68
+ .. code-block:: ruby
69
+
70
+ @token = @capability.generate()
71
+
72
+ By default, this token will expire in one hour. If you'd like to change the
73
+ token expiration, :meth:`generate` takes an optional :attr:`ttl` argument.
74
+
75
+ .. code-block:: ruby
76
+
77
+ @token = @capability.generate(ttl=600)
78
+
79
+ This token will now expire in 10 minutes. If you haven't guessed already,
80
+ :attr:`ttl` is expressed in seconds.
81
+
@@ -0,0 +1,31 @@
1
+ .. module:: twilio.rest.resources
2
+
3
+ ================
4
+ Transcriptions
5
+ ================
6
+
7
+ Transcriptions are generated from recordings via the
8
+ `TwiML <Record> verb <http://www.twilio.com/docs/api/twiml/record>`_.
9
+ Using the API, you can only read your transcription records.
10
+
11
+ For more information, see the `Transcriptions REST Resource
12
+ <http://www.twilio.com/docs/api/rest/transcription>`_ documentation.
13
+
14
+
15
+ Listing Your Transcriptions
16
+ ----------------------------
17
+
18
+ The following code will print out the length of each :class:`Transcription`.
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.transcriptions.list().each do |transcription|
30
+ puts transcription.duration
31
+
@@ -0,0 +1,70 @@
1
+ .. _usage-twiml:
2
+
3
+ .. module:: twilio.twiml
4
+
5
+ ==============
6
+ TwiML Creation
7
+ ==============
8
+
9
+ TwiML creation begins with the :class:`Response` verb.
10
+ Each successive verb is created by calling various methods on the response,
11
+ such as :meth:`say` or :meth:`play`.
12
+ These methods return the verbs they create to ease creation of nested TwiML.
13
+ To finish, call the :meth:`toxml` method on the :class:`Response`,
14
+ which returns raw TwiML.
15
+
16
+ .. code-block:: python
17
+
18
+ require 'twilio-ruby'
19
+
20
+ Twilio::TwiML::Response.new do |r|
21
+ r.Say "Hello"
22
+ end.text
23
+
24
+ .. code-block:: xml
25
+
26
+ <?xml version="1.0" encoding="utf-8"?>
27
+ <Response><Say>Hello</Say><Response>
28
+
29
+ The verb methods (outlined in the :doc:`complete reference </api/twiml>`)
30
+ take the body (only text) of the verb as the first argument.
31
+ All attributes are keyword arguments.
32
+
33
+ .. code-block:: python
34
+
35
+ require 'twilio-ruby'
36
+
37
+ Twilio::TwiML::Response.new do |r|
38
+ r.Play "https://api.twilio.com/cowbell.mp3", :loop => 5
39
+ end.text
40
+
41
+ .. code-block:: xml
42
+
43
+ <?xml version="1.0" encoding="utf-8"?>
44
+ <Response>
45
+ <Play loop="3">https://api.twilio.com/cowbell.mp3</Play>
46
+ <Response>
47
+
48
+ Python 2.6+ added the :const:`with` statement for context management.
49
+ Using :const:`with`, the module can *almost* emulate Ruby blocks.
50
+
51
+ .. code-block:: python
52
+
53
+ require 'twilio-ruby'
54
+
55
+ Twilio::TwiML::Response.new do |r|
56
+ r.Say "hello"
57
+ r.Gather :finish_on_key => 4 do |g|
58
+ g.Say "world"
59
+ end
60
+ end.text
61
+
62
+ which returns the following
63
+
64
+ .. code-block:: xml
65
+
66
+ <?xml version="1.0" encoding="utf-8"?>
67
+ <Response>
68
+ <Say>Hello</Say>
69
+ <Gather finishOnKey="4"><Say>World</Say></Gather>
70
+ </Response>
@@ -0,0 +1,71 @@
1
+ .. module:: twilio.util
2
+
3
+ ===========================
4
+ Validate Incoming Requests
5
+ ===========================
6
+
7
+ Twilio requires that your TwiML-serving web server be open to the public. This
8
+ is necessary so that Twilio can retrieve TwiML from urls and POST data back to
9
+ your server.
10
+
11
+ However, there may be people out there trying to spoof the Twilio service.
12
+ Luckily, there's an easy way to validate that incoming requests are from Twilio
13
+ and Twilio alone.
14
+
15
+ An in-depth guide to our security features can be `found in our online
16
+ documentation <http://www.twilio.com/docs/security>`_.
17
+
18
+ Before you can validate requests, you'll need four pieces of information:
19
+
20
+ * your Twilio Auth Token (found in your `Dashboard
21
+ <https://www.twilio.com/user/account>`_)
22
+ * the POST data for the request
23
+ * the requested URL
24
+ * the X-Twilio-Signature header value
25
+
26
+ Obtaining the last three pieces of information depends on the framework you are
27
+ using to process requests. The below example assumes that you have the POST
28
+ data as a dictionary and the url and X-Twilio-Signature as strings.
29
+
30
+ The below example will print out a confirmation message if the request is
31
+ actually from Twilio.
32
+
33
+ .. code-block:: python
34
+
35
+ require 'twilio-ruby'
36
+
37
+ auth_token = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'
38
+
39
+ @validator = Twilio::Util::RequestValidator.new auth_token
40
+
41
+ # the callback URL you provided to Twilio
42
+ url = "http://www.example.com/my/callback/url.xml"
43
+
44
+ # the POST variables attached to the request (eg "From", "To")
45
+ post_vars = {}
46
+
47
+ # X-Twilio-Signature header value
48
+ signature = "HpS7PBa1Agvt4OtO+wZp75IuQa0=" # will look something like that
49
+
50
+ if @validator.validate(url, post_vars, signature)
51
+ puts "Confirmed to have come from Twilio."
52
+ else
53
+ puts "NOT VALID. It might have been spoofed!"
54
+ end
55
+
56
+
57
+ Trailing Slashes
58
+ ==================
59
+
60
+ If your URL uses an "index" page, such as index.php or index.html to handle
61
+ the request, such as: https://mycompany.com/twilio where the real page
62
+ is served from https://mycompany.com/twilio/index.php, then Apache or
63
+ PHP may rewrite that URL a little bit so it's got a trailing slash, such as
64
+ https://mycompany.com/twilio/ for example.
65
+
66
+ Using the code above, or similar code in another language, you could
67
+ end up with an incorrect hash because Twilio built the hash using
68
+ https://mycompany.com/twilio and you may have built the hash using
69
+ https://mycompany.com/twilio/. More information can be found in our
70
+ documentation on validating requests.
71
+