From 485d7e435c2944f7a468cd46bb00419d4b0cc0a6 Mon Sep 17 00:00:00 2001 From: Chip Miller Date: Mon, 3 Jul 2017 11:53:55 -0700 Subject: [PATCH 1/2] Adding Response#add_audio_stop `when 'AMAZON.PauseIntent' then output.add_audio_stop` --- fixtures/response-sessionAudioStop.json | 12 ++++++++++++ lib/alexa_rubykit/response.rb | 4 ++++ spec/response_spec.rb | 8 ++++++++ 3 files changed, 24 insertions(+) create mode 100644 fixtures/response-sessionAudioStop.json diff --git a/fixtures/response-sessionAudioStop.json b/fixtures/response-sessionAudioStop.json new file mode 100644 index 0000000..00bb216 --- /dev/null +++ b/fixtures/response-sessionAudioStop.json @@ -0,0 +1,12 @@ +{ + "version" : "1.0", + "response" : + { + "directives": [ + { + "type": "AudioPlayer.Stop" + } + ], + "shouldEndSession": true + } +} diff --git a/lib/alexa_rubykit/response.rb b/lib/alexa_rubykit/response.rb index 58d807d..45834e4 100644 --- a/lib/alexa_rubykit/response.rb +++ b/lib/alexa_rubykit/response.rb @@ -39,6 +39,10 @@ def add_audio_url(url, token='', offset=0) } end + def add_audio_stop + @directives << { 'type' => 'AudioPlayer.Stop' } + end + def add_reprompt(speech_text, ssml = false) if ssml @reprompt = { "outputSpeech" => { :type => 'SSML', :ssml => check_ssml(speech_text) } } diff --git a/spec/response_spec.rb b/spec/response_spec.rb index 8b3d742..84a9568 100644 --- a/spec/response_spec.rb +++ b/spec/response_spec.rb @@ -123,4 +123,12 @@ expect(response_json).to eq(sample_json) end + it 'should create a valid response with an AudioPlayer.Stop directive' do + response = AlexaRubykit::Response.new + response.add_audio_stop + response.build_response_object + response_json = response.build_response + sample_json = JSON.parse(File.read('fixtures/response-sessionAudioStop.json')).to_json + expect(response_json).to eq(sample_json) + end end \ No newline at end of file From 5efa29670941ffd7a199f0877a7553733aabf55d Mon Sep 17 00:00:00 2001 From: Chip Miller Date: Wed, 12 Jul 2017 12:28:29 -0700 Subject: [PATCH 2/2] Adding audio_clear_queue and options={} all around --- lib/alexa_rubykit/response.rb | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/alexa_rubykit/response.rb b/lib/alexa_rubykit/response.rb index 45834e4..7526301 100644 --- a/lib/alexa_rubykit/response.rb +++ b/lib/alexa_rubykit/response.rb @@ -24,8 +24,8 @@ def add_speech(speech_text, ssml = false) end @speech end - - def add_audio_url(url, token='', offset=0) + + def add_audio_url(url, token='', offset=0, options={}) @directives << { 'type' => 'AudioPlayer.Play', 'playBehavior' => 'REPLACE_ALL', @@ -36,11 +36,20 @@ def add_audio_url(url, token='', offset=0) 'offsetInMilliseconds' => offset } } - } + }.merge(options) end - def add_audio_stop - @directives << { 'type' => 'AudioPlayer.Stop' } + def add_audio_stop(options={}) + @directives << { + 'type' => 'AudioPlayer.Stop' + }.merge(options) + end + + def add_audio_clear_queue(options={}) + @directives << { + 'type' => 'AudioPlayer.ClearQueue', + 'clearBehavior' => 'CLEAR_ENQUEUED' #CLEAR_ALL + }.merge(options) end def add_reprompt(speech_text, ssml = false)