The Hacker News API

APIs Thu 9 October 2014

I've released a first lash-up of WebService::HackerNews, an interface to the Hacker News API, which was announced earlier this week. OALDERS asked who was going to write a Perl wrapper, and by this evening no-one had.

It really is a first hack: no error checking and no tests, but the following simple example will show you information about the story that's currently top on Hacker News:

use WebService::HackerNews;
my $hn   = WebService::HackerNews->new();

my @top  = $hn->top_story_ids();    # get IDs of top 100 stories
my $item = $hn->item($top[0]);      # Get detail of top story
my $user = $hn->user($item->by);    # Get detail of user who posted it

printf qq{"%s" by %s (karma: %d)\n},
       $item->title, $item->by, $user->karma;

I don't have a need for the API — it was something fun to do on the sofa while watching TV. It's on github, so hack away and send pull requests.

comments powered by Disqus