This repository has been archived by the owner on Oct 15, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Movies Cast spice to replace Kwixer
- Loading branch information
Richard Whalen
committed
May 27, 2016
1 parent
4648d4a
commit d6c0697
Showing
5 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
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 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 | ||
} | ||
}; | ||
|
||
my @triggers = share("triggers.txt")->slurp; | ||
triggers start => @triggers; | ||
|
||
handle remainder => sub { | ||
return $_ if $_; | ||
return; | ||
}; | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{{#if id}} | ||
<a href="{{url}}/reviews" class="btn btn--primary"> | ||
Reviews | ||
</a> | ||
{{/if}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
(function (env) { | ||
'use strict'; | ||
|
||
// This is needed to prevent jQuery from adding '_={timestamp}' to the end | ||
// of the URL, which breaks the call to getScript() | ||
$.ajaxSetup({ cache: true }); | ||
|
||
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); | ||
|
||
env.ddg_spice_movies_cast = function(data) { | ||
// This isn't exactly pretty, but I can't think of any | ||
// more graceful way to handle this. | ||
var hasFailed = ( | ||
!data || | ||
!data.results || | ||
!data.results[0] || | ||
!data.results[0].id | ||
); | ||
|
||
if (hasFailed) { | ||
return Spice.failed('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 | ||
); | ||
|
||
if (hasFailed) { | ||
return Spice.failed('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, | ||
} | ||
} | ||
}); | ||
} | ||
}(this)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
new movies with | ||
new movies featuring | ||
new movies starring | ||
new movie with | ||
new movie featuring | ||
new movie starring | ||
newest movies with | ||
newest movies featuring | ||
newest movies starring | ||
newest movie with | ||
newest movie featuring | ||
newest movie starring | ||
new films with | ||
new films starring | ||
new films featuring | ||
new film with | ||
new film starring | ||
new film featuring | ||
newest films with | ||
newest films starring | ||
newest films featuring | ||
newest film with | ||
newest film starring | ||
newest film featuring | ||
movie with | ||
movies with | ||
movies starring | ||
film with | ||
films with | ||
films starring | ||
film starring | ||
movies featuring | ||
films featuring |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env perl | ||
|
||
use strict; | ||
use warnings; | ||
use Test::More; | ||
use DDG::Test::Spice; | ||
|
||
ddg_spice_test( | ||
[qw( DDG::Spice::Movies::Cast )], | ||
'film with tom cruise' => test_spice( | ||
'/js/spice/movies/cast/tom%20cruise', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::Movies::Cast' | ||
), | ||
'films with tom cruise' => test_spice( | ||
'/js/spice/movies/cast/tom%20cruise', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::Movies::Cast' | ||
), | ||
'movies with tom cruise' => test_spice( | ||
'/js/spice/movies/cast/tom%20cruise', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::Movies::Cast' | ||
), | ||
'movies featuring tom cruise' => test_spice( | ||
'/js/spice/movies/cast/tom%20cruise', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::Movies::Cast' | ||
), | ||
'films featuring tom cruise' => test_spice( | ||
'/js/spice/movies/cast/tom%20cruise', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::Movies::Cast' | ||
), | ||
'film starring tom cruise' => test_spice( | ||
'/js/spice/movies/cast/tom%20cruise', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::Movies::Cast' | ||
), | ||
'Movies directed by tom cruise' => undef, | ||
'movies by tom cruise' => undef, | ||
'tom cruise movies directed' => undef | ||
); | ||
|
||
done_testing; | ||
|