8000 Merge pull request #110 from twilio/sipout-twiml · charlax/twilio-python@51425e3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 51425e3

Browse files
committed
Merge pull request twilio#110 from twilio/sipout-twiml
Add sip out TwiML verbs
2 parents bb9f4a3 + 241a6b5 commit 51425e3

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

tests/test_twiml.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,32 @@ def testDial(self):
409409
r = self.strip(r)
410410
self.assertEquals(r, '<?xml version="1.0" encoding="UTF-8"?><Response><Dial>1231231234</Dial></Response>')
411411

412+
def testSip(self):
413+
""" should redirect the call"""
414+
r = Response()
415+
d = r.dial()
416+
d.sip('foo@example.com')
417+
r = self.strip(r)
418+
self.assertEquals(r, '<?xml version="1.0" encoding="UTF-8"?><Response><Dial><Sip>foo@example.com</Sip></Dial></Response>')
419+
420+
def testSipUsernamePass(self):
421+
""" should redirect the call"""
422+
r = Response()
423+
d = r.dial()
424+
d.sip('foo@example.com', username='foo', password='bar')
425+
r = self.strip(r)
426+
self.assertEquals(r, '<?xml version="1.0" encoding="UTF-8"?><Response><Dial><Sip password="bar" username="foo">foo@example.com</Sip></Dial></Response>')
427+
428+
429+
def testSipUri(self):
430+
""" should redirect the call"""
431+
r = Response()
432+
d = r.dial()
433+
s = d.sip()
434+
s.uri('foo@example.com')
435+
r = self.strip(r)
436+
self.assertEquals(r, '<?xml version="1.0" encoding="UTF-8"?><Response><Dial><Sip><Uri>foo@example.com</Uri></Sip></Dial></Response>')
437+
412438
def testConvienceMethod(self):
413439
""" should dial to a url via post"""
414440
r = Response()

twilio/twiml.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
"""
44

55
import xml.etree.ElementTree as ET
6-
from six import u
7-
6+
from six import iteritems
87

98
class TwimlException(Exception):
109
pass
@@ -390,7 +389,7 @@ class Dial(Verb):
390389
"""
391390
GET = 'GET'
392391
POST = 'POST'
393-
nestables = ['Number', 'Conference', 'Client', 'Queue']
392+
nestables = ['Number', 'Conference', 'Client', 'Queue', 'Sip']
394393

395394
def __init__(self, number=None, **kwargs):
396395
super(Dial, self).__init__(**kwargs)
@@ -412,6 +411,9 @@ def conference(self, name, **kwargs):
412411
def queue(self, name, **kwargs):
413412
return self.append(Queue(name, **kwargs))
414413

414+
def sip(self, sip_address=None, **kwargs):
415+
return self.append(Sip(sip_address, **kwargs))
416+
415417
def addNumber(self, *args, **kwargs):
416418
return self.number(*args, **kwargs)
417419

@@ -472,3 +474,31 @@ class Record(Verb):
472474
"""
473475
GET = 'GET'
474476
POST = 'POST'
477+
478+
479+
class Sip(Verb):
480+
"""Dial out to a SIP endpoint
481+
482+
:param url: call screening URL none
483+
:param method: call screening method POST
484+
:param username: Username for SIP authentication
485+
:param password: Password for SIP authentication
486+
"""
487+
nestables = ['Headers', 'Uri']
488+
489+
def __init__(self, sip_address=None, **kwargs):
490+
super(Sip, self).__init__(**kwargs)
491+
if sip_address:
492+
self.body = sip_address
493+
494+
def uri(self, uri, **kwargs):
495+
return self.append(Uri(uri, **kwargs))
496+
497+
498+
class Uri(Verb):
499+
"""A uniform resource indentifier"""
500+
def __init__(self, uri, **kwargs):
501+
super(Uri, self).__init__(**kwargs)
502+
self.body = uri
503+
504+

0 commit comments

Comments
 (0)
0