Skip to content

Instantly share code, notes, and snippets.

@Akron
Created June 2, 2012 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akron/2858370 to your computer and use it in GitHub Desktop.
Save Akron/2858370 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use Mojo;
use Mojo::Base -strict;
my $ua = Mojo::UserAgent->new;
$ua->max_redirects(5);
my $domain = 'http://api.powerhousemuseum.com';
my $base_url ="$domain/api/v1/category/xml/";
my $api_key = '8fbb61ea34d6f5d';
# Create url
my $base_rest_url = Mojo::URL->new($base_url)->query({ api_key => $api_key});
# Request the resource.
my $dom = $ua->get($base_rest_url)->res->dom;
my @categories;
# Get the elements out of the dom
$dom->find('categories > category')->each(
sub {
my $elem = shift;
my %hash;
foreach (qw/name num_items items_uri/) {
$hash{$_} = $elem->at($_)->text;
};
push(@categories, \%hash);
}
);
print "<table>\n";
foreach my $cat (@categories) {
print '<a href="', $domain, $cat->{items_uri}, '">', $cat->{name}, '</a>';
print $cat->{num_items}, "\n";
}
print "<table>\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment