8000 Merge pull request #77 from twilio/queues · charlax/twilio-python@2e9420a · GitHub
[go: up one dir, main page]

Skip to content

Commit 2e9420a

Browse files
committed
Merge pull request twilio#77 from twilio/queues
Queues
2 parents ada3b2a + 8d793dd commit 2e9420a

20 files changed

+559
-30
lines changed

CHANGES

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ twilio-python Changelog
33

44
Here you can see the full list of changes between each twilio-python release.
55

6+
Version 3.3.10
7+
-------------
8+
9+
- Add support for Queue. Fix a bug where the library wouldn't work in Python 2.5
10+
11+
612
Version 3.3.9
713
-------------
814

docs/api/rest/resources.rst

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,74 @@ Phone Numbers
603603
.. attribute:: iso_country
604604

605605

606+
Queues
607+
>>>>>>>>>>>
608+
609+
.. autoclass:: twilio.rest.resources.Queues
610+
:members:
611+
:exclude-members: instance
612+
613+
.. autoclass:: twilio.rest.resources.Queue
614+
:members:
615+
616+
.. attribute:: sid
617+
618+
A 34 character string that uniquely identifies this queue.
619+
620+
.. attribute:: friendly_name
621+
622+
A user-provided string that identifies this queue.
623+
624+
.. attribute:: current_size
625+
626+
The count of calls currently in the queue.
627+
628+
.. attribute:: max_size
629+
630+
The upper limit of calls allowed to be in the queue.
631+
`unlimited` is an option. The default is 100.
632+
633+
.. attribute:: average_wait_time
634+
635+
The average wait time of the members of this queue in seconds.
636+
This is calculated at the time of the request.
637+
638+
.. attribute:: uri
639+
640+
The URI for this resource, relative to https://api.twilio.com.
641+
642+
643+
Queue Members
644+
>>>>>>>>>>>>>>
645+
646+
.. autoclass:: twilio.rest.resources.Members
647+
:members:
648+
:exclude-members: instance
649+
650+
.. autoclass:: twilio.rest.resources.Member
651+
:members:
652+
653+
.. attribute:: call_sid
654+
655+
A 34 character string that uniquely identifies the call that is enqueued.
656+
657+
.. attribute:: date_enqueued
658+
659+
The date that the member was enqueued, given in RFC 2822 format.
660+
661+
.. attribute:: wait_time
662+
663+
The number of seconds the member has been in the queue.
664+
665+
.. attribute:: position
666+
667+
This member’s current position in the queue.
668+
669+
.. attribute:: uri
670+
671+
The URI for this resource, relative to https://api.twilio.com.
672+
673+
606674
Recordings
607675
>>>>>>>>>>>
608676

docs/api/twiml.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ Secondary Verbs
4343
.. autoclass:: twilio.twiml.Sms
4444
:members:
4545

46+
.. autoclass:: twilio.twiml.Enqueue
47+
:members:
48+
49+
.. autoclass:: twilio.twiml.Leave
50+
:members:
51+
4652
Nouns
4753
~~~~~~
4854

@@ -54,3 +60,6 @@ Nouns
5460

5561
.. autoclass:: twilio.twiml.Client
5662
:members:
63+
64+
.. autoclass:: twilio.twiml.Queue
65+
:members:

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
# The short X.Y version.
5858
version = '3.3'
5959
# The full version, including alpha/beta/rc tags.
60-
release = '3.3.9'
60+
release = '3.3.10'
6161

6262
# The language for content autogenerated by Sphinx. Refer to documentation
6363
# for a list of supported languages.

docs/index.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Query the Twilio REST API to create phone calls, send SMS messages and so much m
6060
usage/recordings
6161
usage/transcriptions
6262
usage/caller-ids
63-
63+
usage/queues
6464
TwiML
6565
---------
6666

@@ -125,4 +125,3 @@ Report bugs using the Github `issue tracker <https://github.com/twilio/twilio-py
125125
If you have questions that aren't answered by this documentation, ask the `#twilio IRC channel <irc://irc.freenode.net/#twilio>`_
126126

127127
See the :doc:`/changelog` for version history.
128-

docs/usage/conferences.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Conferences and Participants
55
==============================
66

7-
For more information, see the `Conference REST Resource <http://www.twilio.com/docs/api/rest/conference>`_ and `Participant REST Resource <http://www.twilio.com/docs/api/rest/conference>`_ documentation.
7+
For more information, see the `Conference REST Resource <http://www.twilio.com/docs/api/rest/conference>`_ and `Participant REST Resource <http://www.twilio.com/docs/api/rest/participant>`_ documentation.
8< F42D /td>8

99
Listing Conferences
1010
-----------------------
@@ -93,4 +93,3 @@ code kicks out the first participant and mutes the rest.
9393
# And mute the rest
9494
for participant in participants:
9595
participant.mute()
96-

docs/usage/queues.rst

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
.. module:: twilio.rest.resources
2+
3+
==============================
4+
Queues and Members
5+
==============================
6+
7+
For more information, see the `Queue REST Resource <http://www.twilio.com/docs/api/rest/queue>`_ and `Member REST Resource <http://www.twilio.com/docs/api/rest/member>`_ documentation.
8+
9+
Listing Queues
10+
-----------------------
11+
12+
.. code-block:: python
13+
14+
from twilio.rest import TwilioRestClient
15+
16+
# To find these visit https://www.twilio.com/user/account
17+
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
18+
AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
19+
20+
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
21+
conferences = client.queues.list()
22+
23+
for queue in queues:
24+
print queue.sid
25+
26+
Listing Queue Members
27+
----------------------
28+
29+
Each :class:`Queue` has a :attr:`queue_members` instance which
30+
represents all current calls in the queue.
31+
32+
.. code-block:: python
33+
34+
from twilio.rest import TwilioRestClient
35+
36+
# To find these visit https://www.twilio.com/user/account
37+
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
38+
AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
39+
40+
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
41+
queue = client.queues.get("QU123")
42+
43+
for member in queue.queue_members.list():
44+
print member.call_sid
45+
46+
Getting a specific Queue Member
47+
-------------------------------
48+
49+
To retrieve information about a specific member in the queue, each
50+
:class:`Members` has a :attr:`get` method. :attr:`get` accepts one
51+
argument. The argument can either be a `call_sid` thats in the queue,
52+
in which case :attr:`get` will return a :class:`Member` instance
53+
representing that call, or the argument can be 'Front', in which case
54+
:attr:`Get` will return a :class:`Member` instance representing the
55+
first call in the queue.
56+
57+
.. code-block:: python
58+
59+
from twilio.rest import TwilioRestClient
60+
61+
# To find these visit https://www.twilio.com/user/account
62+
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
63+
AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
64+
QUEUE_SID = "QUaaaaaaaaaaaaa"
65+
CALL_SID = "CAxxxxxxxxxxxxxx"
66+
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
67+
members = client.queues.get(QUEUE_SID).queue_members
68+
69+
# Get the first call in the queue
70+
print members.get('Front').date_enqueued
71+
72+
# Get the call with the given call sid in the queue
73+
print members.get(CALL_SID).current_position
74+
75+
76+
Dequeueing Queue Members
77+
------------------------
78+
79+
To dequeue a specific member from the queue, each
80+
:class:`Members` has a :attr:`dequeue` method. :attr:`dequeue` accepts an
81+
argument and two optional keyword arguments. The first argument is the
82+
url of the twiml document to be executed when the member is
83+
dequeued. The other two are :attr:`call_sid` and :attr:`method`, their
84+
default values are 'Front' and 'GET'
85+
86+
.. code-block:: python
87+
88+
from twilio.rest import TwilioRestClient
89+
90+
# To find these visit https://www.twilio.com/user/account
91+
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
92+
AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
93+
QUEUE_SID = "QUaaaaaaaaaaaaa"
94+
95+
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
96+
members = client.queues.get(QUEUE_SID).queue_members
97+
98+
# Dequeue the first call in the queue
99+
print members.dequeue('http://www.twilio.com/welcome/call')

tests/resources/members_instance.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"call_sid": "CAaaf2e9ded94aba3e57c42a3d55be6ff2", "date_enqueued": "Tue, 07 Aug 2012 22:57:41 +0000", "wait_time": 143, "current_position": 1, "uri": "/2010-04-01/Accounts/ACf5af0ea0c9955b67b39c52fb11ee6e69/Queues/QUe675e1913214346f48a9d2296a8d3788/Members/CAaaf2e9ded94aba3e57c42a3d55be6ff2.json"}

tests/resources/members_list.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"first_page_uri": "/2010-04-01/Accounts/ACf5af0ea0c9955b67b39c52fb11ee6e69/Queues/QUe675e1913214346f48a9d2296a8d3788/Members.json?Page=0&PageSize=50", "num_pages": 1, "previous_page_uri": null, "last_page_uri": "/2010-04-01/Accounts/ACf5af0ea0c9955b67b39c52fb11ee6e69/Queues/QUe675e1913214346f48a9d2296a8d3788/Members.json?Page=0&PageSize=50", "uri": "/2010-04-01/Accounts/ACf5af0ea0c9955b67b39c52fb11ee6e69/Queues/QUe675e1913214346f48a9d2296a8d3788/Members.json", "page_size": 50, "start": 0, "next_page_uri": null, "end": 0, "total": 1, "queue_members": [{"call_sid": "CAaaf2e9ded94aba3e57c42a3d55be6ff2", "date_enqueued": "Tue, 07 Aug 2012 22:57:41 +0000", "wait_time": 124, "current_position": 1, "uri": "/2010-04-01/Accounts/ACf5af0ea0c9955b67b39c52fb11ee6e69/Queues/QUe675e1913214346f48a9d2296a8d3788/Members/CAaaf2e9ded94aba3e57c42a3d55be6ff2.json"}], "page": 0}

tests/resources/queues_instance.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"sid": "QU6e2cd5a7c8074edc8b383a3b198b2f8b", "friendly_name": "CutieQueue", "current_size": null, "average_wait_time": null, "max_size": 100, "date_created": "Tue, 07 Aug 2012 21:08:51 +0000", "date_updated": "Tue, 07 Aug 2012 21:08:51 +0000", "uri": "/2010-04-01/Accounts/ACf5af0ea0c9955b67b39c52fb11ee6e69/Queues/QU6e2cd5a7c8074edc8b383a3b198b2f8b.json"}

tests/resources/queues_list.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"first_page_uri": "/2010-04-01/Accounts/ACf5af0ea0c9955b67b39c52fb11ee6e69/Queues.json?Page=0&PageSize=50", "num_pages": 1, "previous_page_uri": null, "queues": [{"sid": "QU1b9faddec3d54ec18488f86c83019bf0", "friendly_name": "Support", "current_size": 0, "average_wait_time": 0, "max_size": 100, "date_created": "Tue, 07 Aug 2012 21:09:04 +0000", "date_updated": "Tue, 07 Aug 2012 21:09:04 +0000", "uri": "/2010-04-01/Accounts/ACf5af0ea0c9955b67b39c52fb11ee6e69/Queues/QU1b9faddec3d54ec18488f86c83019bf0.json"}, {"sid": "QU6e2cd5a7c8074edc8b383a3b198b2f8b", "friendly_name": "CutieQueue", "current_size": 0, "average_wait_time": 0, "max_size": 100, "date_created": "Tue, 07 Aug 2012 21:08:51 +0000", "date_updated": "Tue, 07 Aug 2012 21:08:51 +0000", "uri": "/2010-04-01/Accounts/ACf5af0ea0c9955b67b39c52fb11ee6e69/Queues/QU6e2cd5a7c8074edc8b383a3b198b2f8b.json"}, {"sid": "QUa8ce40f68d3f41958e2519646d55b989", "friendly_name": "Test1", "current_size": 0, "average_wait_time": 0, "max_size": 64, "date_created": "Tue, 07 Aug 2012 19:09:17 +0000", "date_updated": "Tue, 07 Aug 2012 19:09:17 +0000", "uri": "/2010-04-01/Accounts/ACf5af0ea0c9955b67b39c52fb11ee6e69/Queues/QUa8ce40f68d3f41958e2519646d55b989.json"}], "uri": "/2010-04-01/Accounts/ACf5af0ea0c9955b67b39c52fb11ee6e69/Queues.json", "page_size": 50, "start": 0, "next_page_uri": null, "end": 2, "total": 3, "last_page_uri": "/2010-04-01/Accounts/ACf5af0ea0c9955b67b39c52fb11ee6e69/Queues.json?Page=0&PageSize=50", "page": 0}

tests/test_base_resource.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
"""
2-
Test the base Resource class
3-
"""
1+
# -*- coding: utf-8 -*-
2+
from __future__ import with_statement
43
import sys
4+
55
if sys.version_info < (2, 7):
66
import unittest2 as unittest
77
else:
88
import unittest
9+
910
from mock import Mock, patch
1011
from nose.tools import assert_equals
1112
from nose.tools import raises

tests/test_calls.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,6 @@
1111

1212
list_resource = Calls(BASE_URI, AUTH)
1313

14-
@patch("twilio.rest.resources.make_twilio_request")
15-
def test_paging(mock):
16-
resp = create_mock_json("tests/resources/calls_list.json")
17-
mock.return_value = resp
18-
19-
uri = "%s/Calls" % (BASE_URI)
20-
list_resource.list(started=date(2010,12,5))
21-
exp_params = {'StartTime': '2010-12-05'}
22-
23-
mock.assert_called_with("GET", uri, params=exp_params, auth=AUTH)
24-
2514
@patch("twilio.rest.resources.make_twilio_request")
2615
def test_create_call(mock):
2716
resp = create_mock_json("tests/resources/calls_instance.json")

tests/test_members.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from mock import patch, Mock
2+
from datetime import date
3+
from mock import patch, Mock
4+
from nose.tools import raises, assert_equals, assert_true
5+
from tools import create_mock_json
6+
from twilio.rest.resources import Member, Members
7+
8+
QUEUE_SID = "QU1b9faddec3d54ec18488f86c83019bf0"
9+
ACCOUNT_SID = "AC123"
10+
AUTH = (ACCOUNT_SID, "token")
11+
CALL_SID = "CAaaf2e9ded94aba3e57c42a3d55be6ff2"
12+
BASE_URI = "https://api.twilio.com/2010-04-01/Accounts/AC123/Queues/%s" % (
13+
QUEUE_SID)
14+
TWIML_URL = "example_twiml_url"
15+
16+
list_resource = Members(BASE_URI, AUTH)
17+
18+
@patch("twilio.rest.resources.make_twilio_request")
19+
def test_members_list(mock):
20+
resp = create_mock_json("tests/resources/members_list.json")
21+
mock.return_value = resp
22+
23+
uri = "%s/Members" % (BASE_URI)
24+
list_resource.list()
25+
26+
mock.assert_called_with("GET", uri, params={}, auth=AUTH)
27+
28+
@patch("twilio.rest.resources.make_twilio_request")
29+
def test_members_dequeue_front(mock):
30+
resp = create_mock_json("tests/resources/members_instance.json")
31+
mock.return_value = resp
32+
33+
uri = "%s/Members/Front" % (BASE_URI)
34+
list_resource.dequeue(TWIML_URL)
35+
36+
mock.assert_called_with("POST", uri, data={"Url": TWIML_URL}, auth=AUTH)
37+
38+
@patch("twilio.rest.resources.make_twilio_request")
39+
def test_members_dequeue_call(mock):
40+
resp = create_mock_json("tests/resources/members_instance.json")
41+
mock.return_value = resp
42+
43+
uri = "%s/Members/%s" % (BASE_URI, CALL_SID)
44+
list_resource.dequeue(TWIML_URL, call_sid=CALL_SID)
45+
46+
mock.assert_called_with("POST", uri, data={"Url": TWIML_URL}, auth=AUTH)

0 commit comments

Comments
 (0)
0