10-07-2009 10:40 AM
use warnings;
use strict;
use HTTP::Request::Common;
use HTTP::Request;
use HTTP::Response;
use HTTP::Headers;
use LWP::UserAgent;
use JSON;
my $alfTicket;
my $host = 'localhost';
my $port = 8080;
sub login ()
{
my ($username, $password) = @_;
my $ua = LWP::UserAgent->new;
my $h = HTTP::Headers->new;
$h->header ('Content-Type' => 'application/json', Accept=>'application/json');
my $GetReq = HTTP::Request->new
(
'POST',
"http://$host:$port/alfresco/service/api/login",
$h,
'{"username" : "' . $username . '","password" : "' . $password . '"}'
);
my $res = $ua->request($GetReq);
# Check the outcome of the response
if ($res->is_success)
{
print "Response :\n";
print $res->as_string;
print "\n\n**************************\n\n";
my $hashRef = JSON::decode_json ($res->content);
$alfTicket = $hashRef->{"data"}->{"ticket"};
return 1;
}
else
{
print 'Error (' . $res->{_rc} . ') : ' . $res->{_msg} . "\n";
print "\t" . $res->content . "\n";
return 0;
}
}
print "username: ";
my $username = <STDIN>;
chomp ($username);
print "password: ";
my $password = <STDIN>;
chomp ($password);
if (&login ($username, $password))
{
print "$username is logged in !\n";
}
else
{
print "$username can't log in $host:$port\n";
}
use warnings;
use strict;
use HTTP::Request::Common;
use HTTP::Request;
use HTTP::Response;
use HTTP::Headers;
use LWP::UserAgent;
use JSON;
my $alfTicket;
my $host = 'localhost.fr';
my $port = 8080;
sub login ()
{
my ($username, $password) = @_;
my $ua = LWP::UserAgent->new;
my $h = HTTP::Headers->new;
$h->header ('Content-Type' => 'application/json', Accept=>'application/json');
my $GetReq = HTTP::Request->new
(
'POST',
"http://$host:$port/alfresco/service/api/login",
$h,
'{"username" : "' . $username . '","password" : "' . $password . '"}'
);
my $res = $ua->request($GetReq);
# Check the outcome of the response
if ($res->is_success)
{
print "Response login :\n";
print $res->as_string;
print "\n\n**************************\n\n";
my $hashRef = JSON::decode_json ($res->content);
$alfTicket = $hashRef->{"data"}->{"ticket"};
return 1;
}
else
{
print 'Error (' . $res->{_rc} . ') : ' . $res->{_msg} . "\n";
print "\t" . $res->content . "\n";
return 0;
}
}
sub createShareSite ()
{
my ($siteInfosRef) = @_;
my $content = JSON::encode_json ($siteInfosRef);
my $ua = LWP::UserAgent->new;
my $h = HTTP::Headers->new;
$h->header ('Content-Type' => 'application/json', Accept=>'application/json');
my $GetReq = HTTP::Request->new
(
'POST',
"http://$host:$port/share/service/modules/create-site?alf_ticket=$alfTicket",
$h,
$content
);
print "—————————-\n";
print "Request createShareSite :\n" . $GetReq->as_string . "\n";
print "—————————-\n";
my $res = $ua->request($GetReq);
print "\n\n**************************\n\n";
print "Response createShareSite :\n";
print $res->as_string;
print "\n\n**************************\n\n";
if ($res->is_success)
{
print $res->content;
print "\n";
return 1;
}
else
{
return 0;
}
}
print "username: ";
my $username = <STDIN>;
chomp ($username);
print "password: ";
my $password = <STDIN>;
chomp ($password);
if (&login ($username, $password))
{
print "$username is logged in !\n";
my %siteInfos;
$siteInfos {'shortName'} = 'ferbru60';
$siteInfos {'title'} = 'The ferbru60 site !';
$siteInfos {'description'} = 'This is the ferbru60 site.';
$siteInfos {'visibility'} = 'PRIVATE';
$siteInfos {'sitePreset'} = 'site-dashboard';
if (&createShareSite (\%siteInfos))
{
print "It's rocks !\n";
}
else
{
print "bad news\n";
}
}
else
{
print "$username can't log in $host:$port\n";
}
use warnings;
use strict;
use HTTP::Request::Common;
use HTTP::Request;
use HTTP::Response;
use HTTP::Headers;
use LWP::UserAgent;
use JSON;
my $alfTicket;
my $host = 'localhost';
my $port = 8080;
sub createShareSite ()
{
my ($username, $password, $siteInfosRef) = @_;
my $content = JSON::encode_json ($siteInfosRef);
my $ua = LWP::UserAgent->new;
my $h = HTTP::Headers->new;
$h->header ('Content-Type' => 'application/json', Accept=>'application/json');
$h->authorization_basic ($username, $password);
my $GetReq = HTTP::Request->new
(
'POST',
"http://$host:$port/share/service/modules/create-site",
$h,
$content
);
print "—————————-\n";
print "Request createShareSite :\n" . $GetReq->as_string . "\n";
print "—————————-\n";
my $res = $ua->request($GetReq);
print "\n\n**************************\n\n";
print "Response createShareSite :\n";
print $res->as_string;
print "\n\n**************************\n\n";
if ($res->is_success)
{
print $res->content;
print "\n";
return 1;
}
else
{
return 0;
}
}
print "username: ";
my $username = <STDIN>;
chomp ($username);
print "password: ";
my $password = <STDIN>;
chomp ($password);
my %siteInfos;
$siteInfos {'shortName'} = 'ferbru60';
$siteInfos {'title'} = 'The ferbru60 site !';
$siteInfos {'description'} = 'This is the ferbru60 site.';
$siteInfos {'visibility'} = 'PRIVATE';
$siteInfos {'sitePreset'} = 'site-dashboard';
if (&createShareSite ($username, $password, \%siteInfos))
{
print "It's rocks !\n";
}
else
{
print "bad news\n";
}
10-14-2009 03:44 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.