diff --git a/tests/test_twiml.py b/tests/test_twiml.py index c413d91315..f132cfb5fd 100644 --- a/tests/test_twiml.py +++ b/tests/test_twiml.py @@ -411,6 +411,32 @@ def testDial(self): r = self.strip(r) self.assertEquals(r, '1231231234') + def testSip(self): + """ should redirect the call""" + r = Response() + d = r.dial() + d.sip('foo@example.com') + r = self.strip(r) + self.assertEquals(r, 'foo@example.com') + + def testSipUsernamePass(self): + """ should redirect the call""" + r = Response() + d = r.dial() + d.sip('foo@example.com', username='foo', password='bar') + r = self.strip(r) + self.assertEquals(r, 'foo@example.com') + + + def testSipUri(self): + """ should redirect the call""" + r = Response() + d = r.dial() + s = d.sip() + s.uri('foo@example.com') + r = self.strip(r) + self.assertEquals(r, 'foo@example.com') + def testConvienceMethod(self): """ should dial to a url via post""" r = Response() diff --git a/twilio/twiml.py b/twilio/twiml.py index 2cf9248f5d..1c8396991c 100644 --- a/twilio/twiml.py +++ b/twilio/twiml.py @@ -3,8 +3,7 @@ """ import xml.etree.ElementTree as ET -from six import u - +from six import iteritems class TwimlException(Exception): pass @@ -390,7 +389,7 @@ class Dial(Verb): """ GET = 'GET' POST = 'POST' - nestables = ['Number', 'Conference', 'Client', 'Queue'] + nestables = ['Number', 'Conference', 'Client', 'Queue', 'Sip'] def __init__(self, number=None, **kwargs): super(Dial, self).__init__(**kwargs) @@ -412,6 +411,9 @@ def conference(self, name, **kwargs): def queue(self, name, **kwargs): return self.append(Queue(name, **kwargs)) + def sip(self, sip_address=None, **kwargs): + return self.append(Sip(sip_address, **kwargs)) + def addNumber(self, *args, **kwargs): return self.number(*args, **kwargs) @@ -472,3 +474,31 @@ class Record(Verb): """ GET = 'GET' POST = 'POST' + + +class Sip(Verb): + """Dial out to a SIP endpoint + + :param url: call screening URL none + :param method: call screening method POST + :param username: Username for SIP authentication + :param password: Password for SIP authentication + """ + nestables = ['Headers', 'Uri'] + + def __init__(self, sip_address=None, **kwargs): + super(Sip, self).__init__(**kwargs) + if sip_address: + self.body = sip_address + + def uri(self, uri, **kwargs): + return self.append(Uri(uri, **kwargs)) + + +class Uri(Verb): + """A uniform resource indentifier""" + def __init__(self, uri, **kwargs): + super(Uri, self).__init__(**kwargs) + self.body = uri + +