App-MatrixTool

 view release on metacpan or  search on metacpan

lib/App/MatrixTool/Command/client.pm  view on Meta::CPAN


=head1 OPTIONS

The following additional options are recognised

=over 4

=item C<--user-id>, C<-u>

User ID to supply the C<access_token> of.

=item C<--user-id-parameter>, C<-U>

User ID to set as the value of the C<user_id> HTTP query parameter. This is
usually only useful for controlling application service ghosted users.

=item C<--server>, C<-s>

Server to connect to. Usually optional, as it is implied by the C<user-id> if
provided.

=back

=head1 COMMANDS

The following 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 authentication token

   $ matrixtool client login USER-ID

See also L<App::MatrixTool::Command::client::login>.

=head2 upload

Upload a file to the media repository

   $ matrixtool client upload FILE [TYPE]

See also L<App::MatrixTool::Command::client::upload>.

=cut

sub run
{
   my $self = shift;
   my ( $opts, @args ) = @_;

   $self->{$_} //= $opts->{$_} 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;

   if( my $user_id = $self->{user_id} ) {
      my ( $server ) = $user_id =~ m/^@.*?:(.*)$/;
      $self->{server} //= $server;
   }

   defined $self->{server} or
      die "Not sure what --server to use\n";

   if( $self->{server} && $self->{user_id} ) {
      my $token = $self->client_token_store->get(
         server => $self->{server},
         id     => $self->{user_id},
      );

      $opts{params}{access_token} = $token if defined $token;
   }

   if( $self->{user_id_parameter} ) {
      $opts{params}{user_id} //= $self->{user_id_parameter};
   }

   $client->request_json(
      server => $self->{server},
      method => $method,
      path   => $path,
      %opts,
   );
}

=head1 AUTHOR

Paul Evans <leonerd@leonerd.org.uk>

=cut

0x55AA;



( run in 1.976 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )