NAME

Mastodon::Client - Talk to a Mastodon server

SYNOPSIS

use Mastodon::Client;

my $client = Mastodon::Client->new(
  instance        => 'mastodon.social',
  name            => 'PerlBot',
  client_id       => $client_id,
  client_secret   => $client_secret,
  access_token    => $access_token,
  coerce_entities => 1,
);

$client->post_status('Posted to a Mastodon server!');
$client->post_status('And now in secret...',
  { visibility => 'unlisted' }
)

# Streaming interface might change!
my $listener = $client->stream( 'public' );
$listener->on( update => sub {
  my ($listener, $status) = @_;
  printf "%s said: %s\n",
    $status->account->display_name,
    $status->content;
});
$listener->start;

DESCRIPTION

Mastodon::Client lets you talk to a Mastodon server to obtain authentication credentials, read posts from timelines in both static or streaming mode, and perform all the other operations exposed by the Mastodon API.

Most of these are available through the convenience methods listed below, which validate input parameters and are likely to provide more meaningful feedback in case of errors.

Alternatively, this distribution can be used via the low-level request methods (post, get, etc), which allow direct access to the API endpoints. All other methods call one of these at some point.

VERSION NOTICE

This distribution currently only supports version 1 of the Mastodon API.

Help implementing support for any missing features in version 1, and for the new features in version 2, would be greatfully appreciated.

ATTRIBUTES

METHODS

Authorizing an application

Although not all of the API methods require authentication to be used, most of them do. The authentication process involves a) registering an application with a Mastodon server to obtain a client secret and ID; b) authorizing the application by either providing a user's credentials, or by using an authentication URL.

The methods facilitating this process are detailed below:

Error handling

Methods that make requests to the server will die whenever an error is encountered, or the data that was received from the server is not what is expected. The error string will, when possible, come from the response's status line, but this will likely not be enough to fully diagnose what went wrong.

The remaining methods listed here follow the order of those in the official API documentation.

Accounts

Blocks

Favourites

Follow requests

Follows

Instances

Media

Mutes

Notifications

Reports

Statuses

Timelines

STREAMING RESULTS

Alternatively, it is possible to use the streaming API to get a constant stream of updates. To do this, there is the stream() method.

REQUEST METHODS

Mastodon::Client uses four lower-level request methods to contact the API with GET, POST, PATCH, and DELETE requests. These are left available in case one of the higher-level convenience methods are unsuitable or undesirable, but you use them at your own risk.

They all take a URL as their first parameter, which can be a string with the API endpoint to contact, or a URI object, which will be used as-is.

If passed as a string, the methods expect one that contains only the variable parts of the endpoint (ie. not including the HOST/api/v1 part). The remaining parts will be filled-in appropriately internally.

CONTRIBUTIONS AND BUG REPORTS

Contributions of any kind are most welcome!

The main repository for this distribution is on GitLab, which is where patches and bug reports are mainly tracked. The repository is also mirrored on Github, in case that platform makes it easier to post contributions.

If none of the above is acceptable, bug reports can also be sent through the CPAN RT system, or by mail directly to the developers at the address below, although these will not be as closely tracked.

AUTHOR

CONTRIBUTORS

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by José Joaquín Atria.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.