aboutsummaryrefslogtreecommitdiff
path: root/lib/Matrix/Client.rakumod
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Matrix/Client.rakumod')
-rw-r--r--lib/Matrix/Client.rakumod40
1 files changed, 17 insertions, 23 deletions
diff --git a/lib/Matrix/Client.rakumod b/lib/Matrix/Client.rakumod
index 01babe5..0c801d6 100644
--- a/lib/Matrix/Client.rakumod
+++ b/lib/Matrix/Client.rakumod
@@ -199,6 +199,15 @@ multi method sync(:$since = "") {
# Rooms
+#| Helper method to get a Matrix::Client::Room instance
+method room(Str $room-id --> Matrix::Client::Room) {
+ Matrix::Client::Room.new(
+ id => $room-id,
+ access-token => self.access-token,
+ home-server => self.home-server
+ )
+}
+
#| POST - /_matrix/client/r0/createRoom
method create-room(
Bool :$public = False,
@@ -216,11 +225,7 @@ method create-room(
my $res = from-json($.post('/createRoom', |%params).content);
- Matrix::Client::Room.new(
- id => $res<room_id>,
- access-token => self.access-token,
- home-server => self.home-server
- )
+ $.room($res<room_id>)
}
#| POST - /_matrix/client/r0/join/{roomIdOrAlias}
@@ -230,46 +235,35 @@ method join-room($room-id!) {
#| POST - /_matrix/client/r0/rooms/{roomId}/ban
method ban(Str $room-id, Str $user-id, $reason = "") {
- $.post(
- "/rooms/$room-id/ban",
- :$user-id,
- :$reason
- );
+ $.room($room-id).ban($user-id, :$reason)
}
#| POST - /_matrix/client/r0/rooms/{roomId}/unban
method unban(Str $room-id, Str $user-id) {
- $.post(
- "/rooms/$room-id/unban",
- :$user-id
- );
+ $.room($room-id).unban($user-id)
}
#| POST - /_matrix/client/r0/rooms/{roomId}/invite
method invite(Str $room-id, Str $user-id) {
- $.post(
- "/rooms/$room-id/invite",
- :$user-id
- )
+ $.room($room-id).invite($user-id)
}
#| POST - /_matrix/client/r0/rooms/{roomId}/forget
method forget(Str $room-id) {
- $.post("/rooms/$room-id/forget")
+ $.room($room-id).forget()
}
#| POST - /_matrix/client/r0/rooms/{roomId}/kick
method kick(Str $room-id, Str $user-id, $reason = "") {
- $.post(
- "/rooms/$room-id/kick",
- :$user-id,
+ $.room($room-id).kick(
+ $user-id,
:$reason
);
}
#| POST - /_matrix/client/r0/rooms/{roomId}/leave
method leave-room($room-id) {
- $.post("/rooms/$room-id/leave");
+ $.room($room-id).leave
}
#| GET - /_matrix/client/r0/joined_rooms