Skip to content

Commit 143f17f

Browse files
authored
DX-2699 Add <StartStream> and <StopStream> BXML Verbs (#97)
* DX-2699 add `StartStream` and `StopStream` verbs * Add tests * Fix URL Typos in test values * Apply Comments from Code Review * `verbs` -> `verb` * Add `tracks` * Missing `,`
1 parent 094f126 commit 143f17f

File tree

4 files changed

+128
-0
lines changed

4 files changed

+128
-0
lines changed

bandwidth/tests/test_bxml.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,4 +408,32 @@ def test_generate_transfer_bxml_verb(self):
408408
'asdf', 'c-93d6f3c0-be584596-0b74-4fa2-8015-d8ede84bd1a4')
409409
assert actual == expected
410410

411+
def test_start_stream_bxml_verb(self):
412+
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>'
413+
response = Response()
414+
start_stream = StartStream(
415+
destination='https://www.test.com/stream',
416+
name='test_stream',
417+
tracks='inbound',
418+
streamEventUrl='https://www.test.com/event',
419+
streamEventMethod='POST',
420+
username='username',
421+
password='password'
422+
)
423+
response.add_verb(start_stream)
424+
actual = response.to_bxml()
425+
426+
assert expected == actual
427+
428+
def test_stop_stream_bxml_verb(self):
429+
expected = '<?xml version="1.0" encoding="UTF-8"?><Response><StopStream name="test_stream"/></Response>'
430+
response = Response()
431+
stop_stream = StopStream(
432+
name='test_stream'
433+
)
434+
response.add_verb(stop_stream)
435+
actual = response.to_bxml()
436+
437+
assert expected == actual
438+
411439

bandwidth/voice/bxml/verbs/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@
2020
from .start_gather import StartGather
2121
from .tag import Tag
2222
from .sip_uri import SipUri
23+
from .start_stream import StartStream
24+
from .stop_stream import StopStream
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
"""
2+
start_stream.py
3+
4+
Representation of Bandwidth's start stream BXML verb
5+
6+
@copyright Bandwidth INC
7+
"""
8+
9+
from lxml import etree
10+
11+
from .base_verb import AbstractBxmlVerb
12+
13+
START_STREAM_TAG = "StartStream"
14+
15+
16+
class StartStream(AbstractBxmlVerb):
17+
18+
def __init__(self, destination, name=None, tracks=None, streamEventUrl=None, streamEventMethod=None, username=None, password=None):
19+
"""
20+
Initializes the PlayAudio class with the following parameters
21+
22+
:param str destination: A websocket URI to send the stream to
23+
:param str name: A name to refer to this stream by
24+
:param str tracks: The part of the call to send a stream from. `inbound`, `outbound` or `both`.
25+
:param str streamEventUrl: URL to send the associated Webhook events to during this stream's lifetime
26+
:param str streamEventMethod: The HTTP method to use for the request to `streamEventUrl`. `GET` or `POST`
27+
:param str username: The username to send in the HTTP request to `streamEventUrl`
28+
:param str password: The password to send in the HTTP request to `streamEventUrl`
29+
"""
30+
self.destination = destination
31+
self.name = name
32+
self.tracks = tracks
33+
self.streamEventUrl = streamEventUrl
34+
self.streamEventMethod = streamEventMethod
35+
self.username = username
36+
self.password = password
37+
38+
def to_etree_element(self):
39+
"""
40+
Converts the class into an etree element. Used for other verb classes to build xml
41+
42+
:return etree.Element: The etree Element representing this class
43+
"""
44+
root = etree.Element(START_STREAM_TAG)
45+
root.set("destination", self.destination)
46+
if self.name is not None:
47+
root.set("name", self.name)
48+
if self.tracks is not None:
49+
root.set("tracks", self.tracks)
50+
if self.streamEventUrl is not None:
51+
root.set("streamEventUrl", self.streamEventUrl)
52+
if self.streamEventMethod is not None:
53+
root.set("streamEventMethod", self.streamEventMethod)
54+
if self.username is not None:
55+
root.set("username", self.username)
56+
if self.password is not None:
57+
root.set("password", self.password)
58+
return root
59+
60+
def to_bxml(self):
61+
return etree.tostring(self.to_etree_element()).decode()
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
start_stream.py
3+
4+
Representation of Bandwidth's start stream BXML verb
5+
6+
@copyright Bandwidth INC
7+
"""
8+
9+
from lxml import etree
10+
11+
from .base_verb import AbstractBxmlVerb
12+
13+
STOP_STREAM_TAG = "StopStream"
14+
15+
16+
class StopStream(AbstractBxmlVerb):
17+
18+
def __init__(self, name):
19+
"""
20+
Initializes the PlayAudio class with the following parameters
21+
22+
:param str name: The name of the stream to stop
23+
"""
24+
self.name = name
25+
26+
def to_etree_element(self):
27+
"""
28+
Converts the class into an etree element. Used for other verb classes to build xml
29+
30+
:return etree.Element: The etree Element representing this class
31+
"""
32+
root = etree.Element(STOP_STREAM_TAG)
33+
root.set("name", self.name)
34+
return root
35+
36+
def to_bxml(self):
37+
return etree.tostring(self.to_etree_element()).decode()

0 commit comments

Comments
 (0)