Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for new HN API methods #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 83 additions & 3 deletions lib/WebService/HackerNews.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -130,12 +170,52 @@ 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;

You can then call C<item()> 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<item()> 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<item()> 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<item()> 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<item()> 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<item()> to get the details for specific items.

=head2 item($ID)

Takes an item id and returns an instance of L<WebService::HackerNews::Item>,
Expand Down