From 4b69cf6345341d71626b0aad91a91ab7debfbd7c Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sat, 4 Aug 2018 18:55:50 -0300 Subject: Add state endpoints --- lib/Matrix/Client/Room.pm6 | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'lib/Matrix/Client') diff --git a/lib/Matrix/Client/Room.pm6 b/lib/Matrix/Client/Room.pm6 index 3e104bf..d8a9848 100644 --- a/lib/Matrix/Client/Room.pm6 +++ b/lib/Matrix/Client/Room.pm6 @@ -1,6 +1,7 @@ use JSON::Tiny; use Matrix::Client::Common; use Matrix::Client::Requester; +use Matrix::Response; unit class Matrix::Client::Room does Matrix::Client::Requester; @@ -38,12 +39,29 @@ method send(Str $body!, Str :$type? = "m.text") { from-json($res.content) } -method leave() { - $.post('/leave') +multi method state(--> Seq) { + my $data = from-json($.get('/state').content); + + gather for $data.List -> $event { + take Matrix::Response::StateEvent.new(:room-id($.id), |$event) + } } -method gist(--> Str) { - "Room" +multi method state(Str $event-type) { + from-json($.get("/state/$event-type").content) +} + +method send-state(Str:D $event-type, :$state-key = "", *%args --> Str) { + my $res = $.put( + "/state/$event-type/$state-key", + |%args + ); + from-json($res.content) +} + + +method leave() { + $.post('/leave') } method Str(--> Str) { -- cgit v1.2.3-70-g09d2