From 24fa000eba9f778311b196e4df255952b6ac92bc Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 3 Feb 2019 23:28:07 -0300 Subject: Add support for room tags --- endpoints.md | 6 +++--- lib/Matrix/Client.pm6 | 18 ++++++++++++++++++ lib/Matrix/Response.pm6 | 9 +++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/endpoints.md b/endpoints.md index c4aeace..a9ee8e6 100644 --- a/endpoints.md +++ b/endpoints.md @@ -152,9 +152,9 @@ from matrix.org. This will give you an overview about what's implemented in the - [ ] GET - /_matrix/client/r0/account/3pid - [ ] POST - /_matrix/client/r0/account/3pid - [ ] PUT - /_matrix/client/r0/user/{userId}/account_data/{type} -- [ ] PUT - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} -- [ ] DELETE - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} -- [ ] GET - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags +- [X] PUT - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} +- [X] DELETE - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} +- [X] GET - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags - [ ] POST - /_matrix/client/r0/account/deactivate - [ ] POST - /_matrix/client/r0/account/3pid/delete diff --git a/lib/Matrix/Client.pm6 b/lib/Matrix/Client.pm6 index 5f52779..bf3935c 100644 --- a/lib/Matrix/Client.pm6 +++ b/lib/Matrix/Client.pm6 @@ -117,6 +117,24 @@ method set-presence(Matrix::Client:D: Str $presence, Str :$status-message = "") :$presence, :status_msg($status-message)); } +#| PUT - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} +multi method tags(Str $room-id, Str:D $tag, $order) { + my $id = $.whoami; + from-json($.put("/user/$id/rooms/$room-id/tags/$tag", :$order).content) +} + +#| GET - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags +multi method tags(Str $room-id) { + my $id = $.whoami; + Matrix::Response::Tag.new(from-json($.get("/user/$id/rooms/$room-id/tags").content)) +} + +#| DELETE - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} +method remove-tag(Str $room-id, Str:D $tag) { + my $id = $.whoami; + $.delete("/user/$id/rooms/$room-id/tags/$tag") +} + # Syncronization multi method sync(Hash :$sync-filter is copy, :$since = "") { diff --git a/lib/Matrix/Response.pm6 b/lib/Matrix/Response.pm6 index d8f68f0..edd4d51 100644 --- a/lib/Matrix/Response.pm6 +++ b/lib/Matrix/Response.pm6 @@ -113,3 +113,12 @@ class Presence { :currently_active(:$!currently-active) = False ) { } } + +class Tag { + has @.tags; + + method new(%json) { + my @tags = %json.keys; + self.bless(:@tags) + } +} -- cgit v1.2.3-70-g09d2 From aff2a2eeb6fba35636a863fdf48a3ad08c335877 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Mon, 18 Mar 2019 16:11:30 -0300 Subject: Better room name --- lib/Matrix/Client/Room.pm6 | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/Matrix/Client/Room.pm6 b/lib/Matrix/Client/Room.pm6 index fa4501a..4c51be6 100644 --- a/lib/Matrix/Client/Room.pm6 +++ b/lib/Matrix/Client/Room.pm6 @@ -12,11 +12,26 @@ submethod TWEAK { $!url-prefix = "/rooms/$!id"; } +method !format-name-from-members { + my @members = $.joined-members.kv.map( + -> $k, %v { + %v // $k + } + ); + + $!name = do given @members.elems { + when 1 { @members.first } + when 2 { @members[0] ~ " and " ~ @members[1] } + when * > 2 { @members.first ~ " and {@members.elems - 1} others" } + default { "Empty room" } + }; +} + method !get-name() { CATCH { when X::Matrix::Response { .code ~~ /M_NOT_FOUND/ - ?? ($!name = '') + ?? self!format-name-from-members !! fail } default { fail } @@ -25,8 +40,18 @@ method !get-name() { $!name = $data; } +method joined-members { + my %data = from-json($.get("/joined_members").content); + %data +} + method name() { - unless $!name.so { self!get-name() } + if $!name { + return $!name; + } + + self!get-name; + $!name } @@ -67,7 +92,6 @@ method send-state(Str:D $event-type, :$state-key = "", *%args --> Str) { from-json($res.content) } - method leave() { $.post('/leave') } -- cgit v1.2.3-70-g09d2 From 0977a9f4148518686ac6e75c56542e7d8daca029 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Mon, 18 Mar 2019 16:12:25 -0300 Subject: Update endpoints --- endpoints.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/endpoints.md b/endpoints.md index c4aeace..8b0d3b7 100644 --- a/endpoints.md +++ b/endpoints.md @@ -80,10 +80,10 @@ from matrix.org. This will give you an overview about what's implemented in the ## Room membership -- [ ] POST - /_matrix/client/r0/rooms/{roomId}/join +- [x] POST - /_matrix/client/r0/rooms/{roomId}/join - [ ] POST - /_matrix/client/r0/join/{roomIdOrAlias} - [ ] POST - /_matrix/client/r0/rooms/{roomId}/kick -- [ ] POST - /_matrix/client/r0/rooms/{roomId}/leave +- [x] POST - /_matrix/client/r0/rooms/{roomId}/leave - [x] GET - /_matrix/client/r0/joined_rooms - [ ] POST - /_matrix/client/r0/rooms/{roomId}/invite - [ ] POST - /_matrix/client/r0/rooms/{roomId}/unban -- cgit v1.2.3-70-g09d2 From 22e9276301e5c9b1a9a38148a5c9ba4194218cea Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Mon, 18 Mar 2019 17:12:04 -0300 Subject: Separate fallback name from name. --- lib/Matrix/Client/Room.pm6 | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/lib/Matrix/Client/Room.pm6 b/lib/Matrix/Client/Room.pm6 index 4c51be6..e0b14a2 100644 --- a/lib/Matrix/Client/Room.pm6 +++ b/lib/Matrix/Client/Room.pm6 @@ -12,26 +12,11 @@ submethod TWEAK { $!url-prefix = "/rooms/$!id"; } -method !format-name-from-members { - my @members = $.joined-members.kv.map( - -> $k, %v { - %v // $k - } - ); - - $!name = do given @members.elems { - when 1 { @members.first } - when 2 { @members[0] ~ " and " ~ @members[1] } - when * > 2 { @members.first ~ " and {@members.elems - 1} others" } - default { "Empty room" } - }; -} - method !get-name() { CATCH { when X::Matrix::Response { .code ~~ /M_NOT_FOUND/ - ?? self!format-name-from-members + ?? ($!name = '') !! fail } default { fail } @@ -45,16 +30,27 @@ method joined-members { %data } -method name() { - if $!name { - return $!name; - } - +method name { self!get-name; $!name } +method fallback-name(--> Str) { + my @members = $.joined-members.kv.map( + -> $k, %v { + %v // $k + } + ); + + $!name = do given @members.elems { + when 1 { @members.first } + when 2 { @members[0] ~ " and " ~ @members[1] } + when * > 2 { @members.first ~ " and {@members.elems - 1} others" } + default { "Empty room" } + }; +} + method messages() { my $res = $.get("/messages"); my $data = from-json($res.content); -- cgit v1.2.3-70-g09d2 From 0769ebef8221cf5fc40a070c7f19d4a8a8e94a46 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Tue, 4 Jun 2019 23:03:20 -0300 Subject: Fix missing =end pod --- docs/room.pod6 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/room.pod6 b/docs/room.pod6 index 1df8c84..9724793 100644 --- a/docs/room.pod6 +++ b/docs/room.pod6 @@ -66,3 +66,5 @@ It will return the C for this state change. method leave() Leaves the room. + +=end pod -- cgit v1.2.3-70-g09d2 From 0b1e90f84b94e22fc8d5a1eb6158498a1a5b2f17 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Tue, 4 Jun 2019 23:04:43 -0300 Subject: Update readme --- .gitignore | 1 + META6.json | 63 +++++++++++++++++++++++++++++++++++--------------------------- README.md | 41 +++++++++++++++++++++++----------------- 3 files changed, 61 insertions(+), 44 deletions(-) diff --git a/.gitignore b/.gitignore index 0e5e830..0d701e8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ state file.json .precomp **/*/.precomp +todo.org \ No newline at end of file diff --git a/META6.json b/META6.json index 83455e5..0788805 100644 --- a/META6.json +++ b/META6.json @@ -1,29 +1,38 @@ { - "perl" : "6.c", - "name" : "Matrix::Client", - "license" : "Artistic-2.0", - "version" : "0.3.0", - "description" : "Matrix client for Perl 6", - "tags" : [ "Net", "Matrix" ], - "depends" : [ - "JSON::Tiny", - "HTTP::UserAgent", - "URI::Encode", - "IO::Socket::SSL" - ], - "test-depends" : [ - "Test", - "Test::META" - ], - "provides" : { - "Matrix::Client" : "lib/Matrix/Client.pm6", - "Matrix::Response" : "lib/Matrix/Response.pm6", - "Matrix::Client::Room" : "lib/Matrix/Client/Room.pm6", - "Matrix::Client::Requester" : "lib/Matrix/Client/Requester.pm6", - "Matrix::Client::Common" : "lib/Matrix/Client/Common.pm6", - "Matrix::Client::Exception" : "lib/Matrix/Client/Exception.pm6" - }, - "authors" : ["Matias Linares"], - "support" : {"source" : "git://github.com/matiaslina/perl6-matrix-client.git"}, - "source-url" : "https://github.com/matiaslina/perl6-matrix-client.git" + "authors" : [ + "Matias Linares" + ], + "build-depends" : [ ], + "depends" : [ + "JSON::Tiny", + "HTTP::UserAgent", + "URI::Encode", + "IO::Socket::SSL" + ], + "description" : "Matrix client for Perl 6", + "license" : "Artistic-2.0", + "name" : "Matrix::Client", + "perl" : "6.c", + "provides" : { + "Matrix::Client" : "lib/Matrix/Client.pm6", + "Matrix::Client::Common" : "lib/Matrix/Client/Common.pm6", + "Matrix::Client::Exception" : "lib/Matrix/Client/Exception.pm6", + "Matrix::Client::Requester" : "lib/Matrix/Client/Requester.pm6", + "Matrix::Client::Room" : "lib/Matrix/Client/Room.pm6", + "Matrix::Response" : "lib/Matrix/Response.pm6" + }, + "resources" : [ ], + "source-url" : "https://github.com/matiaslina/perl6-matrix-client.git", + "support" : { + "source" : "git://github.com/matiaslina/perl6-matrix-client.git" + }, + "tags" : [ + "Net", + "Matrix" + ], + "test-depends" : [ + "Test", + "Test::META" + ], + "version" : "0.3.0" } diff --git a/README.md b/README.md index 43c1aac..e629915 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,33 @@ -# Matrix client +### multi method tags -A perl 6 library for [Matrix](https://matrix.org). +```perl6 +multi method tags( + Str $room-id, + Str:D $tag, + $order +) returns Mu +``` -## Status +PUT - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} -This project is in early development. A lot of methods return a raw -`HTTP::Response` and not something from this library. +### multi method tags -## Examples +```perl6 +multi method tags( + Str $room-id +) returns Mu +``` -From the `examples` directory: +GET - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags - use v6; - use Matrix::Client; +### method remove-tag - # Instantiate a new client for a given home-server - my $client = Matrix::Client.new: :home-server - # Login - $client.login: @*ARGS[0], @*ARGS[1]; +```perl6 +method remove-tag( + Str $room-id, + Str:D $tag +) returns Mu +``` - # Show all joined rooms - say $client.rooms(:sync); +DELETE - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} - # And finally logout. - $client.logout -- cgit v1.2.3-70-g09d2 From 5d8aafcccbc582bf2d3be828b66e1495433ae5e5 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Wed, 5 Jun 2019 00:30:10 -0300 Subject: Auto check the endpoint if it's found on pod declarator --- endpoints.md | 121 ++++++++++++++++++++++++++------------------------- scripts/load-docs.p6 | 25 +++++++++-- 2 files changed, 82 insertions(+), 64 deletions(-) diff --git a/endpoints.md b/endpoints.md index 2d7cb4e..1d5be92 100644 --- a/endpoints.md +++ b/endpoints.md @@ -1,3 +1,4 @@ +SetHash(DELETE - /_matrix/client/r0/directory/room/{roomAlias} DELETE - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} GET - /_matrix/client/r0/account/whoami GET - /_matrix/client/r0/directory/room/{roomAlias} GET - /_matrix/client/r0/joined_rooms GET - /_matrix/client/r0/presence/{userId}/status GET - /_matrix/client/r0/profile/{userId} GET - /_matrix/client/r0/profile/{userId}/avatar_url GET - /_matrix/client/r0/profile/{userId}/displayname GET - /_matrix/client/r0/publicRooms GET - /_matrix/client/r0/rooms/{roomId}/joined_members GET - /_matrix/client/r0/rooms/{roomId}/messages POST - /_matrix/client/r0/createRoom POST - /_matrix/client/r0/join/{roomIdOrAlias} POST - /_matrix/client/r0/logout POST - /_matrix/client/r0/register POST - /_matrix/client/r0/rooms/{roomId}/leave POST - /_matrix/media/r0/upload PUT - /_matrix/client/r0/directory/room/{roomAlias} PUT - /_matrix/client/r0/presence/{userId}/status PUT - /_matrix/client/r0/profile/{userId}/displayname PUT - /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId} PUT - /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}) # List of implemented endpoints This list was generated by the `load-docs.p6` script that gets the data @@ -11,26 +12,26 @@ from matrix.org. This will give you an overview about what's implemented in the ## Device management - [ ] DELETE - /_matrix/client/r0/devices/{deviceId} -- [ ] GET - /_matrix/client/r0/devices/{deviceId} -- [ ] PUT - /_matrix/client/r0/devices/{deviceId} - [ ] GET - /_matrix/client/r0/devices +- [ ] GET - /_matrix/client/r0/devices/{deviceId} - [ ] POST - /_matrix/client/r0/delete_devices +- [ ] PUT - /_matrix/client/r0/devices/{deviceId} ## End-to-end encryption - [ ] GET - /_matrix/client/r0/keys/changes - [ ] POST - /_matrix/client/r0/keys/claim -- [ ] POST - /_matrix/client/r0/keys/upload - [ ] POST - /_matrix/client/r0/keys/query +- [ ] POST - /_matrix/client/r0/keys/upload ## Media -- [ ] GET - /_matrix/media/r0/download/{serverName}/{mediaId}/{fileName} - [ ] GET - /_matrix/media/r0/config -- [ ] GET - /_matrix/media/r0/thumbnail/{serverName}/{mediaId} - [ ] GET - /_matrix/media/r0/download/{serverName}/{mediaId} -- [x] POST - /_matrix/media/r0/upload +- [ ] GET - /_matrix/media/r0/download/{serverName}/{mediaId}/{fileName} - [ ] GET - /_matrix/media/r0/preview_url +- [ ] GET - /_matrix/media/r0/thumbnail/{serverName}/{mediaId} +- [X] POST - /_matrix/media/r0/upload ## OpenID @@ -38,22 +39,22 @@ from matrix.org. This will give you an overview about what's implemented in the ## Presence -- [x] GET - /_matrix/client/r0/presence/{userId}/status -- [x] PUT - /_matrix/client/r0/presence/{userId}/status -- [ ] POST - /_matrix/client/r0/presence/list/{userId} - [ ] GET - /_matrix/client/r0/presence/list/{userId} +- [X] GET - /_matrix/client/r0/presence/{userId}/status +- [ ] POST - /_matrix/client/r0/presence/list/{userId} +- [X] PUT - /_matrix/client/r0/presence/{userId}/status ## Push notifications +- [ ] DELETE - /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId} +- [ ] GET - /_matrix/client/r0/notifications - [ ] GET - /_matrix/client/r0/pushers - [ ] GET - /_matrix/client/r0/pushrules/ +- [ ] GET - /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId} - [ ] POST - /_matrix/client/r0/pushers/set -- [ ] GET - /_matrix/client/r0/notifications +- [ ] PUT - /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId} - [ ] PUT - /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/actions - [ ] PUT - /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId}/enabled -- [ ] PUT - /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId} -- [ ] GET - /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId} -- [ ] DELETE - /_matrix/client/r0/pushrules/{scope}/{kind}/{ruleId} ## Read Markers @@ -65,54 +66,54 @@ from matrix.org. This will give you an overview about what's implemented in the ## Room creation -- [x] POST - /_matrix/client/r0/createRoom +- [X] POST - /_matrix/client/r0/createRoom ## Room directory -- [x] PUT - /_matrix/client/r0/directory/room/{roomAlias} -- [x] DELETE - /_matrix/client/r0/directory/room/{roomAlias} -- [x] GET - /_matrix/client/r0/directory/room/{roomAlias} +- [X] DELETE - /_matrix/client/r0/directory/room/{roomAlias} +- [X] GET - /_matrix/client/r0/directory/room/{roomAlias} +- [X] PUT - /_matrix/client/r0/directory/room/{roomAlias} ## Room discovery +- [X] GET - /_matrix/client/r0/publicRooms - [ ] POST - /_matrix/client/r0/publicRooms -- [x] GET - /_matrix/client/r0/publicRooms ## Room membership -- [x] POST - /_matrix/client/r0/rooms/{roomId}/join -- [ ] POST - /_matrix/client/r0/join/{roomIdOrAlias} -- [ ] POST - /_matrix/client/r0/rooms/{roomId}/kick -- [x] POST - /_matrix/client/r0/rooms/{roomId}/leave -- [x] GET - /_matrix/client/r0/joined_rooms -- [ ] POST - /_matrix/client/r0/rooms/{roomId}/invite -- [ ] POST - /_matrix/client/r0/rooms/{roomId}/unban +- [X] GET - /_matrix/client/r0/joined_rooms +- [X] POST - /_matrix/client/r0/join/{roomIdOrAlias} - [ ] POST - /_matrix/client/r0/rooms/{roomId}/ban - [ ] POST - /_matrix/client/r0/rooms/{roomId}/forget - [ ] POST - /_matrix/client/r0/rooms/{roomId}/invite +- [ ] POST - /_matrix/client/r0/rooms/{roomId}/invite +- [ ] POST - /_matrix/client/r0/rooms/{roomId}/join +- [ ] POST - /_matrix/client/r0/rooms/{roomId}/kick +- [X] POST - /_matrix/client/r0/rooms/{roomId}/leave +- [ ] POST - /_matrix/client/r0/rooms/{roomId}/unban ## Room participation -- [ ] GET - /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} -- [x] PUT - /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} -- [x] GET - /_matrix/client/r0/rooms/{roomId}/state -- [ ] GET - /_matrix/client/r0/rooms/{roomId}/context/{eventId} - [ ] GET - /_matrix/client/r0/events -- [ ] GET - /_matrix/client/r0/rooms/{roomId}/joined_members -- [ ] POST - /_matrix/client/r0/user/{userId}/filter -- [ ] GET - /_matrix/client/r0/rooms/{roomId}/initialSync -- [x] PUT - /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId} (partial) -- [ ] GET - /_matrix/client/r0/initialSync (deprecated) -- [x] GET - /_matrix/client/r0/rooms/{roomId}/messages +- [ ] 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} -- [ ] GET - /_matrix/client/r0/user/{userId}/filter/{filterId} -- [x] GET - /_matrix/client/r0/sync +- [ ] GET - /_matrix/client/r0/rooms/{roomId}/initialSync +- [X] GET - /_matrix/client/r0/rooms/{roomId}/joined_members - [ ] GET - /_matrix/client/r0/rooms/{roomId}/members -- [ ] GET - /_matrix/client/r0/events/{eventId} -- [ ] PUT - /_matrix/client/r0/rooms/{roomId}/redact/{eventId}/{txnId} +- [X] GET - /_matrix/client/r0/rooms/{roomId}/messages +- [ ] GET - /_matrix/client/r0/rooms/{roomId}/state +- [ ] GET - /_matrix/client/r0/rooms/{roomId}/state/{eventType} +- [ ] GET - /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} +- [ ] GET - /_matrix/client/r0/sync +- [ ] GET - /_matrix/client/r0/user/{userId}/filter/{filterId} - [ ] POST - /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId} -- [x] PUT - /_matrix/client/r0/rooms/{roomId}/state/{eventType} -- [x] GET - /_matrix/client/r0/rooms/{roomId}/state/{eventType} +- [ ] POST - /_matrix/client/r0/user/{userId}/filter +- [ ] PUT - /_matrix/client/r0/rooms/{roomId}/redact/{eventId}/{txnId} +- [X] PUT - /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId} +- [ ] PUT - /_matrix/client/r0/rooms/{roomId}/state/{eventType} +- [X] PUT - /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} - [ ] PUT - /_matrix/client/r0/rooms/{roomId}/typing/{userId} ## Search @@ -126,37 +127,37 @@ from matrix.org. This will give you an overview about what's implemented in the ## Server administration - [ ] GET - /.well-known/matrix/client -- [ ] GET - /_matrix/client/versions - [ ] GET - /_matrix/client/r0/admin/whois/{userId} +- [ ] GET - /_matrix/client/versions ## Session management -- [x] POST - /_matrix/client/r0/logout - [ ] GET - /_matrix/client/r0/login -- [x] POST - /_matrix/client/r0/login +- [ ] POST - /_matrix/client/r0/login +- [X] POST - /_matrix/client/r0/logout - [ ] POST - /_matrix/client/r0/logout/all ## User data -- [ ] POST - /_matrix/client/r0/account/password -- [ ] POST - /_matrix/client/r0/user_directory/search -- [ ] PUT - /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type} -- [x] GET - /_matrix/client/r0/profile/{userId}/displayname -- [x] PUT - /_matrix/client/r0/profile/{userId}/displayname -- [x] GET - /_matrix/client/r0/profile/{userId}/avatar_url -- [x] PUT - /_matrix/client/r0/profile/{userId}/avatar_url -- [x] GET - /_matrix/client/r0/account/whoami -- [ ] GET - /_matrix/client/r0/register/available -- [x] POST - /_matrix/client/r0/register -- [x] GET - /_matrix/client/r0/profile/{userId} +- [X] DELETE - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} - [ ] GET - /_matrix/client/r0/account/3pid +- [X] GET - /_matrix/client/r0/account/whoami +- [X] GET - /_matrix/client/r0/profile/{userId} +- [X] GET - /_matrix/client/r0/profile/{userId}/avatar_url +- [X] GET - /_matrix/client/r0/profile/{userId}/displayname +- [ ] GET - /_matrix/client/r0/register/available +- [ ] GET - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags - [ ] POST - /_matrix/client/r0/account/3pid -- [ ] PUT - /_matrix/client/r0/user/{userId}/account_data/{type} -- [X] PUT - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} -- [X] DELETE - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} -- [X] GET - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags -- [ ] POST - /_matrix/client/r0/account/deactivate - [ ] POST - /_matrix/client/r0/account/3pid/delete +- [ ] 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}/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} ## VOIP diff --git a/scripts/load-docs.p6 b/scripts/load-docs.p6 index d3a1f81..c6736d7 100755 --- a/scripts/load-docs.p6 +++ b/scripts/load-docs.p6 @@ -1,7 +1,9 @@ #!/usr/bin/env perl6 use v6; +use lib ; use HTTP::UserAgent; use JSON::Fast; +use Matrix::Client; sub get-api-docs { my $url = "https://matrix.org/docs/api/client-server/json/api-docs.json"; @@ -32,19 +34,34 @@ sub get-api-docs { sub MAIN(:$spec?) { my %tags = get-api-docs; + my $implemented-methods = (Matrix::Client, Matrix::Client::Room).map(*.^methods) + .flat.map( + { + quietly try { .WHY.Str } or "" + }).grep(/_matrix/).SetHash; + .say for $implemented-methods; + say q:to/EOF/; + # List of implemented endpoints + + This list was generated by the `load-docs.p6` script that gets the data + from the [api-docs.json](https://matrix.org/docs/api/client-server/json/api-docs.json) + from matrix.org. This will give you an overview about what's implemented in the library. + EOF + for %tags.sort -> $pair { my $tag = $pair.key; my $methods = $pair.value; say qq:to/EOF/; - # $tag + ## $tag EOF - for $methods.Seq -> $m { - my Str $method = $m; + for $methods.Seq.sort -> $m { + my Str $method = $m.trim; + my $checked = $implemented-methods{$m} ?? "X" !! " "; if $spec { $method = $m.subst(/unstable/, $spec) } - say "- [ ] " ~ $method; + say "- [$checked] " ~ $method; } say ""; } -- cgit v1.2.3-70-g09d2 From ecf602241f38552132e16d44a8871232b23f2b1e Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Wed, 5 Jun 2019 00:30:56 -0300 Subject: Add POD declarators --- lib/Matrix/Client.pm6 | 27 ++++++++++++++++++++++++++- lib/Matrix/Client/Room.pm6 | 7 +++++++ 2 files changed, 33 insertions(+), 1 deletion(-) 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; } +#| 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 // "" } +#| 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 // "" } +#| 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) } +#| GET - /_matrix/client/r0/directory/room/{roomAlias} method get-room-id($room-alias) { my $res = $.get("/directory/room/$room-alias"); from-json($res.content) } +#| 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; } +#| GET - /_matrix/client/r0/rooms/{roomId}/joined_members method joined-members { my %data = from-json($.get("/joined_members").content); %data @@ -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.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) } +#| 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) } +#| POST - /_matrix/client/r0/rooms/{roomId}/leave method leave() { $.post('/leave') } -- cgit v1.2.3-70-g09d2 From 6f12086338bcb4fefbef374710449f364a2faf0f Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Wed, 5 Jun 2019 00:33:51 -0300 Subject: Remove debug information --- endpoints.md | 1 - scripts/load-docs.p6 | 1 - 2 files changed, 2 deletions(-) diff --git a/endpoints.md b/endpoints.md index 1d5be92..9abcf1a 100644 --- a/endpoints.md +++ b/endpoints.md @@ -1,4 +1,3 @@ -SetHash(DELETE - /_matrix/client/r0/directory/room/{roomAlias} DELETE - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} GET - /_matrix/client/r0/account/whoami GET - /_matrix/client/r0/directory/room/{roomAlias} GET - /_matrix/client/r0/joined_rooms GET - /_matrix/client/r0/presence/{userId}/status GET - /_matrix/client/r0/profile/{userId} GET - /_matrix/client/r0/profile/{userId}/avatar_url GET - /_matrix/client/r0/profile/{userId}/displayname GET - /_matrix/client/r0/publicRooms GET - /_matrix/client/r0/rooms/{roomId}/joined_members GET - /_matrix/client/r0/rooms/{roomId}/messages POST - /_matrix/client/r0/createRoom POST - /_matrix/client/r0/join/{roomIdOrAlias} POST - /_matrix/client/r0/logout POST - /_matrix/client/r0/register POST - /_matrix/client/r0/rooms/{roomId}/leave POST - /_matrix/media/r0/upload PUT - /_matrix/client/r0/directory/room/{roomAlias} PUT - /_matrix/client/r0/presence/{userId}/status PUT - /_matrix/client/r0/profile/{userId}/displayname PUT - /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId} PUT - /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey}) # List of implemented endpoints This list was generated by the `load-docs.p6` script that gets the data diff --git a/scripts/load-docs.p6 b/scripts/load-docs.p6 index c6736d7..b20dd86 100755 --- a/scripts/load-docs.p6 +++ b/scripts/load-docs.p6 @@ -39,7 +39,6 @@ sub MAIN(:$spec?) { { quietly try { .WHY.Str } or "" }).grep(/_matrix/).SetHash; - .say for $implemented-methods; say q:to/EOF/; # List of implemented endpoints -- cgit v1.2.3-70-g09d2 From 4c007e0df300e7fb281fcadbcf707b71ed7e2483 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Wed, 5 Jun 2019 00:44:43 -0300 Subject: Get old README --- README.md | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index e629915..43c1aac 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,26 @@ -### multi method tags +# Matrix client -```perl6 -multi method tags( - Str $room-id, - Str:D $tag, - $order -) returns Mu -``` +A perl 6 library for [Matrix](https://matrix.org). -PUT - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} +## Status -### multi method tags +This project is in early development. A lot of methods return a raw +`HTTP::Response` and not something from this library. -```perl6 -multi method tags( - Str $room-id -) returns Mu -``` +## Examples -GET - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags +From the `examples` directory: -### method remove-tag + use v6; + use Matrix::Client; -```perl6 -method remove-tag( - Str $room-id, - Str:D $tag -) returns Mu -``` + # Instantiate a new client for a given home-server + my $client = Matrix::Client.new: :home-server + # Login + $client.login: @*ARGS[0], @*ARGS[1]; -DELETE - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} + # Show all joined rooms + say $client.rooms(:sync); + # And finally logout. + $client.logout -- cgit v1.2.3-70-g09d2