May 2012 Archives

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

About Jeff Ober

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