NAME

Mojo::Snoo::Subreddit - Mojo wrapper for Reddit Subreddits

SYNOPSIS

use Mojo::Snoo::Subreddit;

# OAuth ONLY. Reddit is deprecating cookie auth soon.
my $snoo = Mojo::Snoo::Subreddit->new(
    name          => 'perl',
    username      => 'foobar',
    password      => 'very_secret',
    client_id     => 'oauth_client_id',
    client_secret => 'very_secret_oauth',
);

# print each title from /r/perl post
# (OAuth not required for this action)
$snoo->links->each(sub { say $_->title });

ATTRIBUTES

name

The name of the subreddit. This is required for object instantiation. The constructor can accept a single string value or key/value pairs. Examples:

Mojo::Snoo::Subreddit->new('perl')->name;
Mojo::Snoo::Subreddit->new(name => 'perl')->name;

about

Returns the About section of a subreddit.

GET /r/$subreddit/about

Returns a monkey-patched object containing all of the keys under the JSON's "data" key. Example:

my $about = Mojo::Snoo::Subreddit->new('perl')->about;

say $about-title;
say $about->description;
say $about->description_html;

mods

Returns a list of the subreddit's moderators.

GET /r/$subreddit/about/moderators

Returns a Mojo::Collection object containing a list of monkey-patched objects. Example:

Mojo::Snoo::Subreddit->new('perl')->mods->each(
    sub {
        say $_->id;
        say $_->name;
        say $_->date;
        say $_->mod_permissions;
    }
);

METHODS

Returns a Mojo::Collection object containing a list of Mojo::Snoo::Link objects.

GET /r/$subreddit

Accepts one argument which indicates the maximum number of Links (reddit API's limit parameter). Default is 25, max is 100.

Like "links" but sorted by new.

GET /r/$subreddit/new

Like "links" but sorted by rising.

GET /r/$subreddit/rising

Like "links" but sorted by top (most upvoted).

GET /r/$subreddit/top

Like "links_top" but from the past week.

GET /r/$subreddit/top?t=week

Like "links_top" but from the past month.

GET /r/$subreddit/top?t=month

Like "links_top" but from the past year.

GET /r/$subreddit/top?t=year

Like "links_top" but from all time.

GET /r/$subreddit/top?t=all

Like "links" but sorted by controversial.

GET /r/$subreddit/controversial

Like "links_contro" but from the past week.

GET /r/$subreddit/controversial?t=week

Like "links_contro" but from the past month.

GET /r/$subreddit/controversial?t=month

Like "links_contro" but from the past year.

GET /r/$subreddit/controversial?t=year

Like "links_contro" but from all time.

GET /r/$subreddit/controversial?t=all

API DOCUMENTATION

Please see the official Reddit API documentation for more details regarding the usage of endpoints. For a better idea of how OAuth works, see the Quick Start and the full documentation. There is also a lot of useful information of the redditdev subreddit.

LICENSE

The (two-clause) FreeBSD License. See LICENSE for details.