Webservice/OVH.pm

filter: Statementstmt 38.3% 38 / 99 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 57.1% 12 / 21 Podpod 100% 9 / 9 totaltotal 42.4% 59 / 139 CC 5 SCAR 13.7
CC
5
Cov
36%
new_from_json
12.0
new
12.0
set_timeout
2.0
CRAP 3.9
« Webservice/OVH/Order/Hosting.pm ↑ Summary
1 package Webservice::OVH;
2  
3 =encoding utf-8
4  
5 =head1 NAME
6  
7 Webservice::OVH - A perl representation of the ovh-api
8  
9 =head1 SYNOPSIS
10  
11 use Webservice::OVH;
12  
13 my $ovh = Webservice::OVH->new("credentials.json");
14  
15 my $ovh = Webservice::OVH->new(application_key => $key, application_secret => $secret, consumer_key => $token);
16  
17 my $services = $ovh->domain->services;
18  
19 foreach my $service (@$services) {
20
21 my $last_update = $service->last_update;
22 print $last_update->datetime;
23 }
24  
25 =head1 DESCRIPTION
26  
27 This module reflects the path structure of the ovh web-api.
28 This is the base object from where all api calls originate.
29  
30 This module uses the perl api module provided by ovh.
31  
32 =begin html
33  
34 <p><center><img src="https://raw.githubusercontent.com/itnode/Webservice-OVH/master/inc/API_HowTo.png"></center></p>
35  
36 =end html
37  
38  
39 =head1 METHODS
40  
41 =cut
42  
43 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 36 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 36 ▶use Carp qw{ carp croak };
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 36 our $VERSION = 0.48;
48  
49 # api module provided by ovh
50 36 ▶use OVH::OvhApi;
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 # sub-modules
53 36 ▶use Webservice::OVH::Domain;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 36 ▶use Webservice::OVH::Me;
Subroutine BEGIN: called CC=1 SCAR=0.0
55 36 ▶use Webservice::OVH::Order;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 36 ▶use Webservice::OVH::Email;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 36 ▶use Webservice::OVH::Cloud;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 36 ▶use Webservice::OVH::Hosting;
Subroutine BEGIN: called CC=1 SCAR=0.0
59  
60 # other requirements
61 36 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 36 ▶use File::Slurp qw(read_file);
Subroutine BEGIN: called CC=1 SCAR=0.0
63  
64 =head2 new_from_json
65  
66 Creates an api Object based on credentials in a json File
67  
68 =over
69  
70 =item * Parameter: $file_json - dir to json file
71  
72 =item * Return: L<Webservice::OVH>
73  
74 =item * Synopsis: Webservice::OVH->new_from_json("path/file");
75  
76 =back
77  
78 =over 2
79  
80 =item * application_key is generated when creating an application via ovh web interface
81  
82 =item * application_secret is generated when creating an application via ovh web interface
83  
84 =item * consumer_key must be requested through ovh authentification
85  
86 =item * timeout timeout in milliseconds, warning some request may take a while
87  
88 =back
89  
90 =cut
91  
92 0 ▶sub new_from_json {
Subroutine new_from_json: not called CC=3 SCAR=24.8
Pod documented
93  
94 0 my ( $class, $file_json ) = @_;
95  
96 # slurp file
97 0 my $json = read_file($file_json, { binmode => ':raw' });
98  
99 # decode json
100 0 my $Json = JSON->new->allow_nonref;
101 0 my $data = $Json->decode($json);
102  
103 # check for missing parameters in the json file
104 0 my @keys = qw{ application_key application_secret consumer_key };
105 0 ▶ if ( my @missing_parameters = grep { not $data->{$_} } @keys ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@missing_parameters) = grep({not $data->{$_};} @keys)) 0 0 0
106  
107 0 croak "Missing parameter: @missing_parameters";
108 }
109  
110 0 my $self = bless {}, $class;
111  
112 # Create internal objects to mirror the web api of ovh
113 0 my $api_wrapper = OVH::OvhApi->new( 'type' => "https://eu.api.ovh.com/1.0", applicationKey => $data->{application_key}, applicationSecret => $data->{application_secret}, consumerKey => $data->{consumer_key} );
114 0 my $domain = Webservice::OVH::Domain->_new( wrapper => $api_wrapper, module => $self );
115 0 my $me = Webservice::OVH::Me->_new( wrapper => $api_wrapper, module => $self );
116 0 my $order = Webservice::OVH::Order->_new( wrapper => $api_wrapper, module => $self );
117 0 my $email = Webservice::OVH::Email->_new( wrapper => $api_wrapper, module => $self );
118 0 my $cloud = Webservice::OVH::Cloud->_new( wrapper => $api_wrapper, module => $self );
119 0 my $hosting = Webservice::OVH::Hosting->_new( wrapper => $api_wrapper, module => $self );
120  
121 # Timeout can be also set in the json file
122 0 ▶ OVH::OvhApi->setRequestTimeout( timeout => $data->{timeout} || 120 );
Condition0%0/2
$data->{'timeout'} || 120
l!l
00
MC/DC0%0/1
$data->{'timeout'} || 120
$data->{'timeout'}
Truth table0%0/2
A
A= $data->{'timeout'}
Aresult
11
00
123  
124 # Setting private variables
125 0 $self->{_domain} = $domain;
126 0 $self->{_me} = $me;
127 0 $self->{_order} = $order;
128 0 $self->{_api_wrapper} = $api_wrapper;
129 0 $self->{_email} = $email;
130 0 $self->{_cloud} = $cloud;
131 0 $self->{_hosting} = $hosting;
132  
133 0 return $self;
134 }
135  
136 =head2 new
137  
138 Create the api object. Credentials are given directly via %params
139 Credentials can be generated via ovh web interface and ovh authentification
140  
141 =over
142  
143 =item * Parameter: %params - application_key => value, application_secret => value, consumer_key => value
144  
145 =item * Return: L<Webservice::OVH>
146  
147 =item * Synopsis: Webservice::OVH->new(application_key => $key, application_secret => $secret, consumer_key => $token);
148  
149 =back
150  
151 =cut
152  
153 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
154  
155 0 my ( $class, %params ) = @_;
156  
157 0 my @keys = qw{ application_key application_secret consumer_key };
158  
159 0 ▶ if ( my @missing_parameters = grep { not $params{$_} } @keys ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@missing_parameters) = grep({not $params{$_};} @keys)) 0 0 0
160  
161 0 croak "Missing parameter: @missing_parameters";
162 }
163  
164 0 my $self = bless {}, $class;
165  
166 0 my $api_wrapper = OVH::OvhApi->new( 'type' => "https://eu.api.ovh.com/1.0", applicationKey => $params{application_key}, applicationSecret => $params{application_secret}, consumerKey => $params{consumer_key} );
167 0 my $domain = Webservice::OVH::Domain->_new( wrapper => $api_wrapper, module => $self );
168 0 my $me = Webservice::OVH::Me->_new( wrapper => $api_wrapper, module => $self );
169 0 my $order = Webservice::OVH::Order->_new( wrapper => $api_wrapper, module => $self );
170 0 my $email = Webservice::OVH::Email->_new( wrapper => $api_wrapper, module => $self );
171 0 my $cloud = Webservice::OVH::Cloud->_new( wrapper => $api_wrapper, module => $self );
172 0 my $hosting = Webservice::OVH::Hosting->_new( wrapper => $api_wrapper, module => $self );
173  
174 0 ▶ OVH::OvhApi->setRequestTimeout( timeout => $params{timeout} || 120 );
Condition0%0/2
$params{'timeout'} || 120
l!l
00
MC/DC0%0/1
$params{'timeout'} || 120
$params{'timeout'}
Truth table0%0/2
A
A= $params{'timeout'}
Aresult
11
00
175  
176 0 $self->{_domain} = $domain;
177 0 $self->{_me} = $me;
178 0 $self->{_order} = $order;
179 0 $self->{_api_wrapper} = $api_wrapper;
180 0 $self->{_email} = $email;
181 0 $self->{_cloud} = $cloud;
182 0 $self->{_hosting} = $hosting;
183  
184 0 return $self;
185 }
186  
187 =head2 set_timeout
188  
189 Sets the timeout of the underlying LWP::Agent
190  
191 =over
192  
193 =item * Parameter: timeout - in milliseconds default 120
194  
195 =item * Synopsis: Webservice::OVH->set_timeout(120);
196  
197 =back
198  
199 =cut
200  
201 0 ▶sub set_timeout {
Subroutine set_timeout: not called CC=1 SCAR=6.9
Pod documented
202  
203 0 my ( $class, $timeout ) = @_;
204  
205 0 OVH::OvhApi->setRequestTimeout( timeout => $timeout );
206 }
207  
208 =head2 domain
209  
210 Main access to all /domain/ api methods
211  
212 =over
213  
214 =item * Return: L<Webservice::OVH::Domain>
215  
216 =item * Synopsis: $ovh->domain;
217  
218 =back
219  
220 =cut
221  
222 0 ▶sub domain {
Subroutine domain: not called CC=1 SCAR=6.9
Pod documented
223  
224 0 my ($self) = @_;
225  
226 0 return $self->{_domain};
227 }
228  
229 =head2 me
230  
231 Main access to all /me/ api methods
232  
233 =over
234  
235 =item * Return: L<Webservice::OVH::Me>
236  
237 =item * Synopsis: $ovh->me;
238  
239 =back
240  
241 =cut
242  
243 0 ▶sub me {
Subroutine me: not called CC=1 SCAR=6.9
Pod documented
244  
245 0 my ($self) = @_;
246  
247 0 return $self->{_me};
248 }
249  
250 =head2 order
251  
252 Main access to all /order/ api methods
253  
254 =over
255  
256 =item * Return: L<Webservice::OVH::Order>
257  
258 =item * Synopsis: $ovh->order;
259  
260 =back
261  
262 =cut
263  
264 0 ▶sub order {
Subroutine order: not called CC=1 SCAR=6.9
Pod documented
265  
266 0 my ($self) = @_;
267  
268 0 return $self->{_order};
269 }
270  
271 =head2 email
272  
273 Main access to all /email/ api methods
274  
275 =over
276  
277 =item * Return: L<Webservice::OVH::Email>
278  
279 =item * Synopsis: $ovh->email;
280  
281 =back
282  
283 =cut
284  
285 0 ▶sub email {
Subroutine email: not called CC=1 SCAR=6.9
Pod documented
286  
287 0 my ($self) = @_;
288  
289 0 return $self->{_email};
290 }
291  
292 =head2 cloud
293  
294 Main access to all /cloud/ api methods
295  
296 =over
297  
298 =item * Return: L<Webservice::OVH::Cloud>
299  
300 =item * Synopsis: $ovh->cloud;
301  
302 =back
303  
304 =cut
305  
306 0 ▶sub cloud {
Subroutine cloud: not called CC=1 SCAR=6.9
Pod documented
307  
308 0 my ($self) = @_;
309  
310 0 return $self->{_cloud};
311 }
312  
313 =head2 hosting
314  
315 Main access to all /hosting/ api methods
316  
317 =over
318  
319 =item * Return: L<Webservice::OVH::Cloud>
320  
321 =item * Synopsis: $ovh->cloud;
322  
323 =back
324  
325 =cut
326  
327 0 ▶sub hosting {
Subroutine hosting: not called CC=1 SCAR=6.9
Pod documented
328  
329 0 my ($self) = @_;
330  
331 0 return $self->{_hosting};
332 }
333  
334 =head1 AUTHOR
335  
336 Patrick Jendral
337  
338 =head1 COPYRIGHT AND LICENSE
339  
340 This library is free software; you may redistribute it and/or modify it under the same terms as Perl itself.
341  
342 =cut
343  
344 36 1;
« Webservice/OVH/Order/Hosting.pm ↑ Summary