8000 Add sip out TwiML verbs · twilio/twilio-python@2eeda68 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2eeda68

Browse files
committed
Add sip out TwiML verbs
1 parent 9a445a0 commit 2eeda68

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

tests/test_twiml.py

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

414+
def testSip(self):
415+
""" should redirect the call"""
416+
r = Response()
417+
d = r.dial()
418+
d.sip('foo@example.com')
419+
r = self.strip(r)
420+
self.assertEquals(r, '<?xml version="1.0" encoding="UTF-8"?><Response><Dial><Sip>foo@example.com</Sip></Dial></Response>')
421+
422+
def testSipUri(self):
423+
""" should redirect the call"""
424+
r = Response()
425+
d = r.dial()
426+
s = d.sip()
427+
s.uri('foo@example.com')
428+
r = self.strip(r)
429+
self.assertEquals(r, '<?xml version="1.0" encoding="UTF-8"?><Response><Dial><Sip><Uri>foo@example.com</Uri></Sip></Dial></Response>')
430+
431+
def testSipUriHeaders(self):
432+
""" should redirect the call"""
433+
r = Response()
434+
d = r.dial()
435+
s = d.sip()
436+
s.uri('foo@example.com')
437+
8000 s.headers({'foo-bar': 'key'})
438+
r = self.strip(r)
439+
self.assertEquals(r, '<?xml version="1.0" encoding="UTF-8"?><Response><Dial><Sip><Uri>foo@example.com</Uri><Headers><Header name="foo-bar" value="key" /></Headers></Sip></Dial></Response>')
440+
441+
414442
def testConvienceMethod(self):
415443
""" should dial to a url via post"""
416444
r = Response()

twilio/twiml.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ class Dial(Verb):
390390
"""
391391
GET = 'GET'
392392
POST = 'POST'
393-
nestables = ['Number', 'Conference', 'Client', 'Queue']
393+
nestables = ['Number', 'Conference', 'Client', 'Queue', 'Sip']
394394

395395
def __init__(self, number=None, **kwargs):
396396
super(Dial, self).__init__(**kwargs)
@@ -412,6 +412,9 @@ def conference(self, name, **kwargs):
412412
def queue(self, name, **kwargs):
413413
return self.append(Queue(name, **kwargs))
414414

415+
def sip(self, name=None, **kwargs):
416+
return self.append(Sip(name, **kwargs))
417+
415418
def addNumber(self, *args, **kwargs):
416419
return self.number(*args, **kwargs)
417420

@@ -472,3 +475,51 @@ class Record(Verb):
472475
"""
473476
GET = 'GET'
474477
POST = 'POST'
478+
479+
480+
class Sip(Verb):
481+
"""Dial out to a SIP endpoint
482+
483+
:param url: call screening URL none
484+
:param method: call screening method POST
485+
:param username: Username for SIP authentication
486+
:param password: Password for SIP authentication
487+
"""
488+
nestables = ['Headers', 'Uri']
489+
490+
def __init__(self, sip_address=None, **kwargs):
491+
super(Sip, self).__init__(**kwargs)
492+
if sip_address:
493+
self.body = sip_address
494+
495+
def uri(self, uri, **kwargs):
496+
return self.append(Uri(uri, **kwargs))
497+
498+
def headers(self, headers):
499+
"""Add headers to this Sip noun
500+
501+
:param dict headers: A dictionary of headers
502+
"""
503+
collection = Headers()
504+
505+
for key, value in headers.iteritems():
506+
collection.append(Header(name=key, value=value))
507+
508+
return self.append(collection)
509+
510+
511+
class Uri(Verb):
512+
"""A collection of headers"""
513+
def __init__(self, uri, **kwargs):
514+
super(Uri, self).__init__(**kwargs)
515+
self.body = uri
516+
517+
518+
class Headers(Verb):
519+
"""A collection of headers"""
520+
nestables = ['Header']
521+
522+
523+
class Header(Verb):
524+
"""A single headers"""
525+
pass

0 commit comments

Comments
 (0)
0