Skip to content

Instantly share code, notes, and snippets.

@cabrinha
Created April 3, 2015 18:33
Show Gist options
  • Save cabrinha/890fdde62fd1978c3d12 to your computer and use it in GitHub Desktop.
Save cabrinha/890fdde62fd1978c3d12 to your computer and use it in GitHub Desktop.
sub => ud
use Mojo::URL;
use Mojo::UserAgent;
my $term = 'wtf';
my $url = Mojo::URL->new('http://api.urbandictionary.com/v0/define')->query(term => $term);
my $tx = Mojo::UserAgent->new->get($url);
if ($tx->success) {
my $results = $tx->res->json;
my $definitions = $results->{list};
foreach my $definition (@$definitions) {
print $definition->{definition}, "\n";
}
} else {
my $err = $tx->error;
die "$err->{code} response: $err->{message}" if $err->{code};
die "Connection error: $err->{message}";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment