Skip to content
This repository has been archived by the owner on Nov 19, 2019. It is now read-only.

Commit

Permalink
Merge pull request #29 from raghusagar/queue-members
Browse files Browse the repository at this point in the history
Add Queues and Members support and tests.
  • Loading branch information
brettgerry committed Nov 13, 2013
2 parents e4ec3db + 4309f8e commit f3c4828
Show file tree
Hide file tree
Showing 23 changed files with 873 additions and 144 deletions.
115 changes: 115 additions & 0 deletions docs/usage/queues.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
.. 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:: javascript
String ACCOUNT_SID = 'XXXXXXXXXXXXXXX';
String AUTH_TOKEN = 'XXXXXXXXXXXXXXX';
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
List<TwilioNameValuePair> params = new List<TwilioNameValuePair>();
params.add(new TwilioNameValuePair('FriendlyName','TestQueue'));
TwilioQueue queue = client.getAccount().getQueues().create(params);
List All Available Queues
----------------------


.. code-block:: javascript
String ACCOUNT_SID = 'XXXXXXXXXXXXXXX';
String AUTH_TOKEN = 'XXXXXXXXXXXXXXX';
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
TwilioQueueList queues = client.getAccount().getQueues();
for(TwilioQueue queue :queues.getPageData())
{
system.debug(queue);
}
Retrieving Queue information using QueueId
----------------------


.. code-block:: javascript
String ACCOUNT_SID = 'XXXXXXXXXXXXXXX';
String AUTH_TOKEN = 'XXXXXXXXXXXXXXX';
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
TwilioQueue queue = client.getAccount().getQueue('YYYYYYYYYYYYYYYYY');
system.debug(queue);
Updating Queue Properties
----------------------


.. code-block:: javascript
String ACCOUNT_SID = 'XXXXXXXXXXXXXXX';
String AUTH_TOKEN = 'XXXXXXXXXXXXXXX';
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
TwilioQueue queue = client.getAccount().getQueue('YYYYYYYYYYYYYYYYY');
List<TwilioNameValuePair> params = new List<TwilioNameValuePair>();
params.add(new TwilioNameValuePair('MaxSize','120'));
queue.updateResource(params);
List of Members in a queue
----------------------


.. code-block:: javascript
String ACCOUNT_SID = 'XXXXXXXXXXXXXXX';
String AUTH_TOKEN = 'XXXXXXXXXXXXXXX';
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
TwilioMemberList members = client.getAccount().getQueue('QUcdbadab1b3de41f39f2257395e9b80a9').getMembers();
system.debug('Members :'+members);
Getting a specific Queue Member
----------------------


.. code-block:: javascript
String ACCOUNT_SID = 'XXXXXXXXXXXXXXX';
String AUTH_TOKEN = 'XXXXXXXXXXXXXXX';
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
TwilioMember member = client.getAccount().getQueue('QUcdbadab1b3de41f39f2257395e9b80a9').getMember('ZZZZZZZZZZZZZZZZZ');
Updating Member information
----------------------


.. code-block:: javascript
String ACCOUNT_SID = 'XXXXXXXXXXXXXXX';
String AUTH_TOKEN = 'XXXXXXXXXXXXXXX';
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
//need to have callSid
TwilioMember member = client.getAccount().getQueue('QUcdbadab1b3de41f39f2257395e9b80a9').getMember('Front');
List<TwilioNameValuePair> params = new List<TwilioNameValuePair>();
params.add(new TwilioNameValuePair('URL','http://demo.twilio.com/docs/voice.xml'));
params.add(new TwilioNameValuePair('Method','POST'));
member.updateResource(params);
1 change: 0 additions & 1 deletion install/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ sf.serverurl = https://login.salesforce.com

# If your network requires an HTTP proxy, you'll configuration instructions
# at http://ant.apache.org/manual/proxy.html

20 changes: 20 additions & 0 deletions src/classes/TwilioAccount.cls
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,26 @@ global class TwilioAccount extends TwilioResource.InstanceResource {
return message;
}

public TwilioQueueList getQueues()
{
TwilioQueueList Queuelist = new TwilioQueueList(this.getClient(), filters);
Queuelist.setRequestAccountSid(this.getRequestAccountSid());
return Queuelist;
}

/**
* Get a given queue by sid
*
* @param sid The Sid starting with QU
* @return the TwilioQueue object
*/
public TwilioQueue getQueue(String sid)
{
TwilioQueue queue = new TwilioQueue(this.getClient(), sid);
queue.setRequestAccountSid(this.getRequestAccountSid());
return queue;
}

/**
* Suspend a subaccount.
*
Expand Down
107 changes: 55 additions & 52 deletions src/classes/TwilioAccountList.cls
Original file line number Diff line number Diff line change
Expand Up @@ -23,59 +23,62 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
global class TwilioAccountList extends TwilioResource.ListResource
implements Iterable<TwilioAccount> {
/**
* Instantiates a new account list.
*
* @param client the client
*/
public TwilioAccountList(TwilioRestClient client) {
super(client);
}
/**
* Instantiates a new call list.
*
* @param client the client
* @param filters the filters
*/
public TwilioAccountList(TwilioRestClient client, Map<String, String> filters) {
super(client, filters);
}
implements Iterable<TwilioAccount> {
/**
* Instantiates a new account list.
*
* @param client the client
*/
public TwilioAccountList(TwilioRestClient client) {
super(client);
}
/**
* Instantiates a new call list.
*
* @param client the client
* @param filters the filters
*/
public TwilioAccountList(TwilioRestClient client, Map<String, String> filters) {
super(client, filters);
}

/* implements method from TwilioResource */
public override String getResourceLocation() {
return '/' + TwilioRestClient.DEFAULT_VERSION + '/Accounts.json';
}
/* implements method from TwilioResource */
public override String getResourceLocation() {
return '/' + TwilioRestClient.DEFAULT_VERSION + '/Accounts.json';
}

/* implements method from TwilioResource.ListResource */
public override Object makeNew(TwilioRestClient client,
Map<String, Object> params) {
return new TwilioAccount(client, params);
}
/* implements method from TwilioResource.ListResource */
public override Object makeNew(TwilioRestClient client,
Map<String, Object> params) {
return new TwilioAccount(client, params);
}

/* implements method from TwilioResource.ListResource */
public override String getListKey() {
return 'accounts';
}

public TwilioAccount create(Map<String, String> params) {
return (TwilioAccount)this.createInstance(params);
}

public List<TwilioAccount> getPageData() {
List<TwilioAccount> returnList = new List<TwilioAccount>();

for (Object o : this.getObjectPageData()) {
if (o instanceof TwilioAccount) {
returnList.add((TwilioAccount) o);
}
}
return returnList;
}

global Iterator<TwilioAccount> iterator() {
return new TwilioIterator.AccountIterator(this);
}
/* implements method from TwilioResource.ListResource */
public override String getListKey() {
return 'accounts';
}

public TwilioAccount create(Map<String, String> params) {
return (TwilioAccount)this.createInstance(params);
}
public TwilioAccount create(List<TwilioNameValuePair> params) {
return (TwilioAccount)this.createInstance(params);
}

public List<TwilioAccount> getPageData() {
List<TwilioAccount> returnList = new List<TwilioAccount>();

for (Object o : this.getObjectPageData()) {
if (o instanceof TwilioAccount) {
returnList.add((TwilioAccount) o);
}
}
return returnList;
}

global Iterator<TwilioAccount> iterator() {
return new TwilioIterator.AccountIterator(this);
}
}
3 changes: 2 additions & 1 deletion src/classes/TwilioCapability.cls
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ global class TwilioCapability {
return jwtEncode(payload, this.authToken);
}


/* PRIVATE METHODS */

/**
Expand Down Expand Up @@ -325,4 +326,4 @@ global class TwilioCapability {
}

private class TestOnlyException extends Exception {}
}
}
20 changes: 20 additions & 0 deletions src/classes/TwilioIterator.cls
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,26 @@ global class TwilioIterator {
}
}

global class MemberIterator extends ObjectIteratorSupport implements Iterator<TwilioMember> {
global MemberIterator(TwilioMemberList twlist) {
super(twlist);
}

global TwilioMember next() {
return (TwilioMember)getNext();
}
}

global class QueueIterator extends ObjectIteratorSupport implements Iterator<TwilioQueue> {
global QueueIterator(TwilioQueueList twlist) {
super(twlist);
}

global TwilioQueue next() {
return (TwilioQueue)getNext();
}
}

global class TranscriptionIterator extends ObjectIteratorSupport implements Iterator<TwilioTranscription> {
global TranscriptionIterator(TwilioTranscriptionList twlist) {
super(twlist);
Expand Down
11 changes: 0 additions & 11 deletions src/classes/TwilioMedia.cls
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,6 @@ global class TwilioMedia extends TwilioResource.InstanceResource
return this.getProperty('content_type');
}

/**
* Gets the duration
*
* @return the duration
*/
public Integer getDuration()
{
Integer duration = (Integer) this.getObject('duration');
return duration;
}

/**
* Gets the api version.
*
Expand Down
11 changes: 11 additions & 0 deletions src/classes/TwilioMediaList.cls
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,19 @@ global class TwilioMediaList extends TwilioResource.ListResource implements Iter
return this.requestMessageSid;
}

public List<TwilioMedia> getPageData() {
List<TwilioMedia> returnList = new List<TwilioMedia>();

for (Object o : this.getObjectPageData()) {
if (o instanceof TwilioMedia) {
returnList.add((TwilioMedia) o);
}
}
return returnList;
}
global Iterator<TwilioMedia> iterator()
{
return new TwilioIterator.MediaIterator(this);
}

}
Loading

0 comments on commit f3c4828

Please sign in to comment.