From 48730252e1658b169d500cc7edbf601496cb392c Mon Sep 17 00:00:00 2001 From: Mike Mulev Date: Sun, 1 Oct 2017 17:49:08 +0300 Subject: [PATCH 1/2] add ruby 2.4.2 to travis config --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index c270cd0..9673b68 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ rvm: - 2.1.0 - 2.2.0 - 2.3.4 +- 2.4.2 script: rake test notifications: slack: From 15dcdfbfc33a4fc356e792a27cca947c0c01a5c3 Mon Sep 17 00:00:00 2001 From: Mike Mulev Date: Sun, 1 Oct 2017 19:52:20 +0300 Subject: [PATCH 2/2] handle System requests from Amazon --- CHANGELOG | 5 +++ lib/alexa_ruby/alexa.rb | 2 +- spec/fixtures/request/system_request.json | 41 +++++++++++++++++++++++ spec/request/audio_player_request_spec.rb | 11 ++++++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/request/system_request.json diff --git a/CHANGELOG b/CHANGELOG index bb83fae..8555544 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +[1.4.5] +- Handle different Playback requests +- Validate signature for all except AudioPlayer +- Handle System requests + [1.4.3] - Print original signature rather than decoded when raise validation error diff --git a/lib/alexa_ruby/alexa.rb b/lib/alexa_ruby/alexa.rb index 20128c1..bdd4ad0 100644 --- a/lib/alexa_ruby/alexa.rb +++ b/lib/alexa_ruby/alexa.rb @@ -55,7 +55,7 @@ def define_request IntentRequest.new(@req) when /SessionEnded/ SessionEndedRequest.new(@req) - when /AudioPlayer/, /Playback/ + when /AudioPlayer/, /Playback/, /System/ AudioPlayerRequest.new(@req) end end diff --git a/spec/fixtures/request/system_request.json b/spec/fixtures/request/system_request.json new file mode 100644 index 0000000..3debfe3 --- /dev/null +++ b/spec/fixtures/request/system_request.json @@ -0,0 +1,41 @@ +{ + "version": "1.0", + "context": { + "AudioPlayer": { + "offsetInMilliseconds": 2848, + "token": "d8974a63-8b61-483f-a5b9-52c6a2e78621", + "playerActivity": "PLAYING" + }, + "System": { + "application": { + "applicationId": "amzn1.ask.skill.3b62f58b-eed3-4be4-9339-6b4d0280eab1" + }, + "user": { + "userId": "amzn1.ask.account.AFWYZS4PQO6OLHISVNINUKKE23FTOMLQSX7Q3W6BDOTWWJV5U2FA3JPL4IITSGUXJOAYL3ZYMFZSRFN3EJRKALGP2FSKE2NZTLO52ORF6WPCTN4SCCM2Q2HSJ7AT6SX3LX3HIPGBWRLLUPBYQDI62KDEHIR7PB3ZEZWV5KFL64UZZOPXDL2Q5C56MGVAHNK4DFZ52GX4ZGFTIFY", + "permissions": { + "consentToken": "Atza|IwEBII_UinzkIOWpmH6xfJ8pEBv5v6L24X_VUvqku2cvB2Qs_ZxZeUkHL_R55hEFQBTny6iJjHtbU-OJWjmwIyYbNz1L11q8Clwxzn5lGVmp0qzRHaitiZLNenZFWIzSdJ23i-ibH3HumP1eENNmgtOiv6B5tAiVT-1HhTEWVQR7MaWOn1OLQCZ0QBd0z5l6_rorginVxeOig28s3tkb5v8jeR19LJ4JGjB3uEQ0o9ksvKSep3Ug_s45ldDMRSMZoaM8dRjynkF5PAr8t6a_Rekdxb6izTc7pksph144QmADlUmmxOWg52sLtnMHkud4rgV2-rSVG4ijm5A4JipWmHTr_norJA6W281JadAVd8c83CT75jA4bkVMlSgypXf06y57tmbswf9abbZRN_6zGgJYtjiHbbA62J8lC6GNMRaBu_ZqlSD8-ENIQGCN_bqmmMH4DDqBmkqU0EkffU8TUTvADWcP1m-D4VNqz_pmIFZQBhR5gA" + } + }, + "device": { + "deviceId": "amzn1.ask.device.AFK7L4XTYU55CJJFDAYM56JOYJ4BQ2O44LBZVLLFIX4SOOKRGZTZHEJUBB2T6VP5H5K6QXV6TCRPQ4GO2FOAZXTLUOS35QG5FHSSGPIIFR4AXQXWW57D44XZBM36D3RLGBDC6PKMMCKHLWRNO2WLY7KGXJSQ", + "supportedInterfaces": { + "AudioPlayer": {} + } + }, + "apiEndpoint": "https://api.amazonalexa.com" + } + }, + "request": { + "type": "System.ExceptionEncountered", + "requestId": "amzn1.echo-api.request.cc8b3481-ca5d-44bf-ab15-b03c10ee738c", + "timestamp": "2017-10-01T13:49:26Z", + "locale": "en-US", + "error": { + "type": "INVALID_RESPONSE", + "message": "An exception occurred while dispatching the request to the skill." + }, + "cause": { + "requestId": "amzn1.echo-api.request.f5e57db8-eb70-4d44-95c7-fd7575a2581d" + } + } +} diff --git a/spec/request/audio_player_request_spec.rb b/spec/request/audio_player_request_spec.rb index 11c2ed7..8a50d06 100644 --- a/spec/request/audio_player_request_spec.rb +++ b/spec/request/audio_player_request_spec.rb @@ -21,4 +21,15 @@ alexa.request.error_player_activity.must_equal 'string' end end + + describe 'System request' do + before do + @json = File.read("#{@fpath}/system_request.json") + end + + it 'should parse valid System request correctly' do + alexa = AlexaRuby.new(@json) + alexa.request.type.must_equal :audio_player + end + end end