From 4b01ebdcaa8d7df0ec34c758ae9f3b8ec32fdcd0 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 17 May 2020 20:25:25 -0300 Subject: Fix missing multi methods on the endpoints TODO generator --- endpoints.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'endpoints.md') diff --git a/endpoints.md b/endpoints.md index 2ddf2c3..c77b6c4 100644 --- a/endpoints.md +++ b/endpoints.md @@ -30,7 +30,7 @@ from matrix.org. This will give you an overview about what's implemented in the ## Media - [ ] GET - /_matrix/media/r0/config -- [ ] GET - /_matrix/media/r0/download/{serverName}/{mediaId} +- [X] GET - /_matrix/media/r0/download/{serverName}/{mediaId} - [ ] GET - /_matrix/media/r0/download/{serverName}/{mediaId}/{fileName} - [ ] GET - /_matrix/media/r0/preview_url - [ ] GET - /_matrix/media/r0/thumbnail/{serverName}/{mediaId} @@ -104,9 +104,9 @@ from matrix.org. This will give you an overview about what's implemented in the - [X] GET - /_matrix/client/r0/rooms/{roomId}/joined_members - [ ] GET - /_matrix/client/r0/rooms/{roomId}/members - [X] GET - /_matrix/client/r0/rooms/{roomId}/messages -- [ ] GET - /_matrix/client/r0/rooms/{roomId}/state +- [X] GET - /_matrix/client/r0/rooms/{roomId}/state - [ ] GET - /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} -- [ ] GET - /_matrix/client/r0/sync +- [X] GET - /_matrix/client/r0/sync - [ ] GET - /_matrix/client/r0/user/{userId}/filter/{filterId} - [ ] POST - /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId} - [ ] POST - /_matrix/client/r0/user/{userId}/filter @@ -136,7 +136,7 @@ from matrix.org. This will give you an overview about what's implemented in the ## Session management - [ ] GET - /_matrix/client/r0/login -- [ ] POST - /_matrix/client/r0/login +- [X] POST - /_matrix/client/r0/login - [X] POST - /_matrix/client/r0/logout - [ ] POST - /_matrix/client/r0/logout/all @@ -151,18 +151,20 @@ from matrix.org. This will give you an overview about what's implemented in the - [ ] GET - /_matrix/client/r0/register/available - [ ] GET - /_matrix/client/r0/user/{userId}/account_data/{type} - [ ] GET - /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type} -- [ ] GET - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags +- [X] GET - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags - [ ] POST - /_matrix/client/r0/account/3pid +- [ ] POST - /_matrix/client/r0/account/3pid/bind - [ ] POST - /_matrix/client/r0/account/3pid/delete +- [ ] POST - /_matrix/client/r0/account/3pid/unbind - [ ] POST - /_matrix/client/r0/account/deactivate - [ ] POST - /_matrix/client/r0/account/password - [X] POST - /_matrix/client/r0/register - [ ] POST - /_matrix/client/r0/user_directory/search -- [ ] PUT - /_matrix/client/r0/profile/{userId}/avatar_url +- [X] PUT - /_matrix/client/r0/profile/{userId}/avatar_url - [X] PUT - /_matrix/client/r0/profile/{userId}/displayname - [ ] PUT - /_matrix/client/r0/user/{userId}/account_data/{type} - [ ] PUT - /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type} -- [ ] PUT - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} +- [X] PUT - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} ## VOIP -- cgit v1.2.3-70-g09d2 From ab2a237e5cff43f9b8cd806b7e9e271ffb01b461 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 6 Sep 2020 19:51:23 -0300 Subject: Update endpoints script. Show the total of endpoints implemented at the end --- endpoints.md | 12 ++++++++++-- lib/Matrix/Client/MediaStore.rakumod | 1 + scripts/load-docs.p6 | 12 ++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) (limited to 'endpoints.md') diff --git a/endpoints.md b/endpoints.md index c77b6c4..f47105b 100644 --- a/endpoints.md +++ b/endpoints.md @@ -29,7 +29,7 @@ from matrix.org. This will give you an overview about what's implemented in the ## Media -- [ ] GET - /_matrix/media/r0/config +- [X] GET - /_matrix/media/r0/config - [X] GET - /_matrix/media/r0/download/{serverName}/{mediaId} - [ ] GET - /_matrix/media/r0/download/{serverName}/{mediaId}/{fileName} - [ ] GET - /_matrix/media/r0/preview_url @@ -52,6 +52,8 @@ from matrix.org. This will give you an overview about what's implemented in the - [ ] GET - /_matrix/client/r0/pushers - [ ] GET - /_matrix/client/r0/pushrules/ - [ ] GET - /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId} +- [ ] GET - /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions +- [ ] GET - /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/enabled - [ ] POST - /_matrix/client/r0/pushers/set - [ ] PUT - /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId} - [ ] PUT - /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions @@ -73,6 +75,7 @@ from matrix.org. This will give you an overview about what's implemented in the - [X] DELETE - /_matrix/client/r0/directory/room/{roomAlias} - [X] GET - /_matrix/client/r0/directory/room/{roomAlias} +- [ ] GET - /_matrix/client/r0/rooms/{roomId}/aliases - [X] PUT - /_matrix/client/r0/directory/room/{roomAlias} ## Room discovery @@ -115,7 +118,7 @@ from matrix.org. This will give you an overview about what's implemented in the - [X] PUT - /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} - [ ] PUT - /_matrix/client/r0/rooms/{roomId}/typing/{userId} -## Room ugprades +## Room upgrades - [ ] POST - /_matrix/client/r0/rooms/{roomId}/upgrade @@ -170,3 +173,8 @@ from matrix.org. This will give you an overview about what's implemented in the - [ ] GET - /_matrix/client/r0/voip/turnServer + +# Endpoint completion + +0.378641% - (39/103) + diff --git a/lib/Matrix/Client/MediaStore.rakumod b/lib/Matrix/Client/MediaStore.rakumod index 7afa9e3..cb59626 100644 --- a/lib/Matrix/Client/MediaStore.rakumod +++ b/lib/Matrix/Client/MediaStore.rakumod @@ -70,6 +70,7 @@ multi method download(Str $server-name, Str $media-id, Bool :$allow-remote = Tru ) } +#| GET - /_matrix/media/r0/config method config(--> Matrix::Response::MediaStore::Config) { my $response = $.get("/config"); Matrix::Response::MediaStore::Config.new(from-json($response.content)) diff --git a/scripts/load-docs.p6 b/scripts/load-docs.p6 index 87ef0d4..2392a3a 100755 --- a/scripts/load-docs.p6 +++ b/scripts/load-docs.p6 @@ -34,6 +34,8 @@ sub get-api-docs { sub MAIN(:$spec?) { my %tags = get-api-docs; + my $total = 0; + my $completed = 0; my $implemented-methods = ( Matrix::Client, Matrix::Client::Room, Matrix::Client::MediaStore ).map(*.^methodsĀ».candidates).flat.map( @@ -58,6 +60,9 @@ sub MAIN(:$spec?) { for $methods.Seq.sort -> $m { my Str $method = $m.trim; my $checked = $implemented-methods{$m} ?? "X" !! " "; + $completed++ if $implemented-methods{$m}; + $total++; + if $spec { $method = $m.subst(/unstable/, $spec) } @@ -65,4 +70,11 @@ sub MAIN(:$spec?) { } say ""; } + + say qq:to/EOF/; + + # Endpoint completion + + {$completed/$total}% - ($completed/$total) + EOF } -- cgit v1.2.3-70-g09d2 From d8f623d8093ff8e47d386f86e61deebdac66fc29 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 6 Sep 2020 20:16:15 -0300 Subject: Add thumbnail endpoint --- endpoints.md | 6 ++--- lib/Matrix/Client/MediaStore.rakumod | 49 ++++++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 8 deletions(-) (limited to 'endpoints.md') diff --git a/endpoints.md b/endpoints.md index f47105b..ad26ad9 100644 --- a/endpoints.md +++ b/endpoints.md @@ -31,9 +31,9 @@ from matrix.org. This will give you an overview about what's implemented in the - [X] GET - /_matrix/media/r0/config - [X] GET - /_matrix/media/r0/download/{serverName}/{mediaId} -- [ ] GET - /_matrix/media/r0/download/{serverName}/{mediaId}/{fileName} +- [X] GET - /_matrix/media/r0/download/{serverName}/{mediaId}/{fileName} - [ ] GET - /_matrix/media/r0/preview_url -- [ ] GET - /_matrix/media/r0/thumbnail/{serverName}/{mediaId} +- [X] GET - /_matrix/media/r0/thumbnail/{serverName}/{mediaId} - [X] POST - /_matrix/media/r0/upload ## OpenID @@ -176,5 +176,5 @@ from matrix.org. This will give you an overview about what's implemented in the # Endpoint completion -0.378641% - (39/103) +0.398058% - (41/103) diff --git a/lib/Matrix/Client/MediaStore.rakumod b/lib/Matrix/Client/MediaStore.rakumod index cb59626..9779db2 100644 --- a/lib/Matrix/Client/MediaStore.rakumod +++ b/lib/Matrix/Client/MediaStore.rakumod @@ -48,16 +48,20 @@ method upload(IO::Path $path, Str $filename?, Str :$content-type is copy = "imag } #| GET - /_matrix/media/r0/download/{serverName}/{mediaId} -multi method download(Str $mxc-uri, :$allow-remote = True) { +multi method download(Str $mxc-uri, :$allow-remote = True, Str :$filename?) { my $mxc = self.parse-mxc($mxc-uri); - samewith($mxc, $mxc, :$allow-remote) + samewith($mxc, $mxc, :$allow-remote, :$filename) } -#| GET - /_matrix/media/r0/download/{serverName}/{mediaId} -multi method download(Str $server-name, Str $media-id, Bool :$allow-remote = True) { +#| GET - /_matrix/media/r0/download/{serverName}/{mediaId}/{fileName} +multi method download(Str $server-name, Str $media-id, + Bool :$allow-remote = True, Str :$filename?) { + my $endpoint = "/download/{$server-name}/{$media-id}"; + + $endpoint ~= "/{$filename}" if $filename.defined; my $response = $.get( - "/download/{$server-name}/{$media-id}", + $endpoint, allow_remote => $allow-remote.Str.lc ); @@ -70,6 +74,41 @@ multi method download(Str $server-name, Str $media-id, Bool :$allow-remote = Tru ) } +#| GET - /_matrix/media/r0/thumbnail/{serverName}/{mediaId} +multi method thumbnail(Str $mxc-uri, Int $width, Int $height, + Str :$method where * eq 'crop'|'scale', + Bool :$allow-remote = True) { + my $mxc = self.parse-mxc($mxc-uri); + samewith( + $mxc, $mxc, + $width, $height, + :$method, :$allow-remote + ) +} + +#| GET - /_matrix/media/r0/thumbnail/{serverName}/{mediaId} +multi method thumbnail(Str $server-name, Str $media-id, + Int $width, Int $height, + Str :$method where * eq 'crop'|'scale', + Bool :$allow-remote = True) { + my $endpoint = "/thumbnail/{$server-name}/{$media-id}"; + + my $response = $.get( + $endpoint, + :$height, + :$width, + :$method, + allow_remote => $allow-remote.Str.lc + ); + + my %headers = $response.header.hash(); + + Matrix::Client::MediaStore::File.new( + content-type => %headers.head, + content => $response.content + ) +} + #| GET - /_matrix/media/r0/config method config(--> Matrix::Response::MediaStore::Config) { my $response = $.get("/config"); -- cgit v1.2.3-70-g09d2 From d5b3361c9ceeac3ed3a90dab35b12b0bd4ab7612 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sat, 26 Dec 2020 22:33:31 -0300 Subject: Implement membership endpoints for Matrix::Client::Room This implements for room endpoints: * Join a room * Get a single event * Get states * Get room aliases * Get room members --- endpoints.md | 13 +++-- lib/Matrix/Client/Room.pm6 | 116 ++++++++++++++++++++++++++++++++++++--------- lib/Matrix/Response.pm6 | 4 ++ 3 files changed, 103 insertions(+), 30 deletions(-) (limited to 'endpoints.md') diff --git a/endpoints.md b/endpoints.md index ad26ad9..e8bc9f8 100644 --- a/endpoints.md +++ b/endpoints.md @@ -75,7 +75,7 @@ from matrix.org. This will give you an overview about what's implemented in the - [X] DELETE - /_matrix/client/r0/directory/room/{roomAlias} - [X] GET - /_matrix/client/r0/directory/room/{roomAlias} -- [ ] GET - /_matrix/client/r0/rooms/{roomId}/aliases +- [X] GET - /_matrix/client/r0/rooms/{roomId}/aliases - [X] PUT - /_matrix/client/r0/directory/room/{roomAlias} ## Room discovery @@ -91,7 +91,7 @@ from matrix.org. This will give you an overview about what's implemented in the - [X] POST - /_matrix/client/r0/rooms/{roomId}/forget - [X] POST - /_matrix/client/r0/rooms/{roomId}/invite - [ ] POST - /_matrix/client/r0/rooms/{roomId}/invite -- [ ] POST - /_matrix/client/r0/rooms/{roomId}/join +- [X] POST - /_matrix/client/r0/rooms/{roomId}/join - [X] POST - /_matrix/client/r0/rooms/{roomId}/kick - [X] POST - /_matrix/client/r0/rooms/{roomId}/leave - [X] POST - /_matrix/client/r0/rooms/{roomId}/unban @@ -102,13 +102,13 @@ from matrix.org. This will give you an overview about what's implemented in the - [ ] GET - /_matrix/client/r0/events/{eventId} - [ ] GET - /_matrix/client/r0/initialSync - [ ] GET - /_matrix/client/r0/rooms/{roomId}/context/{eventId} -- [ ] GET - /_matrix/client/r0/rooms/{roomId}/event/{eventId} +- [X] GET - /_matrix/client/r0/rooms/{roomId}/event/{eventId} - [ ] GET - /_matrix/client/r0/rooms/{roomId}/initialSync - [X] GET - /_matrix/client/r0/rooms/{roomId}/joined_members -- [ ] GET - /_matrix/client/r0/rooms/{roomId}/members +- [X] GET - /_matrix/client/r0/rooms/{roomId}/members - [X] GET - /_matrix/client/r0/rooms/{roomId}/messages - [X] GET - /_matrix/client/r0/rooms/{roomId}/state -- [ ] GET - /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} +- [X] GET - /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} - [X] GET - /_matrix/client/r0/sync - [ ] GET - /_matrix/client/r0/user/{userId}/filter/{filterId} - [ ] POST - /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId} @@ -176,5 +176,4 @@ from matrix.org. This will give you an overview about what's implemented in the # Endpoint completion -0.398058% - (41/103) - +0.446602% - (46/103) diff --git a/lib/Matrix/Client/Room.pm6 b/lib/Matrix/Client/Room.pm6 index ca97d2f..72dfb62 100644 --- a/lib/Matrix/Client/Room.pm6 +++ b/lib/Matrix/Client/Room.pm6 @@ -25,15 +25,8 @@ method !get-name() { $!name = $data; } -#| GET - /_matrix/client/r0/rooms/{roomId}/joined_members -method joined-members { - my %data = from-json($.get("/joined_members").content); - %data -} - -method name { +method name(--> Str) { self!get-name; - $!name } @@ -52,6 +45,42 @@ method fallback-name(--> Str) { }; } +#| GET - /_matrix/client/r0/rooms/{roomId}/aliases +method aliases(--> List) { + my %data = from-json($.get('/aliases').content); + %data.List +} + +# Events + +## Getting events for a room + +#| GET - /_matrix/client/r0/rooms/{roomId}/event/{eventId} +method event(Str $event-id --> Matrix::Response::RoomEvent) { + my %data = from-json($.get("/event/$event-id").content); + Matrix::Response::RoomEvent.new(|%data) +} + +#| GET - /_matrix/client/r0/rooms/{roomId}/state +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) + } +} + +#| GET - /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} +multi method state(Str $event-type, Str $state-key = "") { + from-json($.get("/state/$event-type/$state-key").content) +} + +#| GET - /_matrix/client/r0/rooms/{roomId}/joined_members +method joined-members { + my %data = from-json($.get("/joined_members").content); + %data +} + #| GET - /_matrix/client/r0/rooms/{roomId}/messages method messages() { my $res = $.get("/messages"); @@ -60,6 +89,23 @@ method messages() { return $data.clone; } +#| GET - /_matrix/client/r0/rooms/{roomId}/members +method members(:$at, Str :$membership, Str :$not-membership) { + my %query; + + %query = $at with $at; + %query = $membership with $membership; + %query = $not-membership with $not-membership; + + my %data = from-json($.get('/members', |%query).content); + + gather for %data.List -> $ev { + take Matrix::Response::MemberEvent.new(|$ev) + } +} + +## Sending events to a room + #| PUT - /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId} method send(Str $body!, Str :$type? = "m.text") { $Matrix::Client::Common::TXN-ID++; @@ -71,20 +117,6 @@ method send(Str $body!, Str :$type? = "m.text") { from-json($res.content) } -#| GET - /_matrix/client/r0/rooms/{roomId}/state -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) - } -} - -#| 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( @@ -94,11 +126,49 @@ method send-state(Str:D $event-type, :$state-key = "", *%args --> Str) { from-json($res.content) } +# Room membership! + +## Joining rooms + +#| POST - /_matrix/client/r0/rooms/{roomId}/invite +method invite(Str $user-id) { + $.post('/invite', :$user-id) +} + +#| POST - /_matrix/client/r0/rooms/{roomId}/join +method join { + $.post('/join') +} + +## Leaving rooms + #| POST - /_matrix/client/r0/rooms/{roomId}/leave -method leave() { +method leave { $.post('/leave') } +#| POST - /_matrix/client/r0/rooms/{roomId}/forget +method forget { + $.post('/forget') +} + +#| POST - /_matrix/client/r0/rooms/{roomId}/kick +method kick(Str $user-id, Str $reason = "") { + $.post('/kick', :$user-id, :$reason) +} + +## Banning users + +#| POST - /_matrix/client/r0/rooms/{roomId}/ban +method ban(Str $user-id, $reason = "") { + $.post('/ban', :$user-id, :$reason) +} + +#| POST - /_matrix/client/r0/rooms/{roomId}/unban +method unban(Str $user-id) { + $.post('/unban', :$user-id) +} + method Str(--> Str) { "Room" } diff --git a/lib/Matrix/Response.pm6 b/lib/Matrix/Response.pm6 index ec93cf3..cc9e7a8 100644 --- a/lib/Matrix/Response.pm6 +++ b/lib/Matrix/Response.pm6 @@ -23,6 +23,10 @@ class Matrix::Response::StateEvent is Matrix::Response::RoomEvent { has $.state_key; } +class Matrix::Response::MemberEvent is Matrix::Response::StateEvent { + has $.type is required where 'm.room.member'; +} + class Matrix::Response::Timeline { has Matrix::Response::Event @.events; has Bool $limited; -- cgit v1.2.3-70-g09d2