API-PleskExpand

 view release on metacpan or  search on metacpan

lib/API/PleskExpand/Accounts.pm  view on Meta::CPAN

=over 3

=item create()

Params:

  'select'             => 'optimal',
  'template-id'        =>  1,
  'attach_to_template' => 1, # attach account to a certain template
  'general_info'  => {
    login   => 'plesk_login',
    pname   => 'perldonal name',
    passwd  => 'userpasswd',
    status  => 0,                   # active
    cname   => '',                  # company name
    phone   => '',
    fax     => '',
    email   => '',
    address => '',
    city    => '',
    state   => '',                  # state, for USA only

lib/API/PleskExpand/Accounts.pm  view on Meta::CPAN


Return:

  $VAR1 = bless( {
    'answer_data' => [ {
        'server_id'       => '1',
        'status'          => 'ok',
        'tmpl_id'         => '1',
        'id'              => '15',
        'plesk_client_id' => '384',
        'login'           => 'suxdffffxx'
    } ],
        'error_codes' => ''
  }, 'API::Plesk::Response' );


Example (client deactivation):

  print Dumper $client->Accounts->modify(
    id => 10, 
    general_info => { status => 16 }

lib/API/PleskExpand/Accounts.pm  view on Meta::CPAN

# Modify element
# STATIC
sub modify {
    my %params = @_;
    
    if (ref $params{'general_info'} eq 'HASH') {

        my $filter = '';

        if ($params{'id'}) {
            $filter = create_filter(login_field_name => 'id', id => $params{'id'});
        } else {
            return ''; # filter required!
        }
    

        return create_node('set', $filter . '<!-- modify_client -->' . create_node('values',
            generate_info_block('gen_info', %{ $params{'general_info'} } ) ) );

    } else {
        return ''; # general_info field required !

lib/API/PleskExpand/Domains.pm  view on Meta::CPAN


=over 3

=item create()

Params:

  dname              => 'yandex.ru',   # domain name
  client_id          => 9,             # add domain to client with certain id
  'template-id'      => 1,             # domain template id
  ftp_login          => 'nrgsdasd',    # username for ftp 
  ftp_password       => 'dasdasd',     # password for ftp account
  attach_to_template => 1,             # attach domain to template ? 1 -- yes, 0 -- no

Return:

  $VAR1 = bless( {
    'answer_data' => [ {
        'server_id'     => '1',
        'status'        => 'ok',
        'expiration'    => '-1',

lib/API/PleskExpand/Domains.pm  view on Meta::CPAN


# Create element
# STATIC
sub create {

   my %params = @_;

    return '' unless $params{'dname'}        &&
                     #$params{'ip'}           &&
                     $params{'client_id'}    &&
                     $params{'ftp_login'}    &&
                     $params{'ftp_password'} &&
                     $params{'template-id'};

    $params{'attach_to_template'} ||= '';

    my $hosting_block = create_node('hosting',
        generate_info_block(
            'vrt_hst',
            'ftp_login'    => $params{'ftp_login'},
            'ftp_password' => $params{'ftp_password'},
        )
    );
    my $template_block =  create_node('tmpl_id', $params{'template-id'}) .
        ( $params{'attach_to_template'} ? create_node('attach_to_template', '') : '' );

    return create_node( 'add_use_template',
        create_node( 
            'gen_setup',
            create_node( 'name', $params{dname} ) .

t/expand.t  view on Meta::CPAN

    eval { API::PleskExpand->new(%TestData::online_expand_valid_params)->aaa__bbbccc() };
    like($our_warning, qr/aaa__bbbccc/,
         'Checking AUTOLOAD by calling undefined method.');
}


my %create_account_data = (
    'select'        => 'optimal',
    'template-id'   =>  1,
    'general_info'  => {
        login   => 'suxdffffxx',
        pname   => 'stdsdffafff',
        passwd  => '1234d5678',
        status  => 0,
        cname   => '',
        phone   => '',
        fax     => '',
        email   => '',
        address => '',
        city    => '',
        state   => '',
        pcode   => '',
        country => 'RU',
    }
);


my $create_request = API::PleskExpand::Accounts::create( %create_account_data );

is_string($create_request, $_, 'create account test') for
'<add_use_template><gen_info><address></address><city></city><cname></cname>'          .
'<country>RU</country><email></email><fax></fax><login>suxdffffxx</login>'             .
'<passwd>1234d5678</passwd><pcode></pcode><phone></phone><pname>stdsdffafff</pname>'   .
'<state></state><status>0</status></gen_info><!-- create_client -->'                   .
'<tmpl_id>1</tmpl_id><server_auto><optimal></optimal></server_auto></add_use_template>';

$create_request = API::PleskExpand::Accounts::create(
    %create_account_data,
    'attach_to_template' => 1 
);

is_string($create_request, $_, 'create account test') for 
'<add_use_template><gen_info><address></address><city></city><cname></cname>'        .
'<country>RU</country><email></email><fax></fax><login>suxdffffxx</login>'           .
'<passwd>1234d5678</passwd><pcode></pcode><phone></phone><pname>stdsdffafff</pname>' .
'<state></state><status>0</status></gen_info><!-- create_client -->'                 .
'<tmpl_id>1</tmpl_id><attach_to_template></attach_to_template><server_auto>'         .
'<optimal></optimal></server_auto></add_use_template>';


is_deeply(
    API::PleskExpand::Accounts::create( %create_account_data, select => ''),  
    '',
    'Manual select without server_id param'

t/expand.t  view on Meta::CPAN



is_string( $modify_query_alter, $_, 'modify account test') for 
'<set><filter><id>5</id></filter><!-- modify_client --><values>' .
'<gen_info><status>0</status></gen_info></values></set>';

my %new_domain_data = (
    dname               => 'y2a1ddsdfandex.ru',
    client_id           => 16,
    'template-id'       => 1,
    ftp_login           => 'nrddgddsdasd',
    ftp_password        => 'dadsdasd',
);

my $create_domain = API::PleskExpand::Domains::create( %new_domain_data );


is_string( $create_domain, $_, 'modify account test') for 
'<add_use_template><gen_setup><name>y2a1ddsdfandex.ru</name>'  .
'<client_id>16</client_id><status>0</status></gen_setup>'      .
'<hosting><vrt_hst><ftp_login>nrddgddsdasd</ftp_login>'        .
'<ftp_password>dadsdasd</ftp_password></vrt_hst></hosting>'    .
'<!-- create_domain --><tmpl_id>1</tmpl_id></add_use_template>';

$create_domain = API::PleskExpand::Domains::create( %new_domain_data, attach_to_template  => 1 );

is_string( $create_domain, $_, 'modify account test') for
'<add_use_template><gen_setup><name>y2a1ddsdfandex.ru</name>' .
'<client_id>16</client_id><status>0</status></gen_setup>'     .
'<hosting><vrt_hst><ftp_login>nrddgddsdasd</ftp_login>'       .
'<ftp_password>dadsdasd</ftp_password></vrt_hst></hosting>'   .
'<!-- create_domain --><tmpl_id>1</tmpl_id>'                  .
'<attach_to_template></attach_to_template></add_use_template>';

$expand_client->{dump_headers} = 1; # debugg =)

is_deeply(
    $expand_client->_execute_query('<add_use_template><!-- create_domain --></add_use_template>'),
    {
        ':HTTP_AUTH_LOGIN'  => $TestData::online_expand_valid_params{'username'},

t/expand.t  view on Meta::CPAN



is_deeply(
    API::PleskExpand::Accounts::modify_response_parse( $_ ), 
    {
        'server_id' => '1',
        'status' => 'ok',
        'tmpl_id' => '1',
        'id' => '32',
        'plesk_client_id' => '395',
        'login' => 'aseaasdsassrews'
    },
    'parse success modify xml response'
) for '<?xml version="1.0" encoding="UTF-8" standalone="no" ?><packet version="2.2.4.1">' .
      '<set><result><status>ok</status><id>32</id><server_id>1</server_id><tmpl_id>1</tmpl_id>' .
      '<plesk_client_id>395</plesk_client_id><login>aseaasdsassrews</login></result></set></packet>';


is_deeply(
    API::PleskExpand::Accounts::delete_response_parse( $_ ), 
    {
        'server_id' => '1',
        'status' => 'ok',
        'id' => '33',
    },
    'parse success delete xml response'

t/expand.t  view on Meta::CPAN




exit unless $ENV{'online_stress_tests'};

my ($domain_template_id, $client_template_id);
$domain_template_id = $client_template_id = $ENV{template_id} || 1;

diag "Online tests start!";
# 5 tests -- full set !!!
my $login = $ENV{'online_stress_tests_login'} || 'expandtestaccount';
my $create_account_result = $expand_client->Accounts->create(
    'select'             => 'optimal',
    'template-id'        =>  $client_template_id,
    'attach_to_template' => 1,
    'general_info'  => {
        login   => $login,
        pname   => $login,
        passwd  => 'asdasdasd',
        status  => 0,
        cname   => '',
        phone   => '',
        fax     => '',
        email   => '',
        address => '',
        city    => '',
        state   => '',
        pcode   => '',

t/expand.t  view on Meta::CPAN

            id           => $client_id,
        );

        my $plesk_id = $activate_result->get_data->[0]->{plesk_client_id};

        if ($activate_result->is_success) {
            pass "Activation success!";

            
            my $create_domain = $expand_client->Domains->create(
                dname                => $login . '.ru',
                client_id            => $client_id,
                'template-id'        => $domain_template_id,
                'attach_to_template' => 1,
                ftp_login            => $login,
                ftp_password         => 'afsfsaf',
            );

        
            if ($create_domain->is_success) {
   
                pass "Create domain successful";

                my $nop_result = $expand_client->Accounts->modify(
                    general_info => { },         # blank operation



( run in 1.260 second using v1.01-cache-2.11-cpan-49f99fa48dc )