summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@gmail.com>2019-06-29 19:04:10 -0300
committerMatias Linares <matiaslina@gmail.com>2019-06-29 19:04:10 -0300
commit82a19be633aafd305fab93c7e3ea660656ae441a (patch)
tree321f18e9311b8f45cb986130c8d2c2b068ab3506
parent4f9159b228cb2533eccab11f82690171a1484ee5 (diff)
downloadperl6-matrix-client-82a19be633aafd305fab93c7e3ea660656ae441a.tar.gz
Add device management endpoints
Missing delete methods only
-rw-r--r--endpoints.md20
-rw-r--r--lib/Matrix/Client.pm625
-rw-r--r--lib/Matrix/Response.pm615
3 files changed, 53 insertions, 7 deletions
diff --git a/endpoints.md b/endpoints.md
index 8b22289..2ddf2c3 100644
--- a/endpoints.md
+++ b/endpoints.md
@@ -8,13 +8,17 @@ from matrix.org. This will give you an overview about what's implemented in the
- [ ] PUT - /_matrix/client/r0/directory/list/appservice/{networkId}/{roomId}
+## Capabilities
+
+- [ ] GET - /_matrix/client/r0/capabilities
+
## Device management
- [ ] DELETE - /_matrix/client/r0/devices/{deviceId}
-- [ ] GET - /_matrix/client/r0/devices
-- [ ] GET - /_matrix/client/r0/devices/{deviceId}
+- [X] GET - /_matrix/client/r0/devices
+- [X] GET - /_matrix/client/r0/devices/{deviceId}
- [ ] POST - /_matrix/client/r0/delete_devices
-- [ ] PUT - /_matrix/client/r0/devices/{deviceId}
+- [X] PUT - /_matrix/client/r0/devices/{deviceId}
## End-to-end encryption
@@ -38,9 +42,7 @@ from matrix.org. This will give you an overview about what's implemented in the
## Presence
-- [ ] 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
@@ -103,7 +105,6 @@ from matrix.org. This will give you an overview about what's implemented in the
- [ ] GET - /_matrix/client/r0/rooms/{roomId}/members
- [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}
@@ -111,10 +112,13 @@ from matrix.org. This will give you an overview about what's implemented in the
- [ ] 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}
+## Room ugprades
+
+- [ ] POST - /_matrix/client/r0/rooms/{roomId}/upgrade
+
## Search
- [ ] POST - /_matrix/client/r0/search
@@ -145,6 +149,8 @@ from matrix.org. This will give you an overview about what's implemented in the
- [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}/account_data/{type}
+- [ ] GET - /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}
- [ ] GET - /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags
- [ ] POST - /_matrix/client/r0/account/3pid
- [ ] POST - /_matrix/client/r0/account/3pid/delete
diff --git a/lib/Matrix/Client.pm6 b/lib/Matrix/Client.pm6
index 1a24790..d7206b0 100644
--- a/lib/Matrix/Client.pm6
+++ b/lib/Matrix/Client.pm6
@@ -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;
diff --git a/lib/Matrix/Response.pm6 b/lib/Matrix/Response.pm6
index edd4d51..14e2b21 100644
--- a/lib/Matrix/Response.pm6
+++ b/lib/Matrix/Response.pm6
@@ -122,3 +122,18 @@ class Tag {
self.bless(:@tags)
}
}
+
+
+class Matrix::Response::Device {
+ has Str $.device-id;
+ has $.display-name;
+ has $.last-seen-ip;
+ has $.last-seen-ts;
+
+ submethod BUILD(
+ Str :device_id(:$!device-id),
+ :display_name(:$!display-name)?,
+ :last_seen_ip(:$!last-seen-ip)?,
+ :last_seen_ts(:$!last-seen-ts)?
+ ) { }
+}