Skip to content

Commit

Permalink
Merge 17fb069 into c26a249
Browse files Browse the repository at this point in the history
  • Loading branch information
benlangfeld committed Dec 2, 2014
2 parents c26a249 + 17fb069 commit 1a302ce
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/punchblock/component/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
module Punchblock
module Component
class Input < ComponentNode

include HasHeaders

NLSML_NAMESPACE = 'http://www.ietf.org/xml/ns/mrcpv2'

register :input, :input
Expand Down
3 changes: 3 additions & 0 deletions lib/punchblock/component/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
module Punchblock
module Component
class Output < ComponentNode

include HasHeaders

register :output, :output

class Document < RayoNode
Expand Down
4 changes: 2 additions & 2 deletions lib/punchblock/has_headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def headers=(other)
end

def inherit(xml_node)
xml_node.xpath('//ns:header', ns: self.class.registered_ns).to_a.each do |header|
xml_node.xpath('//ns:header', ns: RAYO_NAMESPACES[:core]).to_a.each do |header|
if headers.has_key?(header[:name])
headers[header[:name]] = [headers[header[:name]]]
headers[header[:name]] << header[:value]
Expand All @@ -26,7 +26,7 @@ def rayo_children(root)
super
headers.each do |name, value|
Array(value).each do |v|
root.header name: name, value: v
root.header name: name, value: v, xmlns: RAYO_NAMESPACES[:core]
end
end
end
Expand Down
16 changes: 15 additions & 1 deletion spec/punchblock/component/input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ module Component
:inter_digit_timeout => 2000,
:recognition_timeout => 0,
:sensitivity => 0.5,
:min_confidence => 0.5
:min_confidence => 0.5,
:headers => { 'Confidence-Threshold' => '0.5', 'Sensitivity-Level' => '0.2' }
end

describe '#grammars' do
Expand Down Expand Up @@ -112,6 +113,11 @@ module Component
end
end

describe '#headers' do
subject { super().headers }
it { should be == { 'Confidence-Threshold' => '0.5', 'Sensitivity-Level' => '0.2' } }
end

describe "exporting to Rayo" do
it "should export to XML that can be understood by its parser" do
new_instance = RayoNode.from_xml subject.to_rayo
Expand All @@ -127,6 +133,7 @@ module Component
expect(new_instance.recognition_timeout).to eq(0)
expect(new_instance.sensitivity).to eq(0.5)
expect(new_instance.min_confidence).to eq(0.5)
expect(new_instance.headers).to eq({ 'Confidence-Threshold' => '0.5', 'Sensitivity-Level' => '0.2' })
end

it "should wrap the grammar value in CDATA" do
Expand Down Expand Up @@ -164,6 +171,8 @@ module Component
<grammar content-type="application/grammar+custom">
<![CDATA[ [10 DIGITS] ]]>
</grammar>
<header xmlns='urn:xmpp:rayo:1' name="Confidence-Threshold" value="0.5" />
<header xmlns='urn:xmpp:rayo:1' name="Sensitivity-Level" value="0.2" />
</input>
MESSAGE
end
Expand Down Expand Up @@ -235,6 +244,11 @@ module Component
it { should be == [] }
end
end

describe '#headers' do
subject { super().headers }
it { should be == { 'Confidence-Threshold' => '0.5', 'Sensitivity-Level' => '0.2' } }
end
end

def grxml_doc(mode = :dtmf)
Expand Down
16 changes: 15 additions & 1 deletion spec/punchblock/component/output_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def ssml_doc(mode = :ordinal)
:max_time => 30000,
:voice => 'allison',
:renderer => 'swift',
:render_document => {:value => ssml_doc}
:render_document => {:value => ssml_doc},
:headers => { 'Jump-Size' => '2', 'Kill-On-Barge-In' => 'false' }
end

describe '#interrupt_on' do
Expand Down Expand Up @@ -185,6 +186,11 @@ def ssml_doc(mode = :ordinal)
end
end

describe '#headers' do
subject { super().headers }
it { should be == { 'Jump-Size' => '2', 'Kill-On-Barge-In' => 'false' } }
end

describe "exporting to Rayo" do
it "should export to XML that can be understood by its parser" do
new_instance = RayoNode.from_xml Nokogiri::XML(subject.to_rayo.to_xml, nil, nil, Nokogiri::XML::ParseOptions::NOBLANKS).root
Expand All @@ -198,6 +204,7 @@ def ssml_doc(mode = :ordinal)
expect(new_instance.voice).to eq('allison')
expect(new_instance.renderer).to eq('swift')
expect(new_instance.render_documents).to eq([Output::Document.new(:value => ssml_doc)])
expect(new_instance.headers).to eq({ 'Jump-Size' => '2', 'Kill-On-Barge-In' => 'false' })
end

it "should wrap the document value in CDATA" do
Expand Down Expand Up @@ -258,6 +265,8 @@ def ssml_doc(mode = :ordinal)
</speak>
]]>
</document>
<header xmlns='urn:xmpp:rayo:1' name="Jump-Size" value="2" />
<header xmlns='urn:xmpp:rayo:1' name="Kill-On-Barge-In" value="false" />
</output>
MESSAGE
end
Expand Down Expand Up @@ -330,6 +339,11 @@ def ssml_doc(mode = :ordinal)
it { should be == [Output::Document.new(content_type: 'text/uri-list', value: ['http://example.com/hello.mp3', 'http://example.com/goodbye.mp3'])] }
end
end

describe '#headers' do
subject { super().headers }
it { should be == { 'Jump-Size' => '2', 'Kill-On-Barge-In' => 'false' } }
end
end

describe Output::Document do
Expand Down

0 comments on commit 1a302ce

Please sign in to comment.