Skip to content

Instantly share code, notes, and snippets.

@yusukebe
Created August 7, 2009 19:09
Show Gist options
  • Select an option

  • Save yusukebe/164111 to your computer and use it in GitHub Desktop.

Select an option

Save yusukebe/164111 to your computer and use it in GitHub Desktop.
sub bitly {
my $self = shift;
my $url = $self->url;
my $api_url =
"http://api.bit.ly/shorten?version=2.0.1&format=xml&login=xxx&apiKey=xxx&longUrl=$url";
my $ua = LWP::UserAgent->new();
my $res = $ua->get($api_url);
if ( $res->content =~ m!<shortUrl>(.+?)</shortUrl>! ) {
return $1;
}
else {
return $url;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment