AnyEvent-Mattermost
view release on metacpan or search on metacpan
lib/AnyEvent/Mattermost.pm view on Meta::CPAN
beyond authentication and simple message receiving and sending. Feature parity
with SlackRTM support is a definite goal, and then beyond that it would be nice
to support all the stable Mattermost API features. Baby steps.
=head1 METHODS
=cut
=head2 new
$mconn = AnyEvent::Mattermost->new( $host, $team, $email, $password );
Creates a new AnyEvent::Mattermost object. No connections are opened and no
callbacks are registered yet.
The C<$host> parameter must be the HTTP/HTTPS URL of your Mattermost server. If
you omit the scheme and provide only a hostname, HTTPS will be assumed. Note
that Mattermost servers configured over HTTP will also use unencrypted C<ws://>
for the persistent WebSockets connection for receiving incoming messages. You
should use HTTPS unless there is no other choice.
C<$team> must be the Mattermost team's short name (the version which appears in
the URLs when connected through the web client).
C<$email> must be the email address of the account to be used for logging into
the Mattermost server. The short username is not supported for logins via the
Mattermost APIs, only the email address.
C<$password> is hopefully self-explanatory.
=cut
sub new {
my ($class, $host, $team, $user, $pass) = @_;
croak "must provide a Mattermost server address"
unless defined $host && length($host) > 0;
croak "must provide a Mattermost team name"
unless defined $team && length($team) > 0;
croak "must provide a login email and password"
unless defined $user && defined $pass && length($user) > 0 && length($pass) > 0;
$host = "https://$host" unless $host =~ m{^https?://}i;
$host .= '/' unless substr($host, -1, 1) eq '/';
return bless {
furl => Furl->new( agent => "AnyEvent::Mattermost" ),
host => $host,
team => $team,
user => $user,
lib/AnyEvent/Mattermost.pm view on Meta::CPAN
Any errors encountered will croak() and the connection will be aborted.
=cut
sub start {
my ($self) = @_;
my $data = $self->_post('api/v3/users/login', {
name => $self->{'team'},
login_id => $self->{'user'},
password => $self->{'pass'},
});
croak "could not log in" unless exists $self->{'token'};
my $userdata = $self->_get('api/v3/users/initial_load');
croak "did not receive valid initial_load user data"
unless exists $userdata->{'user'}
&& ref($userdata->{'user'}) eq 'HASH'
&& exists $userdata->{'user'}{'id'};
( run in 0.943 second using v1.01-cache-2.11-cpan-49f99fa48dc )