API-Plesk
view release on metacpan or search on metacpan
- removed Try::Tiny
- Changes was formated according to CPAN::Changes::Spec
- fixed tests
2.02 2013-07-10
- Added DNS zone SOA get (Jari Turkia)
- Added secret key -based authentication (by Jari Turkia)
- Fixed warning about uninitialized value
- subdomain added (Zavarykin Eugeny)
- is_connection_error modified (Zavarykin Eugeny)
- fixed warning and bug (Eugen Konkov)
- .gitignore (Akzhan Abdulin)
- fixed bug (Ivan Shamal)
2.01 2012-06-25
- Fixed tests
2.00 2012-06-25
- Improved is_connection_error function
- Added user component (bgmilne)
- Added mock module for testing without sending requests to real api
- Fixed bug in service_plan->get method
2.00_3 2011-08-01
- Added site-alias component
- Fixed add and set webspace
- Added tests
- Fixed site component
- Added sitebuilder component
- Added ftp-user component
- Fixed hosting ftp_password bug
- Added dns component
- Added mail component
- Fixed is_connection_error function
- Added set and del opetations to service-plan
- Added test of service-plan component
- Reformated Changes
- Fixed Pod
2.00_2 2011-05-16
- Fixed xml renderer
2.00_1 20 Apr 2011 10:52:43
- Add URI.pm as required module for test stage
1.06 2008-07-13
- More improvements in tests
- Get user domains list by login or client id
1.05 2008-06-15
- Added full support operations with databases and db users
- Fixed errors in pod documentation
1.04 2008-05-29
- Added the ability to fine tuning the abstract_parser sub (for API::PleskExpand)
1.03 2008-05-25
- Small bug fix
1.02 2008-03-22
- Fixed errors in pod documentation
- Fixed bug with keys sorting in Methods.pm (thanks to CPAN testers)
1.01 2008-03-20
- Fixed errors in pod documentation
- Fixed bug in Tariff Plan Change sub (Complex.pm)
1.00 2008-03-18
- The first public release
);
my $res = $api->customer->get();
if ($res->is_success) {
for ( @{$res->data} ) {
print "login: $_->{login}\n";
}
}
else {
print $res->error;
}
DESCRIPTION
At present the module provides interaction with Plesk 10.1 (API
1.6.3.1). Distribution was completely rewritten and become more friendly
for developers. Naming of packages and methods become similar to the
same operators and operations of Plesk XML API.
Partially implemented:
$operator - name of operator XML section of Plesk API.
$operation - mane of operation XML section of Plesk API.
$data - data hash that is converted to XML and is sended to plesk
server.
xml_http_req( $xml )
Internal method. it implements real request sending to Plesk API.
Returns array ( $response_xml, $error ).
SEE ALSO
Plesk XML RPC API http://www.parallels.com/en/products/plesk/docs/
AUTHOR
Odintsov Pavel <nrg[at]cpan.org>
Nikolay Shulyakovskiy <shulyakovskiy[at]rambler.ru>
Ivan Sokolov <ivsokolov[at]cpan.org>
lib/API/Plesk.pm view on Meta::CPAN
my ( $self, $operator, $operation, $data, %params ) = @_;
confess "Wrong request data!" unless $data && ref $data;
my $xml = { $operator => { $operation => $data } };
$xml = $self->render_xml($xml);
warn "REQUEST $operator => $operation\n$xml" if $self->{debug};
my ($response, $error) = $self->xml_http_req($xml);
warn "RESPONSE $operator => $operation => $error\n$response" if $self->{debug};
unless ( $error ) {
$response = xml2hash $response, array => [$operation, 'result', 'property'];
}
return API::Plesk::Response->new(
operator => $operator,
operation => $operation,
response => $response,
error => $error,
);
}
sub bulk_send { confess "Not implemented!" }
# Send xml request to plesk api
sub xml_http_req {
my ($self, $xml) = @_;
# HTTP::Request undestends only bytes
lib/API/Plesk.pm view on Meta::CPAN
);
my $res = $api->customer->get();
if ($res->is_success) {
for ( @{$res->data} ) {
print "login: $_->{login}\n";
}
}
else {
print $res->error;
}
=head1 DESCRIPTION
At present the module provides interaction with Plesk 10.1 (API 1.6.3.1).
Distribution was completely rewritten and become more friendly for developers.
Naming of packages and methods become similar to the same operators and operations of Plesk XML API.
Partially implemented:
lib/API/Plesk.pm view on Meta::CPAN
$operator - name of operator XML section of Plesk API.
$operation - mane of operation XML section of Plesk API.
$data - data hash that is converted to XML and is sended to plesk server.
=item xml_http_req( $xml )
Internal method. it implements real request sending to Plesk API.
Returns array ( $response_xml, $error ).
=back
=head1 SEE ALSO
Plesk XML RPC API http://www.parallels.com/en/products/plesk/docs/
=head1 AUTHORS
Odintsov Pavel E<lt>nrg[at]cpan.orgE<gt>
lib/API/Plesk/Mock.pm view on Meta::CPAN
use strict;
use warnings;
use base 'API::Plesk';
sub mock_response {
$_[0]->{mock_response} = $_[1] if @_ > 1;
$_[0]->{mock_response};
}
sub mock_error {
$_[0]->{mock_error} = $_[1] if @_ > 1;
$_[0]->{mock_error};
}
sub xml_http_req { ($_[0]->{mock_response}, $_[0]->{mock_error}) }
1;
__END__
=head1 NAME
API::Plesk::Mock - Module for testing API::Plesk without sending real requests to Plesk API.
=head1 SYNOPSIS
lib/API/Plesk/Mock.pm view on Meta::CPAN
my $api = API::Plesk::Mock->new(
username => 'user', # required
password => 'pass', # required
url => 'https://127.0.0.1:8443/enterprise/control/agent.php', # required
api_version => '1.6.3.1',
debug => 0,
timeout => 30,
);
$api->mock_response($some_response_xml);
$api->mock_error($some_error_text);
=head1 DESCRIPTION
Module for testing API::Plesk without sending real requests to Plesk API.
=head1 METHODS
=over 3
=item mock_response($xml)
Sets response from Plesk API
=item mock_error($text)
Sets any error
=back
=head1 AUTHOR
Ivan Sokolov E<lt>ivsokolov[at]cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2008 by Ivan Sokolov
lib/API/Plesk/Response.pm view on Meta::CPAN
sub new {
my ( $class, %attrs) = @_;
$class = ref $class || $class;
my $operator = $attrs{operator};
my $operation = $attrs{operation};
my $response = $attrs{response};
my $results = [];
my $is_success = 1;
# internal API::Plesk error
if ( $attrs{error} ) {
$results = [{
errcode => '',
errtext => $attrs{error},
status => 'error'
}];
$is_success = '';
}
# remote system plesk error
elsif ( exists $response->{packet}->{'system'} ) {
$results = [$response->{packet}->{'system'}];
$is_success = '';
$operator = 'system';
$operation = '';
}
else {
eval {
for my $result ( @{$response->{packet}->{$operator}->{$operation}->[0]->{result}} ) {
push @$results, $result;
$is_success = '' if $result->{status} && $result->{status} eq 'error';
}
1;
} || do {
$results = [{
errcode => '',
errtext => "Internal Plesk error: $_.\nError: $@\nDetails:" . Dumper( $response ),
status => 'error'
}];
};
}
my $self = {
results => $results,
operator => $operator,
operation => $operation,
is_success => $is_success,
};
lib/API/Plesk/Response.pm view on Meta::CPAN
return [] unless $self->is_success;
return [ map { $_->{data} || () } @{$self->{results}} ];
}
sub results {
my ( $self ) = @_;
return unless $self->is_success;
return $self->{results} || [];
}
sub error_code { $_[0]->error_codes->[0]; }
sub error_text { $_[0]->error_texts->[0]; }
sub error {
my ( $self ) = @_;
return ($self->{results}->[0]->{errcode} || '0') . ': ' . $self->{results}->[0]->{errtext};
}
sub error_codes {
my ( $self ) = @_;
return [] if $self->is_success;
return [ map { $_->{errcode} || () } @{$self->{results}} ];
}
sub error_texts {
my ( $self ) = @_;
return [] if $self->is_success;
return [ map { $_->{errtext} || () } @{$self->{results}} ];
}
sub errors {
my ( $self ) = @_;
return [] if $self->is_success;
my @errors;
for ( @{$self->{results}} ) {
my $error = ($_->{errcode} || '0') . ': ' . $_->{errtext};
push @errors, $error;
}
return \@errors;
}
sub is_connection_error {
my ( $self ) = @_;
return
$self->error_text =~ /connection failed/ ||
$self->error_text =~ /connection timeout/ ||
$self->error_text =~ /500\s+/
? 1 : 0;
}
1;
__END__
=head1 NAME
API::Plesk::Response - Class for processing server answers with errors handling.
=head1 SYNOPSIS
my $res = API::Plesk::Response->new(
operator => 'customer',
operation => 'get',
response => 'xml answer from plesk api',
);
$res->is_success;
$res->is_connection_error;
# get errors
$res->error_code;
$res->error_codes->[0];
$res->error_text;
$res->error_texts->[0];
$res->error;
$res->errors->[0];
# get data sections
$res->data->[0];
# get result sections
$res->results->[0];
# get id and guid
$res->id;
$res->guid;
lib/API/Plesk/Response.pm view on Meta::CPAN
=head1 METHODS
=over 3
=item new(%attributes)
Create response object.
=item is_success()
Returns true if all results have no errors.
=item is_connection_error()
Returns true if connection error happened.
=item data()
$response->data;
$response->data->[0];
=item results()
$response->results;
$response->results->[0];
=item error_code()
$response->error_code;
=item error_codes()
$response->error_codes->[0];
=item error_text()
$response->error_text;
=item error_texts()
$response->error_texts->[0];
=item error()
$response->error;
=item errors()
$response->errors->[0];
=back
=head1 AUTHOR
Ivan Sokolov <lt>ivsokolov@cpan.org<gt>
=cut
t/TestData.pm view on Meta::CPAN
email => 'nrg@nrg.name',
country => 'RU' # optional field
};
our $stress_test_data = {
pname => [ # 1 .. 60 symbols
'pavel',
'2342134123412',
'dasdf_dasdsa_ADdssd__DASsd',
# '____', error
(join '', 'x' x 60),
'add_(efewf)_(sdfsd)',
],
login => [ # 1 .. 20 symbols,
'pav_perl',
# '___', error
'123546',
#'_sdad',
'nrg.name',
'test.code.google.com',
'yet-another-test',
(join q//, 'x' x 20),
# '_(fsdf)_(fsadf)' error
],
passwd => [
'five!',
(join q//, 'x' x 14),
#'##$^$#&^%!@#$d',
12314321,
'_(sdf)%!Sas',
gen_passwd(),
gen_passwd(),
gen_passwd()
#'ÑеÑÑовÑй' error
],
phone => [ # 0 .. 30
'8 555 1111111',
# 'abcdefaff', error
'5',
'+7 499 123 44 55',
'+74991234455',
'',
' ',
'8(846)1234356',
'+7(846)1234356',
# '()()()(',
'312(4324)324',
],
t/TestData.pm view on Meta::CPAN
country => $params->{country}, # optional field
};
my $result_add_by_id = $plesk_client->Accounts->create(
general_info => $general_info,
'template-name' => $manual_created_template_name
);
delete_all_accounts($plesk_client);
# warn Dumper($general_info) . "\n" . $result_add_by_id->get_error_string unless
unless (like(
$result_add_by_id->get_id,
qr/^\d+$/,
'Create account input data check'
)) {
warn $result_add_by_id->get_error_string . "\n" .
Dumper $general_info;
}
}
sub gen_passwd {
my $passwd='';
for (my $i=0; $i<8; $i++) {
$passwd .= chr(rand( 0x3E ));
}
use_ok( 'API::Plesk::Mock' );
}
my $api = API::Plesk::Mock->new( %TestData::plesk_valid_params );
isa_ok( $api, 'API::Plesk::Mock', 'STATIC call new' );
$api->mock_response('some xml');
is($api->mock_response, 'some xml');
$api->mock_error('some error');
is($api->mock_error, 'some error');
$api->mock_response('<packet version="1.6.3.0"><dns><add_rec><result><status>ok</status><id>17</id></result></add_rec></dns></packet>');
$api->mock_error('');
my $res = $api->dns->add_rec(
'site-id' => 1,
type => 'NS',
host => 'Mysite.com',
value => 'ns.Mysite.com.',
);
is(ref $res, 'API::Plesk::Response');
is($res->id, 17);
t/response.t view on Meta::CPAN
is($res->id, 123);
is($res->guid, 123456);
is($res->results->[0]->{status}, 'ok');
is($res->data->[0]->{test}, 'qwerty');
$res = API::Plesk::Response->new(
operator => 'webspace',
operation => 'add',
response => xml2hash(q|
<?xml version="1.0" encoding="UTF-8"?>
<packet version="1.6.3.1"><webspace><add><result><status>error</status><errcode>1018</errcode><errtext>Unable to create hosting on ip 12.34.56.78. Ip address does not exist in client's pool</errtext></result></add></webspace></packet>
|, array => ['add', 'result'])
);
ok(!$res->is_success);
ok(!$res->id);
ok(!$res->guid);
is($res->{results}->[0]->{status}, 'error');
is($res->error_code, '1018');
is($res->error_text, 'Unable to create hosting on ip 12.34.56.78. Ip address does not exist in client\'s pool');
is($res->error_codes->[0], '1018');
is($res->error_texts->[0], 'Unable to create hosting on ip 12.34.56.78. Ip address does not exist in client\'s pool');
is($res->error, '1018: Unable to create hosting on ip 12.34.56.78. Ip address does not exist in client\'s pool');
is($res->errors->[0], '1018: Unable to create hosting on ip 12.34.56.78. Ip address does not exist in client\'s pool');
( run in 0.864 second using v1.01-cache-2.11-cpan-49f99fa48dc )