Skip to content
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
28 changes: 28 additions & 0 deletions bandwidth/tests/test_bxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,4 +408,32 @@ def test_generate_transfer_bxml_verb(self):
'asdf', 'c-93d6f3c0-be584596-0b74-4fa2-8015-d8ede84bd1a4')
assert actual == expected

def test_start_stream_bxml_verb(self):
expected = '<?xml version="1.0" encoding="UTF-8"?><Response><StartStream destination="https://www.test.com/stream" name="test_stream" tracks="inbound" streamEventUrl="https://www.test.com/event" streamEventMethod="POST" username="username" password="password"/></Response>'
response = Response()
start_stream = StartStream(
destination='https://www.test.com/stream',
name='test_stream',
tracks='inbound',
streamEventUrl='https://www.test.com/event',
streamEventMethod='POST',
username='username',
password='password'
)
response.add_verb(start_stream)
actual = response.to_bxml()

assert expected == actual

def test_stop_stream_bxml_verb(self):
expected = '<?xml version="1.0" encoding="UTF-8"?><Response><StopStream name="test_stream"/></Response>'
response = Response()
stop_stream = StopStream(
name='test_stream'
)
response.add_verb(stop_stream)
actual = response.to_bxml()

assert expected == actual


2 changes: 2 additions & 0 deletions bandwidth/voice/bxml/verbs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@
from .start_gather import StartGather
from .tag import Tag
from .sip_uri import SipUri
from .start_stream import StartStream
from .stop_stream import StopStream
61 changes: 61 additions & 0 deletions bandwidth/voice/bxml/verbs/start_stream.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""
start_stream.py

Representation of Bandwidth's start stream BXML verb

@copyright Bandwidth INC
"""

from lxml import etree

from .base_verb import AbstractBxmlVerb

START_STREAM_TAG = "StartStream"


class StartStream(AbstractBxmlVerb):

def __init__(self, destination, name=None, tracks=None, streamEventUrl=None, streamEventMethod=None, username=None, password=None):
"""
Initializes the PlayAudio class with the following parameters

:param str destination: A websocket URI to send the stream to
:param str name: A name to refer to this stream by
:param str tracks: The part of the call to send a stream from. `inbound`, `outbound` or `both`.
:param str streamEventUrl: URL to send the associated Webhook events to during this stream's lifetime
:param str streamEventMethod: The HTTP method to use for the request to `streamEventUrl`. `GET` or `POST`
:param str username: The username to send in the HTTP request to `streamEventUrl`
:param str password: The password to send in the HTTP request to `streamEventUrl`
"""
self.destination = destination
self.name = name
self.tracks = tracks
self.streamEventUrl = streamEventUrl
self.streamEventMethod = streamEventMethod
self.username = username
self.password = password

def to_etree_element(self):
"""
Converts the class into an etree element. Used for other verb classes to build xml

:return etree.Element: The etree Element representing this class
"""
root = etree.Element(START_STREAM_TAG)
root.set("destination", self.destination)
if self.name is not None:
root.set("name", self.name)
if self.tracks is not None:
root.set("tracks", self.tracks)
if self.streamEventUrl is not None:
root.set("streamEventUrl", self.streamEventUrl)
if self.streamEventMethod is not None:
root.set("streamEventMethod", self.streamEventMethod)
if self.username is not None:
root.set("username", self.username)
if self.password is not None:
root.set("password", self.password)
return root

def to_bxml(self):
return etree.tostring(self.to_etree_element()).decode()
37 changes: 37 additions & 0 deletions bandwidth/voice/bxml/verbs/stop_stream.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
start_stream.py

Representation of Bandwidth's start stream BXML verb

@copyright Bandwidth INC
"""

from lxml import etree

from .base_verb import AbstractBxmlVerb

STOP_STREAM_TAG = "StopStream"


class StopStream(AbstractBxmlVerb):

def __init__(self, name):
"""
Initializes the PlayAudio class with the following parameters

:param str name: The name of the stream to stop
"""
self.name = name

def to_etree_element(self):
"""
Converts the class into an etree element. Used for other verb classes to build xml

:return etree.Element: The etree Element representing this class
"""
root = etree.Element(STOP_STREAM_TAG)
root.set("name", self.name)
return root

def to_bxml(self):
return etree.tostring(self.to_etree_element()).decode()