From cfdeb20447fc101c0c00580313c1731cb64e34f0 Mon Sep 17 00:00:00 2001 From: Martin McGrath Date: Thu, 28 Sep 2017 15:53:18 +0100 Subject: [PATCH 1/2] Add new API methods, alter some docs --- lib/WebService/HackerNews.pm | 84 +++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 2 deletions(-) diff --git a/lib/WebService/HackerNews.pm b/lib/WebService/HackerNews.pm index 685b987..bdab8f0 100644 --- a/lib/WebService/HackerNews.pm +++ b/lib/WebService/HackerNews.pm @@ -43,6 +43,46 @@ sub top_story_ids return @$result; } +sub best_story_ids +{ + my $self = shift; + my $result = $self->$get('beststories.json'); + + return @$result; +} + +sub new_story_ids +{ + my $self = shift; + my $result = $self->$get('newstories.json'); + + return @$result; +} + +sub ask_story_ids +{ + my $self = shift; + my $result = $self->$get('askstories.json'); + + return @$result; +} + +sub show_story_ids +{ + my $self = shift; + my $result = $self->$get('showstories.json'); + + return @$result; +} + +sub job_story_ids +{ + my $self = shift; + my $result = $self->$get('jobstories.json'); + + return @$result; +} + sub item { my $self = shift; @@ -86,8 +126,8 @@ WebService::HackerNews - interface to the official HackerNews API use WebService::HackerNews; my $hn = WebService::HackerNews->new; - my @top100 = $hn->top_story_ids; - my $item = $hn->item( $top100[0] ); + my @top500 = $hn->top_story_ids; + my $item = $hn->item( $top500[0] ); my $user = $hn->user($item->by); printf qq{"%s" by %s (karma: %d)\n}, @@ -136,6 +176,46 @@ Returns a list of ids for the current top 100 stories. You can then call C to get the details for specific items. +=head2 best_story_ids + +Returns a list of ids for the current top 500 best stories. + + my @ids = $hn->best_story_ids; + +You can then call C to get the details for specific items. + +=head2 new_story_ids + +Returns a list of ids for the current top 500 new stories. + + my @ids = $hn->new_story_ids; + +You can then call C to get the details for specific items. + +=head2 ask_story_ids + +Returns a list of ids for the top 200 latest 'Ask hacker news' stories. + + my @ids = $hn->ask_story_ids; + +You can then call C to get the details for specific items. + +=head2 show_story_ids + +Returns a list of ids for the 200 latest 'Show Hacker news' stories. + + my @ids = $hn->show_story_ids + +You can then call C to get the details for specific items. + +=head2 jobs_story_ids + +Return a list of ids for the 200 latest 'Jobs' stories. + + my @ids = $hn->jobs_Story_ids + +You can then call C to get the details for specific items. + =head2 item($ID) Takes an item id and returns an instance of L, From c4c1aa668d170f35fa26f3518750fbc74450edb2 Mon Sep 17 00:00:00 2001 From: Martin McGrath Date: Thu, 28 Sep 2017 16:43:20 +0100 Subject: [PATCH 2/2] Minor documentation fix --- lib/WebService/HackerNews.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/WebService/HackerNews.pm b/lib/WebService/HackerNews.pm index bdab8f0..4c5161c 100644 --- a/lib/WebService/HackerNews.pm +++ b/lib/WebService/HackerNews.pm @@ -170,7 +170,7 @@ listed in the official documentation for the API. =head2 top_story_ids -Returns a list of ids for the current top 100 stories. +Returns a list of ids for the current top 500 stories. my @ids = $hn->top_story_ids;