8000 Add documentation for Twiio Capability. · michaelhelmick/twilio-python@b7a3b43 · GitHub
[go: up one dir, main page]

Skip to content

Commit b7a3b43

Browse files
committed
Add documentation for Twiio Capability.
1 parent f91ab01 commit b7a3b43

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

docs/api/util.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
====================
2+
:mod:`twilio.util`
3+
====================
4+
5+
.. automodule:: twilio.util
6+
7+
.. autoclass:: twilio.util.RequestValidator
8+
:members:
9+
10+
.. autoclass:: twilio.util.TwilioCapability
11+
:members: allow_client_incoming, allow_client_outgoing, generate
12+
13+

docs/usage/token-generation.rst

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 recieve connections in the browser. You can place a call to a phone on the PSTN network, all without leaving your browser. See the `Twilio Client Quickstart <http:/www.twilio.com/docs/quickstart/client>`_ to get up and running with Twilio Client.
8+
9+
Capability tokens are used by `Twilio Client <http://www.twilio.com/api/client>`_ to provide connection security and authorization. The `Capability Token documentation <http://www.twilio.con/docs/tokens>`_ explains indepth the purpose and features of these tokens.
10+
11+
:class:`TwilioCapability` is responsible for the creation of these capability tokens. You'll need your Twilio AccountSid and AuthToken.
12+
13+
.. code-block:: python
14+
15+
from twilio.util import TwilioCapability
16+
17+
account_sid = "AC123123"
18+
auth_token = "secret"
19+
20+
capability = TwilioCability(account_sid, auth_token)
21+
22+
23+
Allow Incoming Connections
24+
==============================
25+
26+
Before a device running `Twilio Client <http://www.twilio.com/api/client>`_ can recieve incoming connections, the instance must first register a name (such as "Alice" or "Bob"). The :meth:`allow_client_incoming` method adds the client name to the capability token.
27+
28+
.. code-block:: python
29+
30+
capability.allow_client_incoming("Alice")
31+
32+
33+
Allow Outgoing Connections
34+
==============================
35+
36+
To make an outgoing connection from a `Twilio Client <http://www.twilio.com/api/client>`_ device, you'll need to choose a `Twilio Application <http://www.twilio.com/docs/api/rest/applications>`_ to handle TwiML URLs. A Twilio Application is a collection of URLs responsible for outputing valid TwiML to control phone calls and SMS.
37+
38+
.. code-block:: python
39+
40+
application_sid = "AP123123" # Twilio Application Sid
41+
capability.allow_client_outgoing(application_sid)
42+
43+
Generate a Token
44+
==================
45+
46+
.. code-block:: python
47+
48+
token = capability.generate()
49+
50+
By default, this token will expire in one hour. If you'd like to change the token expiration, :meth:`generate` takes an optional :attr:`expires` argument.
51+
52+
.. code-block:: python
53+
54+
token = capability.generate(expires=600)
55+
56+
This token will now expire in 10 minutes. If you haven't guessed already, :attr:`expires` is expressed in seconds.

0 commit comments

Comments
 (0)
0