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}}) {
    ...
}

7 Comments

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

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:

my $links = $reddit->fetch_links(subreddit => '/r/perl', limit => 10);
foreach my $current_link (@{$links->{items}}) {
    print $current_link->{'title'} ."\n";
}

That generates a whole bunch of warnings before printing the titles:

Field distinguished is missing from package Reddit::Client::Link
 at /usr/local/share/perl/5.12.4/Reddit/Client.pm line 403

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

Leave a comment

About Jeff Ober

user-pic I am a software developer for Cox Media Group, writing Python for cash and Perl for fun.