Skip to content

Instantly share code, notes, and snippets.

@bobtfish
Created May 2, 2010 19:48
Show Gist options
  • Select an option

  • Save bobtfish/387384 to your computer and use it in GitHub Desktop.

Select an option

Save bobtfish/387384 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
#
use LWP::UserAgent;
use JSON 2.07;
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
my $url = "http://bit.ly/1TU8wN";
my $shorty = "http://www.longurlplease.com/api/v1.1?q=$url";
$response = $ua->get($shorty );
if ($response->is_success) {
my $whee = eval { decode_json( $response->decoded_content ) };
die("Invalid JSON returned. Error was: $@ Content was " . $response->decoded_content) if $@;
print $whee->{$url};
}
else {
die $response->status_line;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment