diff options
author | Matias Linares <matiaslina@gmail.com> | 2019-08-17 19:54:09 -0300 |
---|---|---|
committer | Matias Linares <matiaslina@gmail.com> | 2019-08-17 19:54:09 -0300 |
commit | 5feee914510dd9adfa53dce89b160ee2d0218fc0 (patch) | |
tree | 0bdef8fae4f5ae7cefe6848faf1a789707c78748 /lib/Matrix/Client.pm6 | |
parent | bc6c791c72f9fe460fdb9559522ae154124e8e97 (diff) | |
parent | ec4393cb81952fffa2273e313818a57c9611c5a2 (diff) | |
download | perl6-matrix-client-5feee914510dd9adfa53dce89b160ee2d0218fc0.tar.gz |
Merge branch 'master' into documentation
Diffstat (limited to 'lib/Matrix/Client.pm6')
-rw-r--r-- | lib/Matrix/Client.pm6 | 81 |
1 files changed, 78 insertions, 3 deletions
diff --git a/lib/Matrix/Client.pm6 b/lib/Matrix/Client.pm6 index 2fdbf4b..9022c65 100644 --- a/lib/Matrix/Client.pm6 +++ b/lib/Matrix/Client.pm6 @@ -1,6 +1,6 @@ use HTTP::Request::Common; use URI::Encode; -use JSON::Tiny; +use JSON::Fast; use Matrix::Response; use Matrix::Client::Common; use Matrix::Client::Room; @@ -116,6 +116,31 @@ method whoami { $!user-id } +## Device management + +#| GET - /_matrix/client/r0/devices +method devices(Matrix::Client:D: --> Seq) { + my $data = from-json($.get("/devices").content); + $data<devices>.map(-> $device-data { + Matrix::Response::Device.new(|$device-data) + }) +} + +#| GET - /_matrix/client/r0/devices/{deviceId} +method device(Matrix::Client:D: Str $device-id where *.chars > 0 --> Matrix::Response::Device) { + my $device-data = from-json($.get("/devices/$device-id").content); + Matrix::Response::Device.new(|$device-data) +} + +#| PUT - /_matrix/client/r0/devices/{deviceId} +method update-device(Matrix::Client:D: + Str $device-id where *.chars > 0, + Str $display-name) { + $.put("/devices/$device-id", :display_name($display-name)); +} + +## Presence + #| GET - /_matrix/client/r0/presence/{userId}/status method presence(Matrix::Client:D: $user-id? --> Matrix::Response::Presence) { my $id = $user-id // $.whoami; @@ -202,6 +227,45 @@ method join-room($room-id!) { $.post("/join/$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 + ); +} + +#| POST - /_matrix/client/r0/rooms/{roomId}/unban +method unban(Str $room-id, Str $user-id) { + $.post( + "/rooms/$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 + ) +} + +#| POST - /_matrix/client/r0/rooms/{roomId}/forget +method forget(Str $room-id) { + $.post("/rooms/$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, + :$reason + ); +} + #| POST - /_matrix/client/r0/rooms/{roomId}/leave method leave-room($room-id) { $.post("/rooms/$room-id/leave"); @@ -236,6 +300,17 @@ method send(Str $room-id, Str $body, :$type? = "m.text") { from-json($res.content)<event_id> } +#| PUT - /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId} +method send-event(Str $room-id, Str :$event-type, :$content, :$txn-id? is copy, :$timestamp?) { + unless $txn-id.defined { + $txn-id = $Matrix::Client::Common::TXN-ID++; + } + + my $path = "/rooms/$room-id/send/$event-type/$txn-id"; + my $res = $.put($path, |$content); + from-json($res.content)<event_id> +} + #| GET - /_matrix/client/r0/directory/room/{roomAlias} method get-room-id($room-alias) { my $res = $.get("/directory/room/$room-alias"); @@ -270,10 +345,10 @@ method upload(IO::Path $path, Str $filename?) { # Misc -method run(Int :$sleep = 10, :$sync-filter? --> Supply) { +method run(Int :$sleep = 10, :$sync-filter?, :$start-since? --> Supply) { my $s = Supplier.new; my $supply = $s.Supply; - my $since = ""; + my $since = $start-since // ""; start { loop { |