<commit_before>package Mojo::Snoo::Thing;
use Moo;

extends 'Mojo::Snoo::Base';

use Mojo::Collection;
use Mojo::Snoo::Comment;

use constant FIELD => 'name';

has [qw( id name title subreddit )] => (is => 'ro');

sub BUILDARGS { shift->SUPER::BUILDARGS(@_ == 1 ? (name => shift) : @_) }

sub _get_comments {
    my ($self, $sort) = @_;

    my $path = '/r/' . $self->subreddit . '/comments/' . $self->id;

    #$path .= "/$sort" if $sort;

    my %params;
    $params{sort} = $sort if $sort;

    my $json = $self->_do_request('GET', $path, %params);

    my @children =
      map { $_->{kind} eq 't1' ? $_->{data} : () }
      map { @{$_->{data}{children}} } @$json;

    my %args = map { $_ => $self->$_ } (qw(
        username
        password
        client_id
        client_secret
    ));
    my @things = map Mojo::Snoo::Comment->new(%args, %$_), @children;
    Mojo::Collection->new(@things);
}

sub _vote {
    my ($self, $direction) = @_;

    my %params = (
        dir => $direction,
	id => $self->name,
    );

    $self->_do_request('POST', '/api/vote', %params);
}

# comments_hot
# comments_new
# comments_top('
# $thing->comments($sort);
# defaults to comments_hot?
# TODO pass params:
# http://www.reddit.com/dev/api#GET_comments_{article}
sub comments { shift->_get_comments }

sub upvote   { shift->_vote(1)  }
sub downvote { shift->_vote(-1) }
sub unvote   { shift->_vote(0)  }

# TODO support category (gold accounts only)
sub save {
    my $self = shift;
    $self->_do_request('POST', '/api/save', id => $self->name);
}

# TODO support category (gold accounts only)
sub unsave {
    my $self = shift;
    $self->_do_request('POST', '/api/unsave', id => $self->name);
}

1;

__END__<commit_msg>pass arguments to Thing's _get_comments<commit_after>package Mojo::Snoo::Thing;
use Moo;

extends 'Mojo::Snoo::Base';

use Mojo::Collection;
use Mojo::Snoo::Comment;

use constant FIELD => 'name';

has [qw( id name title subreddit )] => (is => 'ro');

sub BUILDARGS { shift->SUPER::BUILDARGS(@_ == 1 ? (name => shift) : @_) }

sub _get_comments {
    my ($self, $sort) = @_;

    my $path = '/r/' . $self->subreddit . '/comments/' . $self->id;

    #$path .= "/$sort" if $sort;

    my %params;
    $params{sort} = $sort if $sort;

    my $json = $self->_do_request('GET', $path, %params);

    my @children =
      map { $_->{kind} eq 't1' ? $_->{data} : () }
      map { @{$_->{data}{children}} } @$json;

    my %args = map { $_ => $self->$_ } (qw(
        username
        password
        client_id
        client_secret
    ));
    my @things = map Mojo::Snoo::Comment->new(%args, %$_), @children;
    Mojo::Collection->new(@things);
}

sub _vote {
    my ($self, $direction) = @_;

    my %params = (
        dir => $direction,
	id => $self->name,
    );

    $self->_do_request('POST', '/api/vote', %params);
}

# comments_hot
# comments_new
# comments_top('
# $thing->comments($sort);
# defaults to comments_hot?
# TODO pass params:
# http://www.reddit.com/dev/api#GET_comments_{article}
sub comments { shift->_get_comments(@_) }

sub upvote   { shift->_vote(1)  }
sub downvote { shift->_vote(-1) }
sub unvote   { shift->_vote(0)  }

# TODO support category (gold accounts only)
sub save {
    my $self = shift;
    $self->_do_request('POST', '/api/save', id => $self->name);
}

# TODO support category (gold accounts only)
sub unsave {
    my $self = shift;
    $self->_do_request('POST', '/api/unsave', id => $self->name);
}

1;

__END__
{'fraction_non_alphanumeric': 0.20023081361800346, 'fraction_numerical': 0.003462204270051933, 'mean_word_length': 3.122473246135553, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6922391', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1262, 'n_words': 299}