summaryrefslogtreecommitdiff
path: root/lib/Matrix/Client.pm6
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@openmailbox.org>2017-04-04 23:07:38 -0300
committerMatias Linares <matiaslina@openmailbox.org>2017-04-04 23:07:38 -0300
commit1f404d2a36c2ac71a889dc241feac8430c330fab (patch)
treee4512cc3baca408e5307a0daf546a2204d58bedd /lib/Matrix/Client.pm6
parent0406e01a54dd3217ec7d518aae499268b41c4834 (diff)
downloadperl6-matrix-client-1f404d2a36c2ac71a889dc241feac8430c330fab.tar.gz
Add Profile and methods
Diffstat (limited to 'lib/Matrix/Client.pm6')
-rw-r--r--lib/Matrix/Client.pm661
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/Matrix/Client.pm6 b/lib/Matrix/Client.pm6
index 6849fe4..8fc9e6a 100644
--- a/lib/Matrix/Client.pm6
+++ b/lib/Matrix/Client.pm6
@@ -92,6 +92,55 @@ method check-res($res) {
}
}
+# User Data
+
+method profile(Str :$user-id?) {
+ my $id = $user-id // $!user-id;
+ my $res = $.get("/profile/" ~ $id);
+ $.check-res($res);
+ $res
+}
+
+method display-name(Str :$user-id?) {
+ my $id = $user-id // $!user-id;
+ my $res = $.get("/profile/" ~ $id ~ "/displayname");
+ $.check-res($res);
+
+ my $data = from-json($res.content);
+
+ $data<displayname> // ""
+}
+
+method change-display-name(Str:D $display-name!) {
+ my $res = $.put("/profile/" ~ $!user-id ~ "/displayname",
+ displayname => $display-name);
+ return $.check-res($res);
+}
+
+method avatar-url(Str :$user-id?) {
+ my $id = $user-id // $!user-id;
+ my $res = $.get("/profile/" ~ $id ~ "/avatar_url");
+ $.check-res($res);
+ my $data = from-json($res.content);
+
+ $data<avatar_url> // ""
+}
+
+method change-avatar(Str:D $avatar!, Bool :$upload) {
+ my $mxc-url;
+ if so $upload {
+ $mxc-url = $.upload($avatar);
+ } else {
+ $mxc-url = $avatar;
+ }
+
+ my $res = $.put("/profile/" ~ $!user-id ~ "/avatar_url",
+ avatar_url => $mxc-url);
+ return $.check-res($res);
+}
+
+# Syncronization
+
multi method sync() {
my $res = $.get("/sync",
timeout => 30000
@@ -116,6 +165,8 @@ multi method sync(:$sync-filter is copy, :$since = "") {
$.sync(sync-filter => to-json($sync-filter), since => $since)
}
+# Rooms
+
method join-room($room-id!) {
$.post("/join/" ~ $room-id)
}
@@ -136,3 +187,13 @@ method send(Str $room-id, Str $body, :$type? = "m.text") {
$Matrix::Client::Common::TXN-ID++;
$.put("/rooms/$room-id/send/m.room.message/{$Matrix::Client::Common::TXN-ID}", msgtype => $type, body => $body)
}
+
+# Media
+
+method upload(Str $path where *.IO.f) {
+ my $buf = slurp $path, :bin;
+ my $res = $.post-bin("/upload", $buf, content-type => "image/png");
+ $.check-res($res);
+ my $data = from-json($res.content);
+ $data<content_uri> // "";
+}