10000 Add sip out TwiML verbs by kyleconroy · Pull Request #110 · twilio/twilio-python · GitHub
[go: up one dir, main page]

Skip to content

Add sip out TwiML verbs #110

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 yo 8000 ur account

Merged
merged 6 commits into from
Mar 11, 2013
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
26 changes: 26 additions & 0 deletions tests/test_twiml.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,32 @@ def testDial(self):
r = self.strip(r)
self.assertEquals(r, '<?xml version="1.0" encoding="UTF-8"?><Response><Dial>1231231234</Dial></Response>')

def testSip(self):
""" should redirect the call"""
r = Response()
d = r.dial()
d.sip('foo@example.com')
r = self.strip(r)
self.assertEquals(r, '<?xml version="1.0" encoding="UTF-8"?><Response><Dial><Sip>foo@example.com</Sip></Dial></Response>')

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, '<?xml version="1.0" encoding="UTF-8"?><Response><Dial><Sip password="bar" username="foo">foo@example.com</Sip></Dial></Response>')


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, '<?xml version="1.0" encoding="UTF-8"?><Response><Dial><Sip><Uri>foo@example.com</Uri></Sip></Dial></Response>')

def testConvienceMethod(self):
""" should dial to a url via post"""
r = Response()
Expand Down
36 changes: 33 additions & 3 deletions twilio/twiml.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"""

import xml.etree.ElementTree as ET
from six import u

from six import iteritems

class TwimlException(Exception):
pass
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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


0