Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Commit

Permalink
Address Code review comments for Movie Cast IA
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Whalen committed May 30, 2016
1 parent d6c0697 commit 5d990aa
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 84 deletions.
23 changes: 19 additions & 4 deletions lib/DDG/Spice/Movies/Cast.pm
Expand Up @@ -2,16 +2,31 @@ package DDG::Spice::Movies::Cast;

use DDG::Spice;

spice to => 'https://api.themoviedb.org/3/search/person?query=$1&api_key={{ENV{DDG_SPICE_THE_MOVIE_DB_KEY}}}&callback={{callback}}';
spice to => 'https://api.themoviedb.org/3/search/person?query=$1&api_key={{ENV{DDG_SPICE_MOVIEDB_APIKEY}}}&callback={{callback}}';

spice alt_to => {
details => {
to => 'http://api.themoviedb.org/3/discover/movie?with_cast=$1&api_key={{ENV{DDG_SPICE_THE_MOVIE_DB_KEY}}}&sort_by=popularity.desc',
wrap_jsonp_callback => 1
to => 'http://api.themoviedb.org/3/discover/movie?with_cast=$1&api_key={{ENV{DDG_SPICE_MOVIEDB_APIKEY}}}&sort_by=popularity.desc'
}
};

my @triggers = share("triggers.txt")->slurp;
my @nouns = (
"newest movies",
"newest movie",
"new films",
"new film",
"newest films",
"newest film",
"movie",
"movies",
"film",
"films",
);
my @triggers = ();
foreach (@nouns) {
push @triggers, ($_ . " with", $_ . " starring", $_ . " featuring")
}

triggers start => @triggers;

handle remainder => sub {
Expand Down
89 changes: 42 additions & 47 deletions share/spice/movies/cast/movies_cast.js
Expand Up @@ -7,11 +7,7 @@

var DETAIL_ENDPOINT = '/js/spice/movies/details/';
var POSTER_URL = 'http://image.tmdb.org/t/p/w185';

var getMovieUrl = function(id) {
return 'http://www.themoviedb.org/movie/' + id;
}
Handlebars.registerHelper("getMovieUrl", getMovieUrl);
var MOVIE_URL = 'http://www.themoviedb.org/movie/';

env.ddg_spice_movies_cast = function(data) {
// This isn't exactly pretty, but I can't think of any
Expand All @@ -24,52 +20,51 @@
);

if (hasFailed) {
return Spice.failed('cast');
return Spice.failed('movies_cast');
}

$.getScript(DETAIL_ENDPOINT + data.results[0].id)
};

env.ddg_spice_movies_details = function(api_result) {
var hasFailed = (
!api_result ||
!api_result.results ||
!api_result.results.length
);
$.getJSON(DETAIL_ENDPOINT + data.results[0].id, function(api_result) {
var hasFailed = (
!api_result ||
!api_result.results ||
!api_result.results.length
);

if (hasFailed) {
return Spice.failed('cast');
}
if (hasFailed) {
return Spice.failed('movies_cast');
}

Spice.add({
id: 'cast',
name: 'Movies',
data: api_result.results,
meta: {
sourceName: 'TheMovieDb',
sourceUrl: 'http://www.themoviedb.org/person/'
+ api_result.results[0].id,
primaryText: 'Showing ' + api_result.results.length + ' Movies'
},
normalize: function(item) {
return {
heading: item.title,
url: getMovieUrl(item.id),
rating: item.vote_average / 2, // normalize from 10 to 5 pt scale
reviewCount: item.vote_count,
brand: item.release_date,
abstract: item.overview,
image: POSTER_URL + item.poster_path,
img_m: POSTER_URL + item.poster_path,
};
},
templates: {
group: 'movies',
options: {
rating: true,
buy: Spice.movies_cast.buy,
Spice.add({
id: 'cast',
name: 'Movies',
data: api_result.results,
meta: {
sourceName: 'TheMovieDb',
sourceUrl: 'http://www.themoviedb.org/person/'
+ api_result.results[0].id,
primaryText: 'Showing ' + api_result.results.length + ' Movies'
},
normalize: function(item) {
return {
heading: item.title,
url: MOVIE_URL + item.id,
rating: item.vote_average / 2, // normalize from 10 to 5 pt scale
reviewCount: item.vote_count,
brand: item.release_date,
abstract: item.overview,
image: POSTER_URL + item.poster_path,
img_m: POSTER_URL + item.poster_path,
};
},
templates: {
group: 'movies',
options: {
rating: true,
buy: Spice.movies_cast.buy,
}
}
}
});

});
}
};
}(this));
33 changes: 0 additions & 33 deletions share/spice/movies/cast/triggers.txt

This file was deleted.

0 comments on commit 5d990aa

Please sign in to comment.