PageRenderTime 273ms CodeModel.GetById 48ms RepoModel.GetById 9ms app.codeStats 0ms

/lib/DDG/Spice/Songkick/Geteventid.pm

http://github.com/duckduckgo/zeroclickinfo-spice
Perl | 41 lines | 31 code | 7 blank | 3 comment | 4 complexity | de43b345ba777546b09be856a28a7399 MD5 | raw file
Possible License(s): Apache-2.0
  1. package DDG::Spice::Songkick::Geteventid;
  2. # ABSTRACT: Get concerts for an artist through Songkick
  3. use strict;
  4. use warnings;
  5. use DDG::Spice;
  6. name "Songkick Events";
  7. description "See upcoming concerts.";
  8. source "Songkick";
  9. primary_example_queries "concerts in Boston";
  10. secondary_example_queries "Boston concerts";
  11. category "entertainment";
  12. topics "entertainment", "everyday", "music";
  13. # FIXME Point to the duckduckgo repository on pull.
  14. code_url "https://github.com/bradcater/zeroclickinfo-spice/blob/master/lib/DDG/Spice/Songkick/Events.pm";
  15. attribution github => ["https://github.com/bradcater", "Brad Cater"],
  16. twitter => ["https://twitter.com/bradcater", "Brad Cater"];
  17. triggers startend => "concert", "concerts";
  18. spice to => 'http://api.songkick.com/api/3.0/search/locations.json?apikey={{ENV{DDG_SPICE_SONGKICK_APIKEY}}}&per_page=1&query=$1&jsoncallback={{callback}}';
  19. handle remainder => sub {
  20. # If the query isn't blank, then use it for the API query.
  21. if (length($_) > 0) {
  22. if ($_ =~ /^(around|in|near) (.+)$/) {
  23. (my $loc = $2) =~ s/^the\sarea$//g;
  24. if (length($loc) > 0) {
  25. return $loc;
  26. }
  27. } else {
  28. return;
  29. }
  30. }
  31. my $location = join(", ", $loc->city, $loc->region_name, $loc->country_name);
  32. return $location;
  33. };
  34. 1;