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