Mastodon-Client
view release on metacpan or search on metacpan
lib/Mastodon/Client.pm view on Meta::CPAN
'q' => $query,
%{$params},
};
return $self->get( 'search', $params );
}
sub search_accounts {
my $self = shift;
state $check = compile( Str, Optional [HashRef] );
my ($query, $params) = $check->(@_);
$params //= {};
$params = {
'q' => $query,
%{$params},
};
return $self->get( 'accounts/search', $params );
}
sub stream {
my $self = shift;
state $check = compile( NonEmptyStr );
my ($query) = $check->(@_);
my $endpoint
= $self->instance->uri
. '/api/v'
. $self->api_version
. '/streaming/'
. (( $query =~ /^#/ )
? ( 'hashtag?' . $query )
: $query
);
use Mastodon::Listener;
return Mastodon::Listener->new(
url => $endpoint,
access_token => $self->access_token,
coerce_entities => $self->coerce_entities,
);
}
sub timeline {
my $self = shift;
state $check = compile( NonEmptyStr, Optional [HashRef] );
my ($query, $params) = $check->(@_);
my $endpoint
= ( $query =~ /^#/ )
? 'timelines/tag/' . $query
: 'timelines/' . $query;
return $self->get($endpoint, $params);
}
sub update_account {
my $self = shift;
state $check = compile(
slurpy Dict [
display_name => Optional [Str],
note => Optional [Str],
avatar => Optional [Image],
header => Optional [Image],
]
);
my ($data) = $check->(@_);
return $self->patch( 'accounts/update_credentials' => $data );
}
sub upload_media {
my $self = shift;
state $check = compile(
File->plus_coercions( Str, sub { Path::Tiny::path($_) } ),
Optional [ Dict[
description => Optional[Str],
focus => Optional[Tuple[StrictNum, StrictNum]],
]]
);
my ($file, $params) = $check->(@_);
$params //= {};
if (exists $params->{focus}) {
my ($x,$y) = @{$params->{focus}};
if ($x >= -1 && $x <= 1 && $y >= -1 && $y <= 1) {
$params->{focus} = "$x,$y";
} else {
delete $params->{focus};
}
}
return $self->post( 'media' =>
{ file => [ $file, undef ], %$params },
headers => { Content_Type => 'form-data' },
);
}
# POST requests with no data and a mandatory ID number
foreach my $pair ([
[ statuses => [qw( reblog unreblog favourite unfavourite )] ],
[ accounts => [qw( mute unmute block unblock follow unfollow )] ],
]) {
my ($base, $endpoints) = @{$pair};
foreach my $endpoint (@{$endpoints}) {
my $method = ($base eq 'statuses') ? $endpoint . '_status' : $endpoint;
no strict 'refs';
*{ __PACKAGE__ . '::' . $method } = sub {
my $self = shift;
state $check = compile( Int );
my ($id) = $check->(@_);
return $self->post( "$base/$id/$endpoint" );
( run in 0.550 second using v1.01-cache-2.11-cpan-2398b32b56e )