aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@gmail.com>2019-06-05 00:46:00 -0300
committerMatias Linares <matiaslina@gmail.com>2019-06-05 00:46:00 -0300
commitbc6c791c72f9fe460fdb9559522ae154124e8e97 (patch)
treea6be2f25368a6c8dc6df95a9db4fc4da16ac1c77
parent2d54d1357deacf23c53bde9b521d464fc2fcb15e (diff)
parent4c007e0df300e7fb281fcadbcf707b71ed7e2483 (diff)
downloadperl6-matrix-client-bc6c791c72f9fe460fdb9559522ae154124e8e97.tar.gz
Merge branch 'master' into documentation
-rw-r--r--.gitignore1
-rw-r--r--META6.json63
-rw-r--r--endpoints.md118
-rw-r--r--lib/Matrix/Client.pm645
-rw-r--r--lib/Matrix/Client/Room.pm633
-rw-r--r--lib/Matrix/Response.pm69
-rwxr-xr-xscripts/load-docs.p624
7 files changed, 199 insertions, 94 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/endpoints.md b/endpoints.md
index c4aeace..9abcf1a 100644
--- a/endpoints.md
+++ b/endpoints.md
@@ -11,26 +11,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 +38,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 +65,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
-- [ ] 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] 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 +126,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
+- [ ] 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}
-- [ ] DELETE - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag}
-- [ ] GET - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags
-- [ ] POST - /_matrix/client/r0/account/deactivate
-- [ ] POST - /_matrix/client/r0/account/3pid/delete
## VOIP
diff --git a/lib/Matrix/Client.pm6 b/lib/Matrix/Client.pm6
index 5f52779..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,23 +116,45 @@ 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));
}
+#| 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
+#| 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,
@@ -133,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)
@@ -140,6 +173,7 @@ multi method sync(:$since = "") {
# Rooms
+#| POST - /_matrix/client/r0/createRoom
method create-room(
Bool :$public = False,
*%args --> Matrix::Client::Room
@@ -163,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);
@@ -183,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(
@@ -197,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 fa4501a..4ec774f 100644
--- a/lib/Matrix/Client/Room.pm6
+++ b/lib/Matrix/Client/Room.pm6
@@ -25,11 +25,34 @@ method !get-name() {
$!name = $data<name>;
}
-method name() {
- unless $!name.so { self!get-name() }
+#| GET - /_matrix/client/r0/rooms/{roomId}/joined_members
+method joined-members {
+ my %data = from-json($.get("/joined_members").content);
+ %data<joined>
+}
+
+method name {
+ self!get-name;
+
$!name
}
+method fallback-name(--> Str) {
+ my @members = $.joined-members.kv.map(
+ -> $k, %v {
+ %v<display_name> // $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" }
+ };
+}
+
+#| GET - /_matrix/client/r0/rooms/{roomId}/messages
method messages() {
my $res = $.get("/messages");
my $data = from-json($res.content);
@@ -37,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(
@@ -47,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);
@@ -55,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",
@@ -67,7 +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')
}
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<tags>.keys;
+ self.bless(:@tags)
+ }
+}
diff --git a/scripts/load-docs.p6 b/scripts/load-docs.p6
index d3a1f81..b20dd86 100755
--- a/scripts/load-docs.p6
+++ b/scripts/load-docs.p6
@@ -1,7 +1,9 @@
#!/usr/bin/env perl6
use v6;
+use lib <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,33 @@ 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 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 "";
}