From e09ee66d1ceb24d53894ebcfaa9b19fa2c149c8e Mon Sep 17 00:00:00 2001 From: Jordan Hackworth Date: Sat, 29 Oct 2016 15:57:45 -0700 Subject: [PATCH] Fix Invalid Response, cleanup (#12) --- README.md | 4 ++-- .env => default.env | 2 +- lib/handlers.js | 4 ++-- lib/utils.js | 17 ++++++++--------- 4 files changed, 13 insertions(+), 14 deletions(-) rename .env => default.env (93%) diff --git a/README.md b/README.md index cf5daf1..275a61c 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Function](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/d ## Configuring The Skill -To configure the skill, open up the `.env` file and fill in the correct values for `CP_URL`, which +To configure the skill, copy `default.env` to `.env` and fill in the correct values for `CP_URL`, which should point to your Couch Potato server, and `CP_API_KEY` which should have your server's API key. ## Testing The Skill Locally @@ -40,7 +40,7 @@ in the Sample Utterances field, copy and paste the contents of The skill is built to be easily hosted on Amazon's [AWS Lambda service](https://aws.amazon.com/lambda/). Create your Lambda function (using the -alexa-skills-kit-color-expert blueprint) and make sure you choose Node.js as the runtime. After +alexa-skills-kit-color-expert blueprint) and make sure you choose Node.js as the runtime. After you've created your Lambda function, look at the top right of the page to get your Lambda ARN number and put that in the Alexa Skill Information Endpoint field. diff --git a/.env b/default.env similarity index 93% rename from .env rename to default.env index 82ef408..c90e982 100644 --- a/.env +++ b/default.env @@ -9,4 +9,4 @@ AWS_TIMEOUT=10 AWS_DESCRIPTION= AWS_RUNTIME=nodejs CP_URL=http://url-to-couch-potato-server -CP_API_KEY=apiKey +CP_API_KEY=APIKEY diff --git a/lib/handlers.js b/lib/handlers.js index 3393923..9e26f10 100644 --- a/lib/handlers.js +++ b/lib/handlers.js @@ -54,12 +54,12 @@ function handleFindMovieIntent(req, resp) { function handleAddMovieIntent(req, resp) { var movieName = req.slot('movieName'); - + cp.movie.search(movieName,5).then(function (movies) { movies = utils.formatSearchResults(movies); utils.sendSearchResponse(movies, movieName, resp); }); - + //Async response return false; } diff --git a/lib/utils.js b/lib/utils.js index f76649d..7753a2a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -18,7 +18,7 @@ function buildPrompt(movies) { } function sendSearchResponse(movies, movieName, resp) { - + if(!movies || !movies.length > 0) { return resp.say('No movie found for ' + movieName).send(); } @@ -31,24 +31,24 @@ function sendSearchResponse(movies, movieName, resp) { } function formatSearchResults(movies) { - + var newMovies = []; - + if (movies != undefined) { for (var i = 0; i < movies.length; i++) { newMovies.push({ original_title: movies[i].original_title, - inLibrary: movies[i].in_library, + in_library: movies[i].in_library, year: movies[i].year, titles: movies[i].titles, imdb: movies[i].imdb - }); - } + }); + } } - - return newMovies; + + return newMovies; } module.exports = { @@ -56,4 +56,3 @@ module.exports = { sendSearchResponse: sendSearchResponse, formatSearchResults: formatSearchResults }; -