diff options
author | Matias Linares <matiaslina@gmail.com> | 2018-08-04 18:55:50 -0300 |
---|---|---|
committer | Matias Linares <matiaslina@gmail.com> | 2018-08-04 18:55:50 -0300 |
commit | 4b69cf6345341d71626b0aad91a91ab7debfbd7c (patch) | |
tree | 5234f3740060a3caf285b739efd7fd3de164d768 | |
parent | 40c0f046ff26ea19a1a5da4ade65d3d0fa93795a (diff) | |
download | perl6-matrix-client-4b69cf6345341d71626b0aad91a91ab7debfbd7c.tar.gz |
Add state endpoints
-rw-r--r-- | lib/Matrix/Client/Room.pm6 | 26 |
1 files changed, 22 insertions, 4 deletions
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)<event_id> } -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<id: {self.id}>" +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)<event_id> +} + + +method leave() { + $.post('/leave') } method Str(--> Str) { |