App-MatrixTool
view release on metacpan or search on metacpan
lib/App/MatrixTool/Command/client/json.pm view on Meta::CPAN
This command performs a direct low-level HTTP request to a Matrix homeserver.
The server name part of the URL is automatically inferred from the given user
ID; the I<PATH> commandline argument only requires the path and optional query
parameters. If an access token is known for the user (see
C<matrixtool client login>) then it is automatically added to the query
parameters as well.
An optional second argument, I<DATA>, may be provided. If so, this should
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 homeserver is parsed and re-printed in a more
human-readable form to standard output. Linefeeds and indentation whitespace
are used to increase readability.
=head1 OPTIONS
=over 4
=item C<--method>, C<-m>
Use a different HTTP method. If not specified, C<GET> or C<PUT> will be
performed, depending on whether the I<DATA> argument was supplied.
=back
=cut
sub run
{
my $self = shift;
my ( $opts, $pathquery, $data ) = @_;
my $method = "GET";
$method = "PUT" if defined $data;
$method = $opts->{method} if defined $opts->{method};
my %opts;
$opts{content} = $self->JSON_pretty->decode( $data ) if defined $data;
my $uri = URI->new( $pathquery );
if( $uri->query_form ) {
$opts{params} = { $uri->query_form };
lib/App/MatrixTool/Command/client/json.pm view on Meta::CPAN
For example, directly querying your user profile data:
$ matrixtool client -u @me:example.com json \
/_matrix/client/r0/profile/@me:example.com
{
"avatar_url": "mxc://example.com/aBcDeFgHiJ...",
"displayname": "Mr Example",
}
By supplying a second parameter containing JSON-encoded data, we can perform
a C<PUT> request to update the displayname:
$ matrixtool client -u @me:example.com json \
/_matrix/client/r0/profile/@me:example.com/displayname \
'{"displayname":"Mr. Example"}'
{}
=cut
=head1 AUTHOR
( run in 0.583 second using v1.01-cache-2.11-cpan-c6e0e5ac2a7 )