diff --git a/bandwidth/tests/test_bxml.py b/bandwidth/tests/test_bxml.py index 66d8ac62..482d7d6e 100644 --- a/bandwidth/tests/test_bxml.py +++ b/bandwidth/tests/test_bxml.py @@ -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 = '' + 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 = '' + response = Response() + stop_stream = StopStream( + name='test_stream' + ) + response.add_verb(stop_stream) + actual = response.to_bxml() + + assert expected == actual + diff --git a/bandwidth/voice/bxml/verbs/__init__.py b/bandwidth/voice/bxml/verbs/__init__.py index 9e153007..27c4d0bb 100644 --- a/bandwidth/voice/bxml/verbs/__init__.py +++ b/bandwidth/voice/bxml/verbs/__init__.py @@ -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 diff --git a/bandwidth/voice/bxml/verbs/start_stream.py b/bandwidth/voice/bxml/verbs/start_stream.py new file mode 100644 index 00000000..26090519 --- /dev/null +++ b/bandwidth/voice/bxml/verbs/start_stream.py @@ -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() diff --git a/bandwidth/voice/bxml/verbs/stop_stream.py b/bandwidth/voice/bxml/verbs/stop_stream.py new file mode 100644 index 00000000..031fba3a --- /dev/null +++ b/bandwidth/voice/bxml/verbs/stop_stream.py @@ -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()