8000 add tokens resource · Twilio-api/twilio-python@c412238 · GitHub
[go: up one dir, main page]

Skip to content

Commit c412238

Browse files
author
Doug Black
committed
add tokens resource
1 parent c13f243 commit c412238

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

tests/test_tokens.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import unittest
2+
3+
from mock import patch
4+
5+
from twilio.rest.resources import Tokens
6+
7+
8+
DEFAULT = {
9+
'Ttl': None,
10+
}
11+
12+
13+
class TokensTest(unittest.TestCase):
14+
15+
def setUp(self):
16+
self.resource = Tokens('foo', ('sid', 'token'))
17+
self.params = DEFAULT.copy()
18+
19+
def test_create(self):
20+
with patch.object(self.resource, 'create_instance') as mock:
21+
self.resource.create(
22+
ttl=111,
23+
)
24+
mock.assert_called_with(
25+
{
26+
'ttl': 111,
27+
}
28+
)

twilio/rest/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
Usage,
3030
CallFeedbackFactory,
3131
CallFeedback,
32+
Tokens,
3233
)
3334

3435

@@ -115,6 +116,7 @@ def __init__(self, account=None, token=None, base="https://api.twilio.com",
115116
self.messages = Messages(account_uri, auth, timeout)
116117
self.media = MediaList(account_uri, auth, timeout)
117118
self.sip = Sip(account_uri, auth, timeout)
119+
self.tokens = Tokens(account_uri, auth, timeout)
118120

119121
self.auth = auth
120122
self.account_uri = account_uri

twilio/rest/resources/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,5 @@
5151
from .media import Media, MediaList
5252

5353
from .sip import Sip
54+
55+
from .tokens import Token, Tokens

twilio/rest/resources/tokens.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from . import InstanceResource, ListResource
2+
3+
4+
class Token(InstanceResource):
5+
""" A Token instance.
6+
7+
.. attribute:: username
8+
9+
The temporary username that uniquely identifies a Token.
10+
11+
.. attribute:: password
12+
13+
The temporary password that the username will use when authenticating with Twilio.
14+
15+
.. attribute:: ttl
16+
17+
The duration in seconds for which the username and password are valid, the default value is 86,400 (24 hours).
18+
19+
.. attribute:: account_sid
20+
21+
The unique id of the Account that created this Token.
22+
23+
.. attribute:: ice_servers
24+
25+
An array representing the ephemeral credentials and the STUN and TURN server URIs.
26+
27+
.. attribute:: date_created
28+
29+
The date that this resource was created, given in RFC 2822 format.
30+
31+
.. attribute:: date_updated
32+
33+
The date that this resource was last updated, given in RFC 2822 format.
34+
"""
35+
pass
36+
37+
38+
class Tokens(ListResource):
39+
40+
def create(self, ttl=None, **kwargs):
41+
"""
42+
Create a new Token.
43+
44+
:param int ttl: The duration in seconds for which the token
45+
is valid, the default value is 86,400 (24 hours).
46+
"""
47+
kwargs['ttl'] = ttl
48+
return self.create_instance(kwargs)

0 commit comments

Comments
 (0)
0