ool::Command::client::json;
use strict;
use warnings;
use base qw( App::MatrixTool::Command::client );
our $VERSION = '0.08';
use constant DESCRIPTION => "Perform a direct JSON request";
use consta
"HTTP method",
);
=head1 NAME
matrixtool client json - Perform a direct JSON request
=head1 SYNOPSIS
$ matrixtool client -u @me:example.com json /_matrix/client/r0/publicRooms
=head1 DESCRIPTI
ould
contain a JSON encoding of data to supply with the request, turning it into a
C<PUT> request. If no data is supplied, then a C<GET> request is performed
instead.
The resulting JSON data from the
die "Type not specified and could not guess it from the filename\n";
}
$self->do_json( POST => "/_matrix/media/r0/upload",
content => $content,
content_type => $type,
)
tomatically supply this
access token on every request:
$ matrixtool client -u @me:example.com json /_matrix/client/r0/publicRooms
...
=head1 OPTIONS
The following additional options are recog
sub-commands are recognised
=head2 json
Perform a direct JSON request
$ matrixtool client json PATH [DATA]
See also L<App::MatrixTool::Command::client::json>.
=head2 login
Obtain a client au
{$_} for qw( server user_id user_id_parameter );
return $self->SUPER::run( @args );
}
sub do_json
{
my $self = shift;
my ( $method, $path, %opts ) = @_;
my $client = $self->http_client;
DNS 0.06 qw( ERR_NO_HOST ERR_NO_ADDRESS ); # Future return with failure details
use JSON qw( encode_json decode_json );
use URI;
use Socket qw( getnameinfo NI_NUMERICHOST SOCK_RAW );
use constant DE
ef $params{content} ) {
$req->content( encode_json( delete $params{content} ) );
$req->header( Content_type => "application/json" );
}
else {
$req->content( dele
);
}
=head2 request_json
( $body, $response ) = $client->request_json( ... )
A small wrapper around C<request> that decodes the returned body as JSON.
=cut
sub request_json
{
my $self = shi
);
our $VERSION = '0.08';
use MIME::Base64 qw( decode_base64 );
use Protocol::Matrix qw( verify_json_signature );
use Net::Async::HTTP;
Net::Async::HTTP->VERSION( '0.40' ); # ->request on_ready
us
$self = shift;
my ( $server_name ) = @_;
my $server_cert;
$self->http_client->request_json(
server => $server_name,
request => $self->federation->make_key_v1_request(
$self = shift;
my ( $server_name ) = @_;
my $server_cert;
$self->http_client->request_json(
server => $server_name,
request => $self->federation->make_key_v2_server_request(
);
our $VERSION = '0.08';
use MIME::Base64 qw( decode_base64 );
use Protocol::Matrix qw( verify_json_signature );
use constant DESCRIPTION => "Fetch a server's signing key via another server";
use
tary_v2
{
my $self = shift;
my ( $server_name, $via ) = @_;
$self->http_client->request_json(
method => "GET",
server => $via,
path => "/_matrix/key/v2/query/$server_name
);
next unless defined $signing_key;
my $verified = eval { verify_json_signature( $result,
public_key => $signing_key,
origin =>
(.*)$/ or
return Future->fail( "Cannot parse room alias" );
$self->http_client->request_json(
method => "GET",
server => $server,
path => "/_matrix/client/r0/directory/ro
sub run
{
my $self = shift;
my ( $opts ) = @_;
my $token;
repeat {
$self->do_json( GET => "/_matrix/client/r0/sync",
params => {
timeout => 30*1000,
if( defined $token or $opts->{initial} ) {
print "---\n";
print $self->JSON_pretty->encode( $body );
}
$token = $body->{next_batch};
Future->done
presence.
# See also
# https://github.com/matrix-org/matrix-doc/issues/734
$self->do_json( GET => "/_matrix/client/r0/sync",
params => {
filter =>
'{"room":{' .
word = <$stdin>; chomp $password; print "\n";
$stdin->setflag_echo( 1 );
}
$self->do_json( POST => "/_matrix/client/r0/login",
content => {
type => "m.login.password",
Struct::Dumb qw( readonly_struct );
use Protocol::Matrix::HTTP::Federation;
require JSON;
my $JSON_pretty = JSON->new->utf8(1)->pretty(1);
my $opt_parser = Getopt::Long::Parser->new(
config => [
encode => "raw", # client tokens are already base64 encoded
);
};
}
sub JSON_pretty { $JSON_pretty }
## Builtin commands
package
App::MatrixTool::Command::help;
use base qw( Ap