The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

WebService::Gitter - An interface to Gitter REST API via Perl 5.

VERSION

version 0.4.0

SYNOPSIS

use WebService::Gitter;

my $client = WebService::Gitter->new(token_pass => 'my_api_or_token_key');

$client->current_user;
$client->rooms;
$client->room_id('gitterHQ/nodejs');
$client->room_users('the_user_id');
$client->send_message('my_text', 'room_id');
$client->nessages('room_id', limit_messages_in_number);

DESCRIPTION

An interface to Gitter REST API (v1). The methods will return a parsed JSON into hash.. That is up to your freedom on specifically accessing each element in the hash.

To access specific element in the JSON hash, for example:

$client->current_user->{'id'};

NOTE You need to include 'use Data::Dumper' in your script to print the whole hash map.

METHODS

new(token_pass => $api_key)

You need to be registered at Gitter to get an api key. Take a look at https://developer.gitter.im/login for further information.

current_user

This will return the authenticated user (you) info in decoded JSON. To see the response data, you can:

print Dumper $obj->current_user

and it will print the returned HASH map.

rooms

This will return the joined rooms by authenticated user (you) info in JSON through HASH. To see the response data, you can:

print Dumper $obj->rooms;

and it will print the returned HASH map.

room_id($room_name)

$room_name arguments is the room name, eg FreecodeCamp/FreeCodeCamp.

This method will return the room ID of the specified room name in JSON through HASH. To see the response data, you can:

print Dumper $obj->room_id($room_uri);

and it will print the returned HASH map.

room_users($room_id)

$room_id is the room ID. You can get this by running the "room_id($room_uri)" method.

This method will return the users in the specified room in JSON through HASH. To see the response data, you can:

print Dumper $obj->room_users($room_id);

and it will print the returned HASH map.

send_message($text, $room_id)

$text is your text message, eg 'HI!'. $room_id is the room ID you want to send message to. You can get the room ID by running:

print Dumper $obj->room_id($room_name/uri);

This method will send the message to the specified room through the room ID. To see the response data, you can:

print Dumper $obj->send_message($text, $room_id);

and it will print the returned HASH map.

messages($room_id, $limit_number)

$room_id is your room targeted room ID. To find the room ID, you can run:

print Dumper $obj->room_id($room_name);

The $limit_number is your total messages to be retrieved.

This method will retrieve messages from targeted room. To see the respose data, you can run:

print Dumper $obj->messages($room_id, $limit_number);

SEE ALSO

LWP::UserAgent

Data::Dumper

JSON::MaybeXS

Gitter API Wiki for developer page

AUTHOR

faraco <skelic3@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by faraco.

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