« blib/lib/App/MatrixTool/Command/resolve.pm
↑ Summary
blib/lib/App/MatrixTool/Command/client/login.pm »
| 1 | # You may distribute under the terms of either the GNU General Public License | ||||||||||
| 2 | # or the Artistic License (the same terms as Perl itself) | ||||||||||
| 3 | # | ||||||||||
| 4 | # (C) Paul Evans, 2016 -- leonerd@leonerd.org.uk | ||||||||||
| 5 | |||||||||||
| 6 | package App::MatrixTool::Command::directory; | ||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use base qw( App::MatrixTool ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | use URI::Escape qw( uri_escape ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 1 | our $VERSION = '0.06'; | |||||||||
| 15 | |||||||||||
| 16 | 1 | ▶ | use constant DESCRIPTION => "Look up room alias to room ID entries"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 1 | ▶ | use constant ARGUMENTS => ( "alias" ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 1 | use constant OPTIONS => ( | |||||||||
| 19 | 's|servers' => 'Include list of candidate servers', | ||||||||||
| 20 | 1 | ▶ | ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | =head1 NAME | ||||||||||
| 23 | |||||||||||
| 24 | matrixtool directory - Look up room alias to room ID entries | ||||||||||
| 25 | |||||||||||
| 26 | =head1 SYNOPSIS | ||||||||||
| 27 | |||||||||||
| 28 | $ matrixtool directory '#matrix:matrix.org' | ||||||||||
| 29 | |||||||||||
| 30 | =head1 DESCRIPTION | ||||||||||
| 31 | |||||||||||
| 32 | This command queries the room directory service on a homeserver to map a room | ||||||||||
| 33 | alias name into a room ID. As this is a fully public API that does not need an | ||||||||||
| 34 | access token, this command is separate from C<matrixtool client>. | ||||||||||
| 35 | |||||||||||
| 36 | =head1 OPTIONS | ||||||||||
| 37 | |||||||||||
| 38 | The following additional options are recognised | ||||||||||
| 39 | |||||||||||
| 40 | =over 4 | ||||||||||
| 41 | |||||||||||
| 42 | =item C<--servers>, C<-s> | ||||||||||
| 43 | |||||||||||
| 44 | Include a list of candidate servers in the output. | ||||||||||
| 45 | |||||||||||
| 46 | =back | ||||||||||
| 47 | |||||||||||
| 48 | =cut | ||||||||||
| 49 | |||||||||||
| 50 | sub run | ||||||||||
| 51 | { | ||||||||||
| 52 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
run: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 53 | 0 | my ( $opts, $alias ) = @_; | |||||||||
| 54 | |||||||||||
| 55 | 0 | ▶ | my ( $server ) = $alias =~ m/^\#[^:]*:(.*)$/ or | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | return Future->fail( "Cannot parse room alias" ); | ||||||||||
| 57 | |||||||||||
| 58 | $self->http_client->request_json( | ||||||||||
| 59 | method => "GET", | ||||||||||
| 60 | server => $server, | ||||||||||
| 61 | path => "/_matrix/client/r0/directory/room/" . uri_escape( $alias ), | ||||||||||
| 62 | )->then( sub { | ||||||||||
| 63 | 0 | ▶ | my ( $body ) = @_; | ||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||
| 64 | |||||||||||
| 65 | 0 | my $room_id = $body->{room_id}; | |||||||||
| 66 | |||||||||||
| 67 | 0 | $self->output( "room_id: " . $room_id ); | |||||||||
| 68 | |||||||||||
| 69 | 0 | ▶ | if( $opts->{servers} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 0 | my $servers = $body->{servers}; | |||||||||
| 71 | |||||||||||
| 72 | 0 | $self->output( "candidate servers:" ); | |||||||||
| 73 | 0 | $self->output( " $_" ) for @$servers; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 0 | Future->done; | |||||||||
| 77 | 0 | }); | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | =head1 EXAMPLES | ||||||||||
| 81 | |||||||||||
| 82 | For example, resolving a room alias into a room ID: | ||||||||||
| 83 | |||||||||||
| 84 | $ matrixtool directory '#matrix:matrix.org' | ||||||||||
| 85 | room_id: !cURbafjkfsMDVwdRDQ:matrix.org | ||||||||||
| 86 | |||||||||||
| 87 | Additionally a list of join candidate servers can also be printed: | ||||||||||
| 88 | |||||||||||
| 89 | room_id: !cURbafjkfsMDVwdRDQ:matrix.org | ||||||||||
| 90 | candidate servers: | ||||||||||
| 91 | matrix.org | ||||||||||
| 92 | ... | ||||||||||
| 93 | |||||||||||
| 94 | =head1 AUTHOR | ||||||||||
| 95 | |||||||||||
| 96 | Paul Evans <leonerd@leonerd.org.uk> | ||||||||||
| 97 | |||||||||||
| 98 | =cut | ||||||||||
| 99 | |||||||||||
| 100 | 1 | 0x55AA; | |||||||||