Reddit API for Perl
I have completed the meat of a reasonably complete API wrapper for Reddit. You can grab it at https://github.com/jsober/Reddit-API.
It is pretty simple to use, and the docs are complete, but here is the gist:
use Reddit::API;
my $session_file = '~/.reddit';
my $reddit = Reddit::API->new(session_file => $session_file);
unless ($reddit->is_logged_in) {
$reddit->login('someone', 'secret');
$reddit->save_session();
}
$reddit->submit_link(
subreddit => 'perl',
title => 'Perl is still alive!',
url => 'http://www.perl.org'
);
my $links = $reddit->fetch_links(subreddit => '/r/perl', limit => 10);
foreach (@{$links->{items}}) {
...
}
Consider renaming to WebService::Reddit instead. The use of API in the module name is discouraged: https://pause.perl.org/pause/query?ACTION=pause_namingmodules#Avoid_API_Interface_and_the_like
Reddit::API has been renamed to Reddit::Client. Thank you for the suggestion.
The use of new top-level namespaces is also discouraged when existing ones will suffice: https://pause.perl.org/pause/query?ACTION=pause_namingmodules#Top_level_namespaces . That's why I suggested using WebService.
I'm a little confused as to how you are supposed to interact with retrieved links:
That generates a whole bunch of warnings before printing the titles:
Am I doing it wrong?
Also, installation from cpan consistently fails, FYI. :)
Any idea how i can get around this ?
Attempt to access disallowed key 'over_18' in a restricted hash at /usr/local/lib/perl5/site_perl/5.10.1/Reddit/Client/Thing.pm line 56.
i've tried setting
use fields qw/over_18/;
with no success .. I blindly tried that without really understanding what it does ( sorry about that )
Thanks
and thank you for the doc