Skip to content

Commit 2b1e779

Browse files
authored
DX-2860 StreamParams (#60)
1 parent 7ef281e commit 2b1e779

File tree

4 files changed

+80
-5
lines changed

4 files changed

+80
-5
lines changed

bandwidth.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.name = 'bandwidth-sdk'
3-
s.version = '10.1.0'
3+
s.version = '10.2.0'
44
s.summary = 'Bandwidth'
55
s.description = 'The official client SDK for Bandwidht\'s Voice, Messaging, MFA, and WebRTC APIs'
66
s.authors = ['Bandwidth']

lib/bandwidth/voice_lib/bxml/verbs/start_stream.rb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,26 @@ def to_bxml(xml)
1515
'streamEventMethod' => streamEventMethod,
1616
'username' => username,
1717
'password' => password
18-
}))
18+
})) do
19+
def embedded_xml(xml, property, type)
20+
if property
21+
s = if property.is_a?(type)
22+
then property
23+
else type.new(property)
24+
end
25+
s.to_bxml(xml)
26+
end
27+
end
28+
def nest_verbs_list(xml, property)
29+
if property
30+
property.each do |verb|
31+
verb.to_bxml(xml)
32+
end
33+
end
34+
end
35+
embedded_xml(xml, stream_params, StreamParam)
36+
nest_verbs_list(xml, nested_verbs)
37+
end
1938
end
2039
end
2140
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require_relative 'xml_verb'
2+
3+
module Bandwidth
4+
module Voice
5+
# The StartStream verb allows a segment of a call to be sent off to another destination for additional processing
6+
class StreamParam
7+
include XmlVerb
8+
9+
def to_bxml(xml)
10+
xml.StreamParam(compact_hash({
11+
'name' => name,
12+
'value' => value
13+
}))
14+
end
15+
end
16+
end
17+
end

test/integration/test_integration.rb

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def test_empty_bxml_verb
274274
assert_equal(expected, actual)
275275
end
276276

277-
def test_bxml_speak_sentence_pause
277+
def test_speak_sentence_pause
278278
bxml = Bandwidth::Voice::Bxml.new()
279279

280280
speak_sentence = Bandwidth::Voice::SpeakSentence.new({
@@ -690,17 +690,56 @@ def test_webrtc_generate_transfer_bxml_verb
690690
end
691691

692692
def test_start_stream_bxml_verb
693-
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>'
693+
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"/></StartStream></Response>'
694694
response = Bandwidth::Voice::Response.new()
695+
696+
stream_param1 = Bandwidth::Voice::StreamParam.new({
697+
:name => "name1",
698+
:value => "value1"
699+
})
700+
701+
start_stream = Bandwidth::Voice::StartStream.new({
702+
:destination => "https://www.test.com/stream",
703+
:name => "test_stream",
704+
:tracks => "inbound",
705+
:streamEventUrl => "https://www.test.com/event",
706+
:streamEventMethod => "POST",
707+
:username => "username",
708+
:password => "password",
709+
:stream_params => stream_param1
710+
})
711+
712+
response.push(start_stream)
713+
actual = response.to_bxml()
714+
715+
assert_equal(expected, actual)
716+
end
717+
718+
def test_start_stream_multiple_nested_stream_params
719+
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>'
720+
response = Bandwidth::Voice::Response.new()
721+
722+
stream_param1 = Bandwidth::Voice::StreamParam.new({
723+
:name => "name1",
724+
:value => "value1"
725+
})
726+
727+
stream_param2 = Bandwidth::Voice::StreamParam.new({
728+
:name => "name2",
729+
:value => "value2"
730+
})
731+
695732
start_stream = Bandwidth::Voice::StartStream.new({
696733
:destination => "https://www.test.com/stream",
697734
:name => "test_stream",
698735
:tracks => "inbound",
699736
:streamEventUrl => "https://www.test.com/event",
700737
:streamEventMethod => "POST",
701738
:username => "username",
702-
:password => "password"
739+
:password => "password",
740+
:nested_verbs => [stream_param1, stream_param2]
703741
})
742+
704743
response.push(start_stream)
705744
actual = response.to_bxml()
706745

0 commit comments

Comments
 (0)