Skip to content

Adding Response#add_audio_stop #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions fixtures/response-sessionAudioStop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version" : "1.0",
"response" :
{
"directives": [
{
"type": "AudioPlayer.Stop"
}
],
"shouldEndSession": true
}
}
19 changes: 16 additions & 3 deletions lib/alexa_rubykit/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -36,7 +36,20 @@ def add_audio_url(url, token='', offset=0)
'offsetInMilliseconds' => offset
}
}
}
}.merge(options)
end

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)
Expand Down
8 changes: 8 additions & 0 deletions spec/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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