File Coverage

blib/lib/API/PleskExpand.pm
Criterion Covered Total %
statement 26 38 68.4
branch 1 10 10.0
condition 0 9 0.0
subroutine 8 9 88.8
pod 1 1 100.0
total 36 67 53.7


line stmt bran cond sub pod time code
1             #
2             # DESCRIPTION:
3             # Plesk Expand communicate interface. Main class.
4             # AUTHORS:
5             # Pavel Odintsov (nrg)
6             #
7             #========================================================================
8             package API::PleskExpand;
9              
10 1     1   46066 use strict;
  1         3  
  1         31  
11 1     1   5 use warnings;
  1         2  
  1         27  
12 1     1   5 use lib qw(../..);
  1         7  
  1         5  
13              
14 1     1   1009 use API::Plesk;
  1         109789  
  1         41  
15 1     1   10 use base 'API::Plesk';
  1         2  
  1         180  
16              
17 1     1   6 use Data::Dumper;
  1         2  
  1         56  
18 1     1   6 use Carp;
  1         2  
  1         560  
19              
20             our $VERSION = '1.07';
21              
22             =head1 NAME
23              
24             API::PleskExpand - OOP interface to the Plesk Expand XML API (http://www.parallels.com/en/products/plesk/expand/).
25              
26             =head1 SYNOPSIS
27              
28             use API::PleskExpand;
29             use API::Plesk::Response;
30              
31             my $expand_client = API::PleskExpand->new(%params);
32             my $res = $expand_client->Func_Module->operation_type(%params);
33              
34             if ($res->is_success) {
35             $res->get_data; # return arr ref of answer blocks
36             }
37              
38             =head1 DESCRIPTION
39              
40             At present the module provides interaction with Plesk Expand 2.2.4 (API 2.2.4.1). Complete support of operations with Accounts, partial support of work with domains. Support of addition of domains to user Accounts.
41              
42             API::PleskExpand module gives the convenient interface for addition of new functions. Extensions represent modules in a folder Plesk with definitions of demanded functions. Each demanded operation is described by two functions: op and op_response_parse. The first sub generates XML query to Plesk, the second is responsible for parse XML answer and its representation in Perl Native Structures. As a template for a writing of own expansions is better to use API/PleskExpand/Accounts.pm. In module API::Plesk::Methods we can find service functions for a writing our extensions.
43              
44             For example, here the set of subs in the Accounts module is those.
45              
46             create / create_response_parse
47             modify / modify_response_parse
48             delete / delete_response_parse
49             get / get_response_parse
50              
51             =head1 EXPORT
52              
53             Nothing.
54              
55             =head1 METHODS
56              
57             =over 3
58              
59             =item new(%params)
60              
61             Create new class instance.
62              
63             Required params:
64             api_version -- default: 2.2.4.1
65             username -- Expand user name (root as default).
66             password -- Expand password.
67             url -- full url to Expand XML RPC gate (https://ip.ad.dr.ess::8442/webgate.php').
68              
69             =cut
70              
71              
72              
73             sub new {
74 2     2 1 391 (undef) = shift @_;
75 2         14 my $self = __PACKAGE__->SUPER::new(@_);
76 2         42 $self->{package_name} = __PACKAGE__;
77              
78 2 50       6 unless ($self->{api_version}) {
79 0         0 $self->{api_version} = '2.2.4.1';
80             }
81              
82 2         19 return $self;
83             }
84              
85              
86             =item AUTOLOADed methods
87              
88             All other methods are loaded by Autoload from corresponding modules.
89             Execute some operations (see API::PleskExpand::* modules documentation).
90              
91             Example:
92              
93             my $res = $expand_client->Func_Module->operation_type(%params);
94             # Func_Module -- module in API/PleskExpand folder
95             # operation_type -- sub which defined in Func_Module.
96             # params hash used as @_ for operation_type sub.
97              
98             =back
99              
100             =cut
101              
102              
103              
104             # OVERRIDE, INSTANCE(xml_request)
105             sub _execute_query {
106 0     0     my ($self, $xml_request) = @_;
107              
108             # packet version override for
109 0           my $packet_version = $self->{'api_version'};
110              
111 0 0         return unless $xml_request;
112 0           my $xml_packet_struct = <<" DOC";
113            
114            
115             $xml_request
116            
117             DOC
118              
119 0           my $operator = '';
120            
121 0 0 0       if ($xml_request =~ m/create_client/is or
    0 0        
      0        
122             $xml_request =~ m/del_client/is or
123             $xml_request =~ m/modify_client/is or
124             $xml_request =~ m/get_client/is
125             ) {
126 0           $operator = 'exp_plesk_client';
127             } elsif ($xml_request =~ m/create_domain/is) {
128 0           $operator = 'exp_plesk_domain';
129             }
130              
131 0           my $headers = {
132             ':HTTP_AUTH_LOGIN' => $self->{'username'},
133             ':HTTP_AUTH_PASSWD' => $self->{'password'},
134             ':HTTP_AUTH_OP' => $operator
135             };
136              
137 0 0         return $headers if $self->{'dump_headers'};
138              
139 0           return API::Plesk::xml_http_req(
140             $self->{'url'},
141             $xml_packet_struct,
142             headers => $headers
143             );
144             }
145              
146             1;
147             __END__