diff options
-rw-r--r-- | lib/Matrix/Client.pm6 | 27 | ||||
-rw-r--r-- | lib/Matrix/Client/Room.pm6 | 7 |
2 files changed, 33 insertions, 1 deletions
diff --git a/lib/Matrix/Client.pm6 b/lib/Matrix/Client.pm6 index bf3935c..2fdbf4b 100644 --- a/lib/Matrix/Client.pm6 +++ b/lib/Matrix/Client.pm6 @@ -17,11 +17,12 @@ submethod TWEAK { $Matrix::Client::Common::TXN-ID = now.Int; } - +#| POST - /_matrix/client/r0/login multi method login(Str $username, Str $password) { $.login(:$username, :$password); } +#| POST - /_matrix/client/r0/login multi method login(Str :$username, Str :$password) { my $post-data = { type => "m.login.password", @@ -41,10 +42,12 @@ multi method login(Str :$username, Str :$password) { $!device-id = $data<device_id>; } +#| POST - /_matrix/client/r0/logout method logout() { $.post("/logout") } +#| POST - /_matrix/client/r0/register method register($username, $password, Bool :$bind-email? = False) { my $res = $.post("/register", username => $username, password => $password, @@ -59,11 +62,13 @@ method register($username, $password, Bool :$bind-email? = False) { # User Data +#| GET - /_matrix/client/r0/profile/{userId} method profile(Str :$user-id?) { my $id = $user-id // $.whoami; from-json($.get("/profile/" ~ $id).content); } +#| GET - /_matrix/client/r0/profile/{userId}/displayname method display-name(Str :$user-id?) { my $id = $user-id // $.whoami; my $res = $.get("/profile/" ~ $id ~ "/displayname"); @@ -73,11 +78,13 @@ method display-name(Str :$user-id?) { $data<displayname> // "" } +#| PUT - /_matrix/client/r0/profile/{userId}/displayname method change-display-name(Str:D $display-name!) { so $.put("/profile/" ~ $.whoami ~ "/displayname", displayname => $display-name) } +#| GET - /_matrix/client/r0/profile/{userId}/avatar_url method avatar-url(Str :$user-id?) { my $id = $user-id // $.whoami; my $res = $.get("/profile/" ~ $id ~ "/avatar_url"); @@ -86,16 +93,19 @@ method avatar-url(Str :$user-id?) { $data<avatar_url> // "" } +#| PUT - /_matrix/client/r0/profile/{userId}/avatar_url multi method change-avatar(IO::Path $avatar) { my $mxc-url = $.upload($avatar.IO); samewith($mxc-url); } +#| PUT - /_matrix/client/r0/profile/{userId}/avatar_url multi method change-avatar(Str:D $mxc-url!) { $.put("/profile/" ~ $.whoami ~ "/avatar_url", avatar_url => $mxc-url); } +#| GET - /_matrix/client/r0/account/whoami method whoami { unless $!user-id { my $res = $.get('/account/whoami'); @@ -106,12 +116,14 @@ method whoami { $!user-id } +#| GET - /_matrix/client/r0/presence/{userId}/status method presence(Matrix::Client:D: $user-id? --> Matrix::Response::Presence) { my $id = $user-id // $.whoami; my $data = from-json($.get("/presence/$id/status").content); Matrix::Response::Presence.new(|$data) } +#| PUT - /_matrix/client/r0/presence/{userId}/status method set-presence(Matrix::Client:D: Str $presence, Str :$status-message = "") { $.put("/presence/$.whoami/status", :$presence, :status_msg($status-message)); @@ -137,10 +149,12 @@ method remove-tag(Str $room-id, Str:D $tag) { # Syncronization +#| GET - /_matrix/client/r0/sync multi method sync(Hash :$sync-filter is copy, :$since = "") { $.sync(sync-filter => to-json($sync-filter), since => $since) } +#| GET - /_matrix/client/r0/sync multi method sync(Str:D :$sync-filter, Str :$since = "") { my $res = $.get("/sync", timeout => 30000, @@ -151,6 +165,7 @@ multi method sync(Str:D :$sync-filter, Str :$since = "") { Matrix::Response::Sync.new($res.content) } +#| GET - /_matrix/client/r0/sync multi method sync(:$since = "") { my $res = $.get("/sync", timeout => 30000, since => $since); Matrix::Response::Sync.new($res.content) @@ -158,6 +173,7 @@ multi method sync(:$since = "") { # Rooms +#| POST - /_matrix/client/r0/createRoom method create-room( Bool :$public = False, *%args --> Matrix::Client::Room @@ -181,14 +197,17 @@ method create-room( ) } +#| POST - /_matrix/client/r0/join/{roomIdOrAlias} method join-room($room-id!) { $.post("/join/$room-id") } +#| POST - /_matrix/client/r0/rooms/{roomId}/leave method leave-room($room-id) { $.post("/rooms/$room-id/leave"); } +#| GET - /_matrix/client/r0/joined_rooms method joined-rooms(--> Seq) { my $res = $.get('/joined_rooms'); my $data = from-json($res.content); @@ -201,10 +220,12 @@ method joined-rooms(--> Seq) { }); } +#| GET - /_matrix/client/r0/publicRooms method public-rooms() { $.get('/publicRooms') } +#| PUT - /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId} method send(Str $room-id, Str $body, :$type? = "m.text") { $Matrix::Client::Common::TXN-ID++; my $res = $.put( @@ -215,23 +236,27 @@ method send(Str $room-id, Str $body, :$type? = "m.text") { 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"); from-json($res.content)<room_id> } +#| PUT - /_matrix/client/r0/directory/room/{roomAlias} method add-room-alias($room-id, $room-alias) { $.put("/directory/room/$room-alias", room_id => $room-id); } +#| DELETE - /_matrix/client/r0/directory/room/{roomAlias} method remove-room-alias($room-alias) { $.delete("/directory/room/$room-alias"); } # Media +#| POST - /_matrix/media/r0/upload method upload(IO::Path $path, Str $filename?) { my $buf = slurp $path, :bin; my $fn = $filename ?? $filename !! $path.basename; diff --git a/lib/Matrix/Client/Room.pm6 b/lib/Matrix/Client/Room.pm6 index e0b14a2..4ec774f 100644 --- a/lib/Matrix/Client/Room.pm6 +++ b/lib/Matrix/Client/Room.pm6 @@ -25,6 +25,7 @@ method !get-name() { $!name = $data<name>; } +#| GET - /_matrix/client/r0/rooms/{roomId}/joined_members method joined-members { my %data = from-json($.get("/joined_members").content); %data<joined> @@ -51,6 +52,7 @@ method fallback-name(--> Str) { }; } +#| GET - /_matrix/client/r0/rooms/{roomId}/messages method messages() { my $res = $.get("/messages"); my $data = from-json($res.content); @@ -58,6 +60,7 @@ method messages() { return $data<chunk>.clone; } +#| PUT - /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId} method send(Str $body!, Str :$type? = "m.text") { $Matrix::Client::Common::TXN-ID++; my $res = $.put( @@ -68,6 +71,7 @@ method send(Str $body!, Str :$type? = "m.text") { from-json($res.content)<event_id> } +#| GET - /_matrix/client/r0/rooms/{roomId}/state multi method state(--> Seq) { my $data = from-json($.get('/state').content); @@ -76,10 +80,12 @@ multi method state(--> Seq) { } } +#| GET - /_matrix/client/r0/rooms/{roomId}/state/{eventType} multi method state(Str $event-type) { from-json($.get("/state/$event-type").content) } +#| PUT - /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} method send-state(Str:D $event-type, :$state-key = "", *%args --> Str) { my $res = $.put( "/state/$event-type/$state-key", @@ -88,6 +94,7 @@ method send-state(Str:D $event-type, :$state-key = "", *%args --> Str) { from-json($res.content)<event_id> } +#| POST - /_matrix/client/r0/rooms/{roomId}/leave method leave() { $.post('/leave') } |