App-MatrixTool

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

        [CHANGES]
         * Much expanded documentation
         * Improved 'help' command's handling of subcommands

        [BUGFIXES]
         * Fix typo in "image/png" MIME type
         * Treat ERR_NO_ADDRESS DNS errors the same as ERR_NO_HOST

0.05    2016/09/23 19:59:34
        [CHANGES]
         * Implement 'client upload' for uploading content to media repo
         * Allow 'client json' to take query parameters

        [BUGFIXES]
         * Fix unit tests for renamed module

0.04    2016/09/14 21:02:35
        [CHANGES]
         * Initial attempt at a 'client' subcommand structure; added
           'client json' and 'client login'
         * Added 'directory' command for interfacing with public directory

MANIFEST  view on Meta::CPAN

bin/matrixtool
Build.PL
Changes
lib/App/MatrixTool.pm
lib/App/MatrixTool/Command/client.pm
lib/App/MatrixTool/Command/client/json.pm
lib/App/MatrixTool/Command/client/list_rooms.pm
lib/App/MatrixTool/Command/client/login.pm
lib/App/MatrixTool/Command/client/sync.pm
lib/App/MatrixTool/Command/client/upload.pm
lib/App/MatrixTool/Command/directory.pm
lib/App/MatrixTool/Command/notary.pm
lib/App/MatrixTool/Command/resolve.pm
lib/App/MatrixTool/Command/server_key.pm
lib/App/MatrixTool/HTTPClient.pm
lib/App/MatrixTool/ServerIdStore.pm
lib/App/MatrixTool/SubCommands.pm
LICENSE
Makefile.PL
MANIFEST			This list of files

META.json  view on Meta::CPAN

         "version" : "0.08"
      },
      "App::MatrixTool::Command::client::login" : {
         "file" : "lib/App/MatrixTool/Command/client/login.pm",
         "version" : "0.08"
      },
      "App::MatrixTool::Command::client::sync" : {
         "file" : "lib/App/MatrixTool/Command/client/sync.pm",
         "version" : "0.08"
      },
      "App::MatrixTool::Command::client::upload" : {
         "file" : "lib/App/MatrixTool/Command/client/upload.pm",
         "version" : "0.08"
      },
      "App::MatrixTool::Command::directory" : {
         "file" : "lib/App/MatrixTool/Command/directory.pm",
         "version" : "0.08"
      },
      "App::MatrixTool::Command::notary" : {
         "file" : "lib/App/MatrixTool/Command/notary.pm",
         "version" : "0.08"
      },

META.yml  view on Meta::CPAN

    version: '0.08'
  App::MatrixTool::Command::client::list_rooms:
    file: lib/App/MatrixTool/Command/client/list_rooms.pm
    version: '0.08'
  App::MatrixTool::Command::client::login:
    file: lib/App/MatrixTool/Command/client/login.pm
    version: '0.08'
  App::MatrixTool::Command::client::sync:
    file: lib/App/MatrixTool/Command/client/sync.pm
    version: '0.08'
  App::MatrixTool::Command::client::upload:
    file: lib/App/MatrixTool/Command/client/upload.pm
    version: '0.08'
  App::MatrixTool::Command::directory:
    file: lib/App/MatrixTool/Command/directory.pm
    version: '0.08'
  App::MatrixTool::Command::notary:
    file: lib/App/MatrixTool/Command/notary.pm
    version: '0.08'
  App::MatrixTool::Command::resolve:
    file: lib/App/MatrixTool/Command/resolve.pm
    version: '0.08'

bin/matrixtool  view on Meta::CPAN

=over 4

=item * --initial (-i)

Print the initial sync result too

=back

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

=head2 client upload

Upload a file to the media repository

   $ matrixtool client upload FILE [TYPE]

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

=head2 directory

Look up room alias to room ID entries

   $ matrixtool directory ALIAS

Options:

=over 4

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

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 );

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

#  You may distribute under the terms of either the GNU General Public License
#  or the Artistic License (the same terms as Perl itself)
#
#  (C) Paul Evans, 2016 -- leonerd@leonerd.org.uk

package App::MatrixTool::Command::client::upload;

use strict;
use warnings;
use base qw( App::MatrixTool::Command::client );

our $VERSION = '0.08';

use File::Slurper qw( read_binary );

use constant DESCRIPTION => "Upload a file to the media repository";
use constant ARGUMENTS => ( "file", "type?" );
use constant OPTIONS => ();

=head1 NAME

matrixtool client upload - Upload a file to the media repository

=head1 SYNOPSIS

   $ matrixtool client -u @me:example.com upload avatar.png

=head1 DESCRIPTION

This command uploads a file to the media repository of a Matrix homeserver,
printing the returned F<mxc://> URL.

Normally the MIME type must be supplied as a second argument, but in the
common case of files whose names end in certain recognised file extensions,
the MIME type can be automatically inferred for convenience.

The recognised extensions are

   .jpg, .jpeg     image/jpeg
   .png            image/png

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

   my $content = read_binary( $file );

   unless( defined $type ) {
      $type = "image/jpeg" if $file =~ m/\.jp[e]?g$/;
      $type = "image/png"  if $file =~ m/\.png$/;

      defined $type or
         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,
   )->then( sub {
      my ( $result ) = @_;

      $self->output_ok( "Uploaded content" );

      print $result->{content_uri} . "\n";

      Future->done();

t/00use.t  view on Meta::CPAN

use_ok( "App::MatrixTool" );

use_ok( "App::MatrixTool::HTTPClient" );
use_ok( "App::MatrixTool::ServerIdStore" );

use_ok( "App::MatrixTool::Command::client" );
use_ok( "App::MatrixTool::Command::client::json" );
use_ok( "App::MatrixTool::Command::client::list_rooms" );
use_ok( "App::MatrixTool::Command::client::login" );
use_ok( "App::MatrixTool::Command::client::sync" );
use_ok( "App::MatrixTool::Command::client::upload" );
use_ok( "App::MatrixTool::Command::directory" );
use_ok( "App::MatrixTool::Command::notary" );
use_ok( "App::MatrixTool::Command::resolve" );
use_ok( "App::MatrixTool::Command::server_key" );

done_testing;



( run in 2.268 seconds using v1.01-cache-2.11-cpan-b16cb0d3907 )