Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Queues #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Aug 9, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ twilio-python Changelog

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

Version 3.3.10
-------------

- Add support for Queue. Fix a bug where the library wouldn't work in Python 2.5


Version 3.3.9
-------------

Expand Down
68 changes: 68 additions & 0 deletions docs/api/rest/resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,74 @@ Phone Numbers
.. attribute:: iso_country


Queues
>>>>>>>>>>>

.. autoclass:: twilio.rest.resources.Queues
:members:
:exclude-members: instance

.. autoclass:: twilio.rest.resources.Queue
:members:

.. attribute:: sid

A 34 character string that uniquely identifies this queue.

.. attribute:: friendly_name

A user-provided string that identifies this queue.

.. attribute:: current_size

The count of calls currently in the queue.

.. attribute:: max_size

The upper limit of calls allowed to be in the queue.
`unlimited` is an option. The default is 100.

.. attribute:: average_wait_time

The average wait time of the members of this queue in seconds.
This is calculated at the time of the request.

.. attribute:: uri

The URI for this resource, relative to https://api.twilio.com.


Queue Members
>>>>>>>>>>>>>>

.. autoclass:: twilio.rest.resources.Members
:members:
:exclude-members: instance

.. autoclass:: twilio.rest.resources.Member
:members:

.. attribute:: call_sid

A 34 character string that uniquely identifies the call that is enqueued.

.. attribute:: date_enqueued

The date that the member was enqueued, given in RFC 2822 format.

.. attribute:: wait_time

The number of seconds the member has been in the queue.

.. attribute:: position

This member’s current position in the queue.

.. attribute:: uri

The URI for this resource, relative to https://api.twilio.com.


Recordings
>>>>>>>>>>>

Expand Down
9 changes: 9 additions & 0 deletions docs/api/twiml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ Secondary Verbs
.. autoclass:: twilio.twiml.Sms
:members:

.. autoclass:: twilio.twiml.Enqueue
:members:

.. autoclass:: twilio.twiml.Leave
:members:

Nouns
~~~~~~

Expand All @@ -54,3 +60,6 @@ Nouns

.. autoclass:: twilio.twiml.Client
:members:

.. autoclass:: twilio.twiml.Queue
:members:
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
# The short X.Y version.
version = '3.3'
# The full version, including alpha/beta/rc tags.
release = '3.3.9'
release = '3.3.10'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
3 changes: 1 addition & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Query the Twilio REST API to create phone calls, send SMS messages and so much m
usage/recordings
usage/transcriptions
usage/caller-ids

usage/queues
TwiML
---------

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

See the :doc:`/changelog` for version history.

3 changes: 1 addition & 2 deletions docs/usage/conferences.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Conferences and Participants
==============================

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.
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.

Listing Conferences
-----------------------
Expand Down Expand Up @@ -93,4 +93,3 @@ code kicks out the first participant and mutes the rest.
# And mute the rest
for participant in participants:
participant.mute()

99 changes: 99 additions & 0 deletions docs/usage/queues.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
.. module:: twilio.rest.resources

==============================
Queues and Members
==============================

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.

Listing Queues
-----------------------

.. code-block:: python

from twilio.rest import TwilioRestClient

# To find these visit https://www.twilio.com/user/account
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"

client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
conferences = client.queues.list()

for queue in queues:
print queue.sid

Listing Queue Members
----------------------

Each :class:`Queue` has a :attr:`queue_members` instance which
represents all current calls in the queue.

.. code-block:: python

from twilio.rest import TwilioRestClient

# To find these visit https://www.twilio.com/user/account
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"

client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
queue = client.queues.get("QU123")

for member in queue.queue_members.list():
print member.call_sid

Getting a specific Queue Member
-------------------------------

To retrieve information about a specific member in the queue, each
:class:`Members` has a :attr:`get` method. :attr:`get` accepts one
argument. The argument can either be a `call_sid` thats in the queue,
in which case :attr:`get` will return a :class:`Member` instance
representing that call, or the argument can be 'Front', in which case
:attr:`Get` will return a :class:`Member` instance representing the
first call in the queue.

.. code-block:: python

from twilio.rest import TwilioRestClient

# To find these visit https://www.twilio.com/user/account
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
QUEUE_SID = "QUaaaaaaaaaaaaa"
CALL_SID = "CAxxxxxxxxxxxxxx"
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
members = client.queues.get(QUEUE_SID).queue_members

# Get the first call in the queue
print members.get('Front').date_enqueued

# Get the call with the given call sid in the queue
print members.get(CALL_SID).current_position


Dequeueing Queue Members
------------------------

To dequeue a specific member from the queue, each
:class:`Members` has a :attr:`dequeue` method. :attr:`dequeue` accepts an
argument and two optional keyword arguments. The first argument is the
url of the twiml document to be executed when the member is
dequeued. The other two are :attr:`call_sid` and :attr:`method`, their
default values are 'Front' and 'GET'

.. code-block:: python

from twilio.rest import TwilioRestClient

# To find these visit https://www.twilio.com/user/account
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
QUEUE_SID = "QUaaaaaaaaaaaaa"

client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
members = client.queues.get(QUEUE_SID).queue_members

# Dequeue the first call in the queue
print members.dequeue('http://www.twilio.com/welcome/call')
1 change: 1 addition & 0 deletions tests/resources/members_instance.json
Original file line number Diff line number Diff line change
@@ -0,0 +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"}
1 change: 1 addition & 0 deletions tests/resources/members_list.json
Original file line number Diff line number Diff line change
@@ -0,0 +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}
1 change: 1 addition & 0 deletions tests/resources/queues_instance.json
Original file line number Diff line number Diff line change
@@ -0,0 +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"}
1 change: 1 addition & 0 deletions tests/resources/queues_list.json
Original file line number Diff line number Diff line change
@@ -0,0 +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}
7 changes: 4 additions & 3 deletions tests/test_base_resource.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""
Test the base Resource class
"""
# -*- coding: utf-8 -*-
from __future__ import with_statement
import sys

if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest

from mock import Mock, patch
from nose.tools import assert_equals
from nose.tools import raises
Expand Down
11 changes: 0 additions & 11 deletions tests/test_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@

list_resource = Calls(BASE_URI, AUTH)

@patch("twilio.rest.resources.make_twilio_request")
def test_paging(mock):
resp = create_mock_json("tests/resources/calls_list.json")
mock.return_value = resp

uri = "%s/Calls" % (BASE_URI)
list_resource.list(started=date(2010,12,5))
exp_params = {'StartTime': '2010-12-05'}

mock.assert_called_with("GET", uri, params=exp_params, auth=AUTH)

@patch("twilio.rest.resources.make_twilio_request")
def test_create_call(mock):
resp = create_mock_json("tests/resources/calls_instance.json")
Expand Down
46 changes: 46 additions & 0 deletions tests/test_members.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from mock import patch, Mock
from datetime import date
from mock import patch, Mock
from nose.tools import raises, assert_equals, assert_true
from tools import create_mock_json
from twilio.rest.resources import Member, Members

QUEUE_SID = "QU1b9faddec3d54ec18488f86c83019bf0"
ACCOUNT_SID = "AC123"
AUTH = (ACCOUNT_SID, "token")
CALL_SID = "CAaaf2e9ded94aba3e57c42a3d55be6ff2"
BASE_URI = "https://api.twilio.com/2010-04-01/Accounts/AC123/Queues/%s" % (
QUEUE_SID)
TWIML_URL = "example_twiml_url"

list_resource = Members(BASE_URI, AUTH)

@patch("twilio.rest.resources.make_twilio_request")
def test_members_list(mock):
resp = create_mock_json("tests/resources/members_list.json")
mock.return_value = resp

uri = "%s/Members" % (BASE_URI)
list_resource.list()

mock.assert_called_with("GET", uri, params={}, auth=AUTH)

@patch("twilio.rest.resources.make_twilio_request")
def test_members_dequeue_front(mock):
resp = create_mock_json("tests/resources/members_instance.json")
mock.return_value = resp

uri = "%s/Members/Front" % (BASE_URI)
list_resource.dequeue(TWIML_URL)

mock.assert_called_with("POST", uri, data={"Url": TWIML_URL}, auth=AUTH)

@patch("twilio.rest.resources.make_twilio_request")
def test_members_dequeue_call(mock):
resp = create_mock_json("tests/resources/members_instance.json")
mock.return_value = resp

uri = "%s/Members/%s" % (BASE_URI, CALL_SID)
list_resource.dequeue(TWIML_URL, call_sid=CALL_SID)

mock.assert_called_with("POST", uri, data={"Url": TWIML_URL}, auth=AUTH)
Loading