aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@gmail.com>2018-08-08 22:45:01 -0300
committerMatias Linares <matiaslina@gmail.com>2018-08-08 22:45:01 -0300
commit89c178e90786f668c15506f7e52206214ac29ed6 (patch)
treef2d81049d8d1346cb013baf152513e20cc75e8b0
parente69b990cf4ac80adac0496d988717b49f41547d0 (diff)
downloadperl6-matrix-client-89c178e90786f668c15506f7e52206214ac29ed6.tar.gz
Add /directory/room/<alias> endpoints
This allows work with the discoverability of the aliases for the rooms. The next step is allow the client to send a message, join, etc, a room with the room alias like #8 and #14
-rw-r--r--lib/Matrix/Client.pm615
-rw-r--r--t/20-client.t35
2 files changed, 49 insertions, 1 deletions
diff --git a/lib/Matrix/Client.pm6 b/lib/Matrix/Client.pm6
index 1e080bd..5f52779 100644
--- a/lib/Matrix/Client.pm6
+++ b/lib/Matrix/Client.pm6
@@ -197,6 +197,21 @@ method send(Str $room-id, Str $body, :$type? = "m.text") {
from-json($res.content)<event_id>
}
+method get-room-id($room-alias) {
+ my $res = $.get("/directory/room/$room-alias");
+
+ from-json($res.content)<room_id>
+}
+
+method add-room-alias($room-id, $room-alias) {
+ $.put("/directory/room/$room-alias",
+ room_id => $room-id);
+}
+
+method remove-room-alias($room-alias) {
+ $.delete("/directory/room/$room-alias");
+}
+
# Media
method upload(IO::Path $path, Str $filename?) {
diff --git a/t/20-client.t b/t/20-client.t
index 3fd6739..2215a6b 100644
--- a/t/20-client.t
+++ b/t/20-client.t
@@ -1,7 +1,7 @@
use lib 'lib';
use Test;
use Matrix::Client;
-plan 4;
+plan 5;
unless %*ENV<MATRIX_CLIENT_TEST_SERVER> {
skip-rest 'No test server setted';
@@ -62,3 +62,36 @@ subtest 'sync' => {
isa-ok $client.sync(:sync-filter(room => timeline => limit => 1)),
Matrix::Response::Sync, 'sync wit Hash sync-filter';
}
+
+subtest 'directory' => {
+ plan 6;
+ my $alias = '#testing:localhost';
+ my $test-room = $client.create-room;
+
+ throws-like {
+ $client.get-room-id($alias);
+ }, X::Matrix::Response,
+ message => /M_NOT_FOUND/,
+ "raises with unknown alias";
+
+ lives-ok {
+ $client.add-room-alias($test-room.id, $alias)
+ }, 'can add an alias to the room';
+
+ lives-ok {
+ $client.get-room-id($alias);
+ }, 'can retrieve room with an alias';
+
+ is $client.get-room-id($alias), $test-room.id,
+ 'good room when retrieve';
+
+ lives-ok {
+ $client.remove-room-alias($alias);
+ }, 'can remove the alias';
+
+ throws-like {
+ $client.get-room-id($alias);
+ }, X::Matrix::Response,
+ message => /M_NOT_FOUND/,
+ "Room not found after delete";
+}