aboutsummaryrefslogtreecommitdiff
path: root/lib/Matrix/Client
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
parent0406e01a54dd3217ec7d518aae499268b41c4834 (diff)
downloadperl6-matrix-client-1f404d2a36c2ac71a889dc241feac8430c330fab.tar.gz
Add Profile and methods
Diffstat (limited to 'lib/Matrix/Client')
-rw-r--r--lib/Matrix/Client/Requester.pm626
1 files changed, 18 insertions, 8 deletions
diff --git a/lib/Matrix/Client/Requester.pm6 b/lib/Matrix/Client/Requester.pm6
index c2ba865..ec9a2d1 100644
--- a/lib/Matrix/Client/Requester.pm6
+++ b/lib/Matrix/Client/Requester.pm6
@@ -12,31 +12,41 @@ has $!url-prefix = "";
has $!access-token = "";
has $!sync-since = "";
-method get(Str $path, *%data) {
+method get(Str $path, :$media = False, *%data) {
my $q = "$path?access_token=$!access-token";
for %data.kv -> $k,$v {
$q ~= "&$k=$v" unless $v eq "";
}
- my $uri = uri_encode($.base-url ~ $q);
+ my $uri = uri_encode($.base-url($media) ~ $q);
$!ua.history = [];
$!ua.get($uri)
}
-method base-url(--> Str) {
- "$.home-server$!client-endpoint$!url-prefix"
+method base-url(Bool :$media? = False --> Str) {
+ if !$media {
+ "$.home-server$!client-endpoint$!url-prefix"
+ } else {
+ "$.home-server/_matrix/media/r0"
+ }
}
-multi method post(Str $path, Str $json) {
- my $req = HTTP::Request.new(POST => $.base-url() ~ $path ~ "?access_token=$!access-token",
+multi method post(Str $path, Str $json, :$media = False) {
+ my $req = HTTP::Request.new(POST => $.base-url(:$media) ~ $path ~ "?access_token=$!access-token",
Content-Type => 'application/json');
$req.add-content($json);
$!ua.history = [];
$!ua.request($req)
}
-multi method post(Str $path, *%params) {
- self.post($path, to-json(%params))
+method post-bin(Str $path, Buf $buf, :$content-type) {
+ my $req = POST($.base-url(:media) ~ $path ~ "?access_token=$!access-token", content => $buf, Content-Type => $content-type);
+ $!ua.history = [];
+ $!ua.request($req)
+}
+
+multi method post(Str $path, :$media = False, *%params) {
+ self.post($path, :$media, to-json(%params))
}
multi method put(Str $path,Str $json) {