/lib/DDG/Spice/Movie.pm

https://github.com/pardocz/zeroclickinfo-spice · Perl · 37 lines · 22 code · 7 blank · 8 comment · 1 complexity · df14c3a84c2980080a53e760e8574ed7 MD5 · raw file

  1. package DDG::Spice::Movie;
  2. use DDG::Spice;
  3. primary_example_queries "the graduate movie";
  4. secondary_example_queries "jiro dreams of sushi rating", "indie game film";
  5. description "Movie information from Rotten Tomatoes";
  6. name "Movie";
  7. code_url "https://github.com/duckduckgo/zeroclickinfo-spice/blob/master/lib/DDG/Spice/Movie.pm";
  8. icon_url "/i/www.rottentomatoes.com.ico";
  9. topics "entertainment", "everyday";
  10. category "entertainment";
  11. attribution github => ['https://github.com/moollaza','Zaahir Moolla'],
  12. twitter => ['https://twitter.com/zmoolla','zmoolla'];
  13. spice proxy_cache_valid => "200 7d";
  14. spice to => 'http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey={{ENV{DDG_SPICE_ROTTEN_APIKEY}}}&q=$1&page_limit=50&page=1&callback={{callback}}';
  15. # It's important that 'movie info' precede 'movie' so that the handler
  16. # encounters it first and removes both words, rather than encountering 'movie'
  17. # first in the list, removing it, and leaving the word 'info.'
  18. # This spice will usually be triggered by deep triggers,
  19. # with a few extra triggers that deep might miss.
  20. my @triggers = ( 'rotten tomatoes', 'rotten');
  21. triggers startend => @triggers;
  22. handle query_lc => sub {
  23. # spice triggers are called when a trigger is part of a hyphenated word
  24. # i.e.: asus rt-66nu
  25. # this makes sure that only space deliminated words fire this spice
  26. my $input = $_;
  27. map { return $input if $input =~ s/(^|\s)$_(\s|$)// and $input ne '' } @triggers;
  28. return;
  29. };
  30. 1;