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->things->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

things

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

    GET /r/$subreddit

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

things_new

Like "things" but sorted by new.

    GET /r/$subreddit/new

things_rising

Like "things" but sorted by rising.

    GET /r/$subreddit/rising

things_top

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

    GET /r/$subreddit/top

things_top_week

Like "things_top" but from the past week.

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

things_top_month

Like "things_top" but from the past month.

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

things_top_year

Like "things_top" but from the past year.

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

things_top_all

Like "things_top" but from all time.

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

things_contro

Like "things" but sorted by controversial.

    GET /r/$subreddit/controversial

things_contro_week

Like "things_contro" but from the past week.

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

things_contro_month

Like "things_contro" but from the past month.

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

things_contro_year

Like "things_contro" but from the past year.

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

things_contro_all

Like "things_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.