#!/usr/bin/perl -w
use strict;
use CipUX::RPC::Client;
use English qw( -no_match_vars);

# prep
my $rpc = CipUX::RPC::Client->new(
    {
        url     => 'http://localhost:8001/RPC2',
        client  => 'expl_rpc_task_list',
        version => '0.0.1',
    }
);

# start calling
eval { $rpc->rpc_ping; };
die "Server is down! $EVAL_ERROR" if $EVAL_ERROR;
my $ok = $rpc->rpc_login;
if ($ok) {
    my $cmd  = 'cipux_task_list_student_accounts';
    my $a_hr = $rpc->xmlrpc( { cmd => $cmd } );
    my $d_hr = $rpc->extract_data_for_tpl(
        { answer_hr => $a_hr, use_ltarget => 1 } );
    print "Students on the system:\n";
    foreach ( @{ $d_hr->{tpl_data_ar} } ) {
        print "\t$_->{$d_hr->{ltarget}}\n";
    }
    $rpc->rpc_logout;
}
else {
    print 'No access for ' . $rpc->get_login . "!\n";
    print "Wrong password?\n";
}
