Skip to content

Commit 025fbbb

Browse files
authored
DX-2858 Add StreamParam BXML Verb (#111)
* Add `StreamParam` verb * bump version to `14.2.0`
1 parent 95a55d8 commit 025fbbb

File tree

6 files changed

+61
-6
lines changed

6 files changed

+61
-6
lines changed

bandwidth/tests/test_bxml.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,17 +409,27 @@ def test_generate_transfer_bxml_verb(self):
409409
assert actual == expected
410410

411411
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>'
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"><StreamParam name="name1" value="value1"/><StreamParam name="name2" value="value2"/></StartStream></Response>'
413413
response = Response()
414+
stream_param_1 = StreamParam(
415+
name="name1",
416+
value="value1"
417+
)
418+
stream_param_2 = StreamParam(
419+
name="name2",
420+
value="value2"
421+
)
414422
start_stream = StartStream(
415423
destination='https://www.test.com/stream',
416424
name='test_stream',
417425
tracks='inbound',
418426
streamEventUrl='https://www.test.com/event',
419427
streamEventMethod='POST',
420428
username='username',
421-
password='password'
429+
password='password',
430+
streamParams=[stream_param_1, stream_param_2]
422431
)
432+
423433
response.add_verb(start_stream)
424434
actual = response.to_bxml()
425435

bandwidth/voice/bxml/verbs/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@
2121
from .tag import Tag
2222
from .sip_uri import SipUri
2323
from .start_stream import StartStream
24+
from .stream_param import StreamParam
2425
from .stop_stream import StopStream

bandwidth/voice/bxml/verbs/start_stream.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
class StartStream(AbstractBxmlVerb):
1717

18-
def __init__(self, destination, name=None, tracks=None, streamEventUrl=None, streamEventMethod=None, username=None, password=None):
18+
def __init__(self, destination, name=None, tracks=None, streamEventUrl=None, streamEventMethod=None, username=None, password=None, streamParams=None):
1919
"""
20-
Initializes the PlayAudio class with the following parameters
20+
Initializes the StartStream class with the following parameters
2121
2222
:param str destination: A websocket URI to send the stream to
2323
:param str name: A name to refer to this stream by
@@ -34,6 +34,7 @@ def __init__(self, destination, name=None, tracks=None, streamEventUrl=None, str
3434
self.streamEventMethod = streamEventMethod
3535
self.username = username
3636
self.password = password
37+
self.stream_params = streamParams
3738

3839
def to_etree_element(self):
3940
"""
@@ -55,6 +56,9 @@ def to_etree_element(self):
5556
root.set("username", self.username)
5657
if self.password is not None:
5758
root.set("password", self.password)
59+
if self.stream_params is not None:
60+
for stream_param in self.stream_params:
61+
root.append(stream_param.to_etree_element())
5862
return root
5963

6064
def to_bxml(self):

bandwidth/voice/bxml/verbs/stop_stream.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class StopStream(AbstractBxmlVerb):
1717

1818
def __init__(self, name):
1919
"""
20-
Initializes the PlayAudio class with the following parameters
20+
Initializes the StopStream class with the following parameters
2121
2222
:param str name: The name of the stream to stop
2323
"""
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
STREAM_PARAM_TAG = "StreamParam"
14+
15+
16+
class StreamParam(AbstractBxmlVerb):
17+
18+
def __init__(self, name, value):
19+
"""
20+
Initializes the StreamParam class with the following parameters
21+
22+
:param str name: The name of this parameter, up to 256 characters.
23+
:param str value: The value of this parameter, up to 2048 characters.
24+
"""
25+
self.name = name
26+
self.value = value
27+
28+
def to_etree_element(self):
29+
"""
30+
Converts the class into an etree element. Used for other verb classes to build xml
31+
32+
:return etree.Element: The etree Element representing this class
33+
"""
34+
root = etree.Element(STREAM_PARAM_TAG)
35+
root.set("name", self.name)
36+
root.set("value", self.value)
37+
return root
38+
39+
def to_bxml(self):
40+
return etree.tostring(self.to_etree_element()).decode()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
setup(
1717
name='bandwidth-sdk',
18-
version='14.1.0',
18+
version='14.2.0',
1919
description='Bandwidth\'s set of APIs',
2020
long_description=long_description,
2121
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)