Dokuwiki::RPC::XML::Client - A RPC::XML::Client for dokuwiki.
Dokuwiki::RPC::XML::Client extends the RPC::XML::Client with the Dokuwiki XML-RPC methods (without namespace) described in the dokuwiki xml-rpc page.
As example, a call to wiki.getVersion (which also require a call to dokuwiki.login) is:
use Dokuwiki::RPC::XML::Client; use Modern::Perl; my $wiki = Dokuwiki::RPC::XML::Client -> reach('https://wiki.example.com/'); $wiki->login(qw( editor s3cr3t ))->value or die; say $wiki->getVersion->value;
reach
to use the RPC::XML::Client::new constructor directly, you have to remember the url of the RPC server and how to setup a cookie file so you stay connected after the dokuwiki.login) was called.
RPC::XML::Client::new
So, as explained in http://stackoverflow.com/questions/16572903/logging-into-dokuwiki-using-perls-rpcxmlclient-or-alternately-how-can-i-re, calling the constructor would be:
my $client = RPC::XML::Client->new ('http://example.com/wikiname/lib/exe/xmlrpc.php' , useragent => [ cookie_jar => { file => "$ENV{HOME}/.cookies.txt" }] );
But you don't want to write it down? don't you? Dokuwiki::RPC::XML::Client comes with a wrapper called reach $class $url %options; possible calls are
reach $class $url %options
Dokuwiki::RPC::XML::Client->reach ('http://example.com/wikiname/' ); Dokuwiki::RPC::XML::Client->reach ( base => 'http://example.com/wikiname/' ); Dokuwiki::RPC::XML::Client->reach ( url => 'http://example.com/wikiname/lib/exe/xmlrpc.php' ); Dokuwiki::RPC::XML::Client->reach ('http://example.com/wikiname/' , file => '/tmp/dokukookies.txt' );
%Dokuwiki::RPC::XML::Client::API is a hash where keys are the Dokuwiki::RPC::XML::Client methods and values are the Dokuwiki XML-RPC methods. So you can have the list of the mapped functions with:
%Dokuwiki::RPC::XML::Client::API
Dokuwiki::RPC::XML::Client
perl -MDokuwiki::RPC::XML::Client -E' say for keys %Dokuwiki::RPC::XML::Client::API
but please refer to the dokuwiki xml-rpc page for more details.
~/.netrc
getting the login and password from STDIN, @ARGV or hardcoded in your source file is always a bad idea. so this is an example to get things done using the god damn old and good ~/.netrc file.
STDIN
@ARGV
use Dokuwiki::RPC::XML::Client; use Modern::Perl; use Net::Netrc; my $base = 'https://example.com/'; my $host = 'company'; my $wiki = Dokuwiki::RPC::XML::Client -> reach('https://wiki.example.com/'); my $credentials = Net::Netrc->lookup($host) or die "please add a fake $host machine in your ~/.netrc"; my ( $l, $p ) = $credentials->lpa; $wiki->login( $l, $p )->value or die "can't authenticate with $l"; say $wiki->getVersion->value;
i'm still experimenting to make my mind up about the right way to do it. it would be nice to have both a raw RPC::XML::Client as a singleton. then we could have something usable in both way
RPC::XML::Client
use aliased qw<Dokuwiki::RPC::XML::Client::Singleton D>; D::netrc 'unistra'; D::login 'https://di.u-strasbg.fr'; say "connected to dokuwiki version ". D::getVersion; say for grep /^metiers:/, ids_of D::getAllPages;
or
use Dokuwiki::RPC::XML::Client::Singleton ':all'; netrc 'unistra'; login 'https://di.u-strasbg.fr'; say "connected to dokuwiki version ". getVersion; say for grep /^metiers:/, ids_of getAllPages;
To install Dokuwiki::RPC::XML::Client, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dokuwiki::RPC::XML::Client
CPAN shell
perl -MCPAN -e shell install Dokuwiki::RPC::XML::Client
For more information on module installation, please visit the detailed CPAN module installation guide.