view release on metacpan or search on metacpan
use strict;
use warnings;
use Module::Build;
my $build = Module::Build->new(
module_name => 'API::Plesk',
license => 'perl',
dist_author => 'Ivan Sokolov <ivsokolov@cpan.org>',
requires => {
'Module::Build' => 0,
'Data::Dumper' => 0,
'LWP::UserAgent' => 0,
'HTTP::Request' => 0,
'Carp' => 0,
'XML::Fast' => 0,
'version' => 0,
},
build_requires => {
'Test::More' => 0,
'Test::LongString' => 0,
'URI' => 0,
},
create_makefile_pl => 'traditional',
);
$build->create_build_script;
lib/API/Plesk/User.pm
Makefile.PL
MANIFEST This list of files
META.yml
README
t/compoment.t
t/customer.t
t/database.t
t/plesk.t
t/mock.t
t/response.t
t/site.t
t/sitebuilder.t
t/site-alias.t
t/ftp_user.t
t/webuser.t
t/webspace.t
t/dns.t
t/mail.t
t/service-plan.t
t/user.t
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
},
"name" : "API-Plesk",
"prereqs" : {
"build" : {
"requires" : {
"Test::LongString" : "0",
"Test::More" : "0",
"URI" : "0"
}
},
"configure" : {
"requires" : {
"Module::Build" : "0.40"
}
},
"runtime" : {
"requires" : {
"Carp" : "0",
"Data::Dumper" : "0",
"HTTP::Request" : "0",
"LWP::UserAgent" : "0",
"Module::Build" : "0",
"XML::Fast" : "0",
"version" : "0"
}
}
},
"API::Plesk::WebUser" : {
"file" : "lib/API/Plesk/WebUser.pm",
"version" : 0
},
"API::Plesk::Webspace" : {
"file" : "lib/API/Plesk/Webspace.pm",
"version" : 0
}
},
"release_status" : "stable",
"resources" : {
"license" : [
"http://dev.perl.org/licenses/"
]
},
"version" : "2.03"
}
---
abstract: 'OO interface to the Plesk XML API (http://www.parallels.com/en/products/plesk/).'
author:
- 'Ivan Sokolov <ivsokolov@cpan.org>'
build_requires:
Test::LongString: 0
Test::More: 0
URI: 0
configure_requires:
Module::Build: 0.40
dynamic_config: 1
generated_by: 'Module::Build version 0.4003, CPAN::Meta::Converter version 2.120921'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: API-Plesk
provides:
API::Plesk:
version: 0
API::Plesk::User:
file: lib/API/Plesk/User.pm
version: 0
API::Plesk::WebUser:
file: lib/API/Plesk/WebUser.pm
version: 0
API::Plesk::Webspace:
file: lib/API/Plesk/Webspace.pm
version: 0
requires:
Carp: 0
Data::Dumper: 0
HTTP::Request: 0
LWP::UserAgent: 0
Module::Build: 0
XML::Fast: 0
version: 0
resources:
license: http://dev.perl.org/licenses/
version: 2.03
my $api = API::Plesk->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,
);
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:
API::Plesk::Customer
API::Plesk::Database
$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) = @_;
lib/API/Plesk.pm view on Meta::CPAN
$req->push_header(':HTTP_AUTH_PASSWD', $self->{password});
}
$req->content_type('text/xml; charset=UTF-8');
$req->content($xml);
# LWP6 hack to prevent verification of hostname
$ua->ssl_opts(verify_hostname => 0) if $ua->can('ssl_opts');
warn $req->as_string if defined $self->{debug} && $self->{debug} > 1;
my $res = eval {
local $SIG{ALRM} = sub { die "connection timeout" };
alarm $self->{timeout};
$ua->request($req);
};
alarm 0;
warn $res->as_string if defined $self->{debug} && $self->{debug} > 1;
return ('', 'connection timeout')
if !$res || $@ || ref $res && $res->status_line =~ /connection timeout/;
return $res->is_success() ?
($res->content(), '') :
('', $res->status_line);
}
# renders xml packet for request
sub render_xml {
my ($self, $hash) = @_;
my $xml = _render_xml($hash);
$xml = qq|<?xml version="1.0" encoding="UTF-8"?><packet version="$self->{api_version}">$xml</packet>|;
lib/API/Plesk.pm view on Meta::CPAN
my $api = API::Plesk->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,
);
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:
API::Plesk::Customer
API::Plesk::Database
API::Plesk::DNS
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/Component.pm view on Meta::CPAN
sub check_hosting {
my ( $self, $params, $required ) = @_;
unless ( $params->{hosting} ) {
confess "Required hosting!" if $required;
return;
}
my $hosting = $params->{hosting};
my $type = delete $hosting->{type};
my $ip = delete $hosting->{ip_address};
#confess "Required ip_address" unless $ip;
if ( $type eq 'vrt_hst' ) {
$self->check_required_params($hosting, qw(ftp_login ftp_password));
my @properties;
for my $key ( sort keys %$hosting ) {
push @properties, { property => [
{name => $key},
{value => $hosting->{$key}}
]};
delete $hosting->{$key};
}
push(@properties, { ip_address => $ip }) if $ip;
$hosting->{$type} = @properties ? \@properties : '';
return;
}
elsif ( $type eq 'std_fwd' or $type eq 'frm_fwd' ) {
confess "Required dest_url field!" unless $hosting->{dest_url};
$hosting->{$type} = {
dest_url => delete $hosting->{dest_url},
};
$hosting->{$type}->{ip_address} = $ip if $ip;
return;
}
elsif ( $type eq 'none' ) {
$hosting->{$type} = '';
return;
}
confess "Unknown hosting type!";
}
lib/API/Plesk/Customer.pm view on Meta::CPAN
my @gen_info_fields = qw(
cname
pname
login
passwd
status
phone
fax
email
address
city
state
pcode
country
owner-id
);
sub add {
my ( $self, %params ) = @_;
my $bulk_send = delete $params{bulk_send};
lib/API/Plesk/Customer.pm view on Meta::CPAN
__END__
=head1 NAME
API::Plesk::Customer - Managing customer accounts.
=head1 SYNOPSIS
$api = API::Plesk->new(...);
$response = $api->customer->add(..);
$response = $api->customer->get(..);
$response = $api->customer->set(..);
$response = $api->customer->del(..);
=head1 DESCRIPTION
Module manage customer accounts.
=head1 METHODS
=over 3
=item add(%params)
lib/API/Plesk/Database.pm view on Meta::CPAN
__END__
=head1 NAME
API::Plesk::Database - Managing databases.
=head1 SYNOPSIS
$api = API::Plesk->new(...);
$response = $api->database->add_db(..);
$response = $api->database->del_db(..);
$response = $api->database->add_db_user(..);
$response = $api->database->del_db_user(..);
=head1 DESCRIPTION
Module manage databases and database users.
=head1 METHODS
=over 3
=item add_db(%params)
lib/API/Plesk/FTPUser.pm view on Meta::CPAN
__END__
=head1 NAME
API::Plesk::Site - Managing sites (domains).
=head1 SYNOPSIS
$api = API::Plesk->new(...);
$response = $api->site->get(..);
=head1 DESCRIPTION
Module manage sites (domains).
=head1 METHODS
=over 3
=item add(%params)
lib/API/Plesk/Mail.pm view on Meta::CPAN
__END__
=head1 NAME
API::Plesk::Mail - Managing mail on Domain Level.
=head1 SYNOPSIS
$api = API::Plesk->new(...);
$response = $api->mail->enable(..);
=head1 DESCRIPTION
Module manage mail on Domain Level.
=head1 METHODS
=over 3
=item enable(%params)
lib/API/Plesk/Mock.pm view on Meta::CPAN
package API::Plesk::Mock;
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
use API::Plesk::Mock;
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>
lib/API/Plesk/Response.pm view on Meta::CPAN
use warnings;
use Data::Dumper;
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,
};
return bless $self, $class;
}
sub is_success { $_[0]->{is_success} }
sub id { $_[0]->{results}->[0]->{id} }
sub guid { $_[0]->{results}->[0]->{guid} }
sub data {
my ( $self ) = @_;
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
lib/API/Plesk/Response.pm view on Meta::CPAN
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;
=head1 DESCRIPTION
This class is intended for convenient processing results of Plesk API responses.
Every operation of API::Plesk::Component return object of this class.
And it get you easy way to manipulate with response from Plesk API.
=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
lib/API/Plesk/ServicePlan.pm view on Meta::CPAN
__END__
=head1 NAME
API::Plesk::ServicePlan - Managing service plans.
=head1 SYNOPSIS
$api = API::Plesk->new(...);
$response = $api->service_plan->get(...);
$response = $api->service_plan->set(...);
$response = $api->service_plan->del(...);
=head1 DESCRIPTION
Module manage service plans.
=head1 METHODS
=over 3
=item get(%params)
lib/API/Plesk/ServicePlanAddon.pm view on Meta::CPAN
__END__
=head1 NAME
API::Plesk::ServicePlanAddon - Managing add-on plans.
=head1 SYNOPSIS
$api = API::Plesk->new(...);
$response = $api->service_addon_plan->get(..);
=head1 DESCRIPTION
Module manage add-on plans.
=head1 METHODS
=over 3
=item get(%params)
lib/API/Plesk/Site.pm view on Meta::CPAN
__END__
=head1 NAME
API::Plesk::Site - Managing sites (domains).
=head1 SYNOPSIS
$api = API::Plesk->new(...);
$response = $api->site->get(..);
=head1 DESCRIPTION
Module manage sites (domains).
=head1 METHODS
=over 3
=item add(%params)
lib/API/Plesk/SiteAlias.pm view on Meta::CPAN
__END__
=head1 NAME
API::Plesk::SiteAlias - Managing site aliases.
=head1 SYNOPSIS
$api = API::Plesk->new(...);
$response = $api->site_alias->get(..);
=head1 DESCRIPTION
Module manage sites (domains).
=head1 METHODS
=over 3
=item create(%params)
lib/API/Plesk/SiteBuilder.pm view on Meta::CPAN
__END__
=head1 NAME
API::Plesk::SiteBuilder - Managing SiteBuilder sites.
=head1 SYNOPSIS
$api = API::Plesk->new(...);
$response = $api->sitebuilder->assign_trial_site(...);
=head1 DESCRIPTION
Module manage SiteBuilder sites.
=head1 METHODS
=over 3
=item assign_trial_site(%params)
lib/API/Plesk/User.pm view on Meta::CPAN
__END__
=head1 NAME
API::Plesk::Customer - Managing user (e.g. auxiliary) accounts.
=head1 SYNOPSIS
$api = API::Plesk->new(...);
$response = $api->user->add(..);
$response = $api->user->get(..);
$response = $api->user->set(..);
$response = $api->user->del(..);
=head1 DESCRIPTION
Module manage user (e.g. auxiliary) accounts.
Filters used by get,del etc. are as follows:
%filter => {
guid => xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
# or
owner-guid => xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
lib/API/Plesk/WebUser.pm view on Meta::CPAN
__END__
=head1 NAME
API::Plesk::WebUser - Managing webusers.
=head1 SYNOPSIS
$api = API::Plesk->new(...);
$response = $api->webuser->get(..);
=head1 DESCRIPTION
Module manage webusers.
=head1 METHODS
=over 3
=item add(%params)
lib/API/Plesk/Webspace.pm view on Meta::CPAN
use base 'API::Plesk::Component';
my @gen_setup_fields = qw(
name
owner-id
owner-login
owner-guid
owner-external-id
htype
ip_address
status
external-id
);
my @main_fields = qw(
gen_setup
hosting
limits
prefs
performance
lib/API/Plesk/Webspace.pm view on Meta::CPAN
);
sub add {
my ( $self, %params ) = @_;
my $bulk_send = delete $params{bulk_send};
my $gen_setup = $params{gen_setup} || confess "Required gen_setup parameter!";
$self->check_hosting(\%params);
$self->check_required_params(\%params, [qw(plan-id plan-name plan-guid plan-external-id)]);
$self->check_required_params($gen_setup, qw(name ip_address));
$params{gen_setup} = $self->sort_params($gen_setup, @gen_setup_fields);
my $data = $self->sort_params(\%params, @main_fields);
return $bulk_send ? $data :
$self->plesk->send('webspace', 'add', $data);
}
sub get {
lib/API/Plesk/Webspace.pm view on Meta::CPAN
__END__
=head1 NAME
API::Plesk::Webspace - Managing subscriptions (webspaces).
=head1 SYNOPSIS
$api = API::Plesk->new(...);
$response = $api->webspace->add(..);
$response = $api->webspace->del(..);
=head1 DESCRIPTION
Module manage subscriptions (webspaces).
=head1 METHODS
=over 3
=item add(%params)
t/TestData.pm view on Meta::CPAN
our $test_user_data = {
pname => 'pavel',
login => 'pav_perl',
passwd => 'password',
phone => '8 555 1111111',
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',
t/TestData.pm view on Meta::CPAN
my $manual_created_template_name = $ENV{'template_name'} || 'name';
my $manual_created_template_id = $ENV{'template_id'} || 1;
sub iterate {
my $hash = shift;
my $plesk_client = shift;
my $result_hash = { };
# initial data
for (keys %$hash) {
$result_hash->{$_} = $hash->{$_}->[0];
}
check_input_data($result_hash, $plesk_client);
foreach my $key (keys %$hash) {
my $old_value = $result_hash->{$key}; # rewrite
for my $index (1 .. scalar @{$hash->{$key}} - 1){
$result_hash->{$key} = $hash->{$key}->[$index];
check_input_data($result_hash, $plesk_client);
# warn Dumper $result_hash;
}
$result_hash->{$key} = $old_value;
}
return $result_hash;
}
sub check_input_data {
my $params = shift;
my $plesk_client = shift;
my $general_info = {
pname => $params->{pname}, # utf8 string
login => $params->{login},
passwd => $params->{passwd},
phone => $params->{phone},
email => $params->{email},
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 ));
}
t/TestData.pm view on Meta::CPAN
'Delete all accounts'
);
}
# Sub for create accounts online test
sub create_work_logins {
my $plesk_client = shift;
my $data_accumulator_for_online_tests = shift;
my $result_add_by_id = $plesk_client->Accounts->create(
general_info => create_unique_user_data('crby_login'),
'template-name' => $manual_created_template_name
);
like(
$data_accumulator_for_online_tests->{user_id_from_create_with_tmpl_name} =
$result_add_by_id->get_id,
qr/^\d+$/,
'Create account with template name'
);
like(
$data_accumulator_for_online_tests->{user_id_from_create_with_tmpl_id} =
$plesk_client->Accounts->create(
general_info => create_unique_user_data('createby_id'),
t/TestData.pm view on Meta::CPAN
)->get_id,
qr/^\d+$/,
'Create account with template id'
);
}
sub create_unique_user_data {
my $unique_id = shift;
my %result_user_data = %{$test_user_data};
$result_user_data{'pname'} = $result_user_data{'login'} = "testuser_$unique_id";
return \%result_user_data;
}
# "Compare" two hashrefs
# Sub for get info online tests
sub _compare {
my $checked = shift;
my $template = shift;
return '' unless ref $checked eq 'HASH' && ref $template eq 'HASH';
foreach my $key (keys %$template) {
my $key_name_from; # field name in response from Plesk
my $key_name_to; # field name
# in request to Plesk field named "passwd"
# in response from Plesk -- it named "password" :(
if ($key =~ /pass/) {
$key_name_from = 'password';
$key_name_to = 'passwd';
} else {
$key_name_to = $key_name_from = $key;
}
t/compoment.t view on Meta::CPAN
{key => 1},
]
);
eval {
$c->check_hosting({
hosting => {
type => 'vrt_hst',
ftp_login => 'ert',
ftp_password => '123',
ip_address => '12.34.56.78',
}
})
};
ok(!$@);
eval {
$c->check_hosting({
hosting => {
type => 'vrt_hst',
ftp_login => 'ert',
BEGIN {
plan tests => 6;
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
BEGIN {
plan tests => 17;
use_ok('API::Plesk::Response');
}
isa_ok(
API::Plesk::Response->new(
operator => 'customer',
operation => 'get',
response => {}
),
'API::Plesk::Response'
);
my $res = API::Plesk::Response->new(
operator => 'customer',
operation => 'get',
response => xml2hash('
<?xml version="1.0" encoding="utf-8"?>
<packet>
<customer>
<get>
<result>
<status>ok</status>
<id>123</id>
<guid>123456</guid>
<data>
<test>qwerty</test>
</data>
</result>
</get>
</customer>
</packet>', array => ['get', 'result'])
);
ok($res->is_success);
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');
t/service-plan.t view on Meta::CPAN
isa_ok($api->service_plan, 'API::Plesk::ServicePlan');
is_deeply(
$api->service_plan->set(
filter => { name => '123' },
hosting => {
type => 'vrt_hst',
ftp_login => '123',
ftp_password => '123',
ip_address => '123',
},
limits => '',
bulk_send => 1,
),
[
{ filter => { name => '123' } },
{ limits => '' },
{
hosting => {
vrt_hst => [
{ property => [ {name => 'ftp_login'}, {value => '123'} ] },
{ property => [ {name => 'ftp_password'}, {value => '123'} ] },
{ ip_address => '123' },
]
},
},
],
'set'
);
is_deeply(
$api->service_plan->del(
name => 'test.ru',
isa_ok($api->site, 'API::Plesk::Site');
is_deeply(
$api->site->add(
gen_setup => {
name => 'test.ru',
'webspace-name' => 'main.ru',
},
hosting => {
type => 'std_fwd',
ip_address => '12.34.56.78',
dest_url => 'fwd.ru',
},
bulk_send => 1
),
[
{gen_setup => [
{name => 'test.ru'},
{'webspace-name' => 'main.ru'},
]},
{hosting => {
std_fwd => {
dest_url => 'fwd.ru',
ip_address => '12.34.56.78',
}
}}
],
'add'
);
is_deeply(
$api->site->set(
filter => {name => 'test.ru'},
gen_setup => {
name => 'test.ru',
},
hosting => {
type => 'vrt_hst',
ip_address => '12.34.56.78',
ftp_login => 'qwerty',
ftp_password => '12345',
ip_address => '12.34.56.78',
},
bulk_send => 1
),
{
filter => {name => 'test.ru'},
values => [
{gen_setup => {
name => 'test.ru',
}},
{hosting => {
vrt_hst => [
{ property => [
{name => 'ftp_login'},
{value => 'qwerty'}
]},
{ property => [
{name => 'ftp_password'},
{value => '12345'}
]},
{ip_address => '12.34.56.78'},
]
}}
]
},
'set'
);
is_deeply(
$api->site->del(
t/webspace.t view on Meta::CPAN
my $api = API::Plesk->new( %TestData::plesk_valid_params );
isa_ok($api->webspace, 'API::Plesk::Webspace');
is_deeply(
$api->webspace->add(
'plan-name' => '123',
gen_setup => {
name => '123',
ip_address => '123',
'owner-login' => '123',
},
hosting => {
type => 'vrt_hst',
ftp_login => '123',
ftp_password => '123',
ip_address => '123',
},
prefs => { www => 'true' },
bulk_send => 1,
),
[
{
gen_setup => [
{name => '123'},
{'owner-login' => '123'},
{ip_address => '123'},
],
},
{
hosting => {
vrt_hst => [
{ property => [ {name => 'ftp_login'}, {value => '123'} ] },
{ property => [ {name => 'ftp_password'}, {value => '123'} ] },
{ ip_address => '123' },
]
},
},
{ prefs => { www => 'true' } },
{ 'plan-name' => '123' },
],
'add'
);
is_deeply(
$api->webspace->set(
filter => { name => '123' },
gen_setup => {
name => '123',
ip_address => '123',
'owner-login' => '123',
},
hosting => {
type => 'vrt_hst',
ftp_login => '123',
ftp_password => '123',
ip_address => '123',
},
prefs => { www => 'true' },
bulk_send => 1,
),
[
{ filter => { name => '123' } },
{ values => [
{
gen_setup => [
{name => '123'},
{'owner-login' => '123'},
{ip_address => '123'},
],
},
{
hosting => {
vrt_hst => [
{ property => [ {name => 'ftp_login'}, {value => '123'} ] },
{ property => [ {name => 'ftp_password'}, {value => '123'} ] },
{ ip_address => '123' },
]
},
},
{ prefs => { www => 'true' } },
]},
],
'set'
);