PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/DDG/Spice/Bitly.pm

https://github.com/aembleton/zeroclickinfo-spice
Perl | 35 lines | 28 code | 6 blank | 1 comment | 3 complexity | 7bce790fe3be9b50a4c80335f7e1b80a MD5 | raw file
  1. package DDG::Spice::Bitly;
  2. # ABSTRACT: Return a shortened version of a URL using the bitly API.
  3. use DDG::Spice;
  4. primary_example_queries "bitly http://www.duckduckgo.com/about.html";
  5. secondary_example_queries "shorten http://www.duckduckgo.com/goodies", "url shorten www.github.com/explore";
  6. description "Shorten URLs using the bitly API";
  7. name "Bitly";
  8. icon_url "/i/bitly.com.ico";
  9. source "Bitly";
  10. code_url "https://github.com/duckduckgo/zeroclickinfo-spice/blob/master/lib/DDG/Spice/Bitly.pm";
  11. topics "social";
  12. category "computing_tools";
  13. attribution github => ['https://github.com/danjarvis','Dan Jarvis'],
  14. twitter => ['http://twitter.com/danjarvis','danjarvis'];
  15. spice to => 'http://api.bitly.com/v3/shorten?login=duckduckhack&apiKey={{ENV{DDG_SPICE_BITLY_APIKEY}}}&longUrl=$1://$2&callback={{callback}}';
  16. spice from => '(?:([^/]+)/(.+))';
  17. triggers any => 'bitly', 'bit.ly', 'shorten', 'shorten url', 'short url', 'url shorten';
  18. handle remainder => sub {
  19. my ($longUri) = shift;
  20. if ($longUri) {
  21. if($longUri =~ /(.+):\/\/(.+)/) {
  22. return $1, $2;
  23. } else {
  24. return 'http', $longUri;
  25. }
  26. }
  27. return;
  28. };
  29. 1;