Webservice/OVH/Me.pm

filter: Statementstmt 27.3% 26 / 95 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 24 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 47.0% 8 / 17 Podpod 100% 8 / 8 totaltotal 23.3% 42 / 180 CC 23 SCAR 29.6
CC
23
Cov
19%
orders
42.0
bills
42.0
contacts
20.0
CRAP 19.4
« Webservice/OVH/Order/Email/Domain.pm ↑ Summary Webservice/OVH/Cloud/Project/IP.pm »
1 package Webservice::OVH::Me;
2  
3 =encoding utf-8
4  
5 =head1 NAME
6  
7 Webservice::OVH::Me
8  
9 =head1 SYNOPSIS
10  
11 use Webservice::OVH;
12
13 my $ovh = Webservice::OVH->new_from_json("credentials.json");
14
15 my $contacts = $ovh->me->contacts;
16 my $tasks_contact_change = $ovh->me->tasks_contact_change;
17 my $orders = $ovh->me->orders(DateTime->now->sub(days => -1), DateTime->now);
18 my $bills = $ovh->me->bills(DateTime->now->sub(days => -1), DateTime->now);
19
20 my $bill_id = $bills->[0]->id;
21 my $order_id = $orders->[0]->id;
22
23 my $bill = $me->ovh->bill($bill_id);
24 my $order = $me->ovh->bill($order_id);
25
26 print $bill->pdf_url;
27 print $order->url;
28  
29 =head1 DESCRIPTION
30  
31 Module support for now only basic retrieval methods for contacs, tasks, orders and bills
32  
33 =head1 METHODS
34  
35 =cut
36  
37 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 36 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 36 ▶use Carp qw{ carp croak };
Subroutine BEGIN: called CC=1 SCAR=0.0
40 36 ▶use Webservice::OVH::Helper;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 36 our $VERSION = 0.48;
43  
44 # sub modules
45 36 ▶use Webservice::OVH::Me::Contact;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 36 ▶use Webservice::OVH::Me::Order;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 36 ▶use Webservice::OVH::Me::Bill;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 36 ▶use Webservice::OVH::Me::Task;
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 =head2 _new
51  
52 Internal Method to create the me object.
53 This method is not ment to be called external.
54  
55 =over
56  
57 =item * Parameter: $api_wrapper - ovh api wrapper object, $module - root object
58  
59 =item * Return: L<Webservice::OVH::Me>
60  
61 =item * Synopsis: Webservice::OVH::Me->_new($ovh_api_wrapper, $self);
62  
63 =back
64  
65 =cut
66  
67 0 ▶sub _new {
Subroutine _new: not called CC=3 SCAR=24.8
68  
69 0 my ( $class, %params ) = @_;
70  
71 0 ▶ die "Missing module" unless $params{module};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"module"} 0 0 0
72 0 ▶ die "Missing wrapper" unless $params{wrapper};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"wrapper"} 0 0 0
73  
74 0 my $module = $params{module};
75 0 my $api_wrapper = $params{wrapper};
76  
77 0 my $self = bless { _module => $module, _api_wrapper => $api_wrapper, _contacts => {}, _tasks_contact_change => {}, _orders => {}, _bills => {} }, $class;
78  
79 0 return $self;
80 }
81  
82 =head2 contacts
83  
84 Produces an array of all available contacts that are stored for the used account.
85  
86 =over
87  
88 =item * Return: ARRAY
89  
90 =item * Synopsis: my $contacts = $ovh->me->contacs();
91  
92 =back
93  
94 =cut
95  
96 0 ▶sub contacts {
Subroutine contacts: not called CC=4 SCAR=30.0
Pod documented
97  
98 0 my ($self) = @_;
99  
100 0 my $api = $self->{_api_wrapper};
101 0 my $response = $api->rawCall( method => 'get', path => "/me/contact", noSignature => 0 );
102 0 ▶ croak $response->error if $response->error;
Branch: 1 branch
BranchTrueFalseTotal
if $response->error 0 0 0
103  
104 0 my $contact_ids = $response->content;
105 0 my $contacts = [];
106  
107 0 foreach my $contact_id (@$contact_ids) {
108  
109 0 ▶ my $contact = $self->{_contacts}{$contact_id} = $self->{_contacts}{$contact_id} || Webservice::OVH::Me::Contact->_new_existing( wrapper => $api, id => $contact_id, module => $self->{_module} );
Condition0%0/3
$self->{'_contacts'}{$contact_id} || 'Webservice::OVH::Me::Contact'->_new_existing('wrapper', $api, 'id', $contact_id, 'module', $self->{'_module'})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'_contacts'}{$contact_id} || 'Webservice::OVH::Me::Contact'->_new_existing('wrapper', $api, 'id', $contact_id, 'module', $self->{'_module'})
$self->{'_contacts'}{$contact_id} 'Webservice::OVH::Me::Contact'->_new_existing('wrapper', $api, 'id', $contact_id, 'module', $self->{'_module'})
Truth table0%0/3
A || B
A= $self->{'_contacts'}{$contact_id}B= 'Webservice::OVH::Me::Contact'->_new_existing('wrapper', $api, 'id', $contact_id, 'module', $self->{'_module'})
ABresult
1X1
011
000
110 0 push @$contacts, $contact;
111 }
112  
113 0 return $contacts;
114 }
115  
116 =head2 contact
117  
118 Returns a single contact by id
119  
120 =over
121  
122 =item * Parameter: $contact_id - id
123  
124 =item * Return: L<Webservice::OVH::Me::Contact>
125  
126 =item * Synopsis: my $contact = $ovh->me->contact(1234567);
127  
128 =back
129  
130 =cut
131  
132 0 ▶sub contact {
Subroutine contact: not called CC=2 SCAR=17.9
Pod documented
133  
134 0 my ( $self, $contact_id ) = @_;
135  
136 0 my $api = $self->{_api_wrapper};
137 0 ▶ my $contact = $self->{_contacts}{$contact_id} = $self->{_contacts}{$contact_id} || Webservice::OVH::Me::Contact->_new_existing( wrapper => $api, id => $contact_id, module => $self->{_module} );
Condition0%0/3
$self->{'_contacts'}{$contact_id} || 'Webservice::OVH::Me::Contact'->_new_existing('wrapper', $api, 'id', $contact_id, 'module', $self->{'_module'})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'_contacts'}{$contact_id} || 'Webservice::OVH::Me::Contact'->_new_existing('wrapper', $api, 'id', $contact_id, 'module', $self->{'_module'})
$self->{'_contacts'}{$contact_id} 'Webservice::OVH::Me::Contact'->_new_existing('wrapper', $api, 'id', $contact_id, 'module', $self->{'_module'})
Truth table0%0/3
A || B
A= $self->{'_contacts'}{$contact_id}B= 'Webservice::OVH::Me::Contact'->_new_existing('wrapper', $api, 'id', $contact_id, 'module', $self->{'_module'})
ABresult
1X1
011
000
138  
139 0 return $contact;
140 }
141  
142 =head2 tasks_contact_change
143  
144 Produces an array of all available contact change tasks.
145  
146 =over
147  
148 =item * Return: ARRAY
149  
150 =item * Synopsis: my $tasks = $ovh->me->tasks_contact_change();
151  
152 =back
153  
154 =cut
155  
156 0 ▶sub tasks_contact_change {
Subroutine tasks_contact_change: not called CC=4 SCAR=30.0
Pod documented
157  
158 0 my ($self) = @_;
159  
160 0 my $api = $self->{_api_wrapper};
161 0 my $response = $api->rawCall( method => 'get', path => "/me/task/contactChange", noSignature => 0 );
162 0 ▶ croak $response->error if $response->error;
Branch: 1 branch
BranchTrueFalseTotal
if $response->error 0 0 0
163  
164 0 my $task_ids = $response->content;
165 0 my $tasks = [];
166  
167 0 foreach my $task_id (@$task_ids) {
168  
169 0 ▶ my $task = $self->{_tasks_contact_change}{$task_id} = $self->{_tasks_contact_change}{$task_id} || Webservice::OVH::Me::Task->_new( wrapper => $api, type => "contact_change", id => $task_id, module => $self->{_module} );
Condition0%0/3
$self->{'_tasks_contact_change'}{$task_id} || 'Webservice::OVH::Me::Task'->_new('wrapper', $api, 'type', 'contact_change', 'id', $task_id, 'module', $self->{'_module'})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'_tasks_contact_change'}{$task_id} || 'Webservice::OVH::Me::Task'->_new('wrapper', $api, 'type', 'contact_change', 'id', $task_id, 'module', $self->{'_module'})
$self->{'_tasks_contact_change'}{$task_id} 'Webservice::OVH::Me::Task'->_new('wrapper', $api, 'type', 'contact_change', 'id', $task_id, 'module', $self->{'_module'})
Truth table0%0/3
A || B
A= $self->{'_tasks_contact_change'}{$task_id}B= 'Webservice::OVH::Me::Task'->_new('wrapper', $api, 'type', 'contact_change', 'id', $task_id, 'module', $self->{'_module'})
ABresult
1X1
011
000
170 0 push @$tasks, $task;
171 }
172  
173 0 return $tasks;
174 }
175  
176 =head2 task_contact_change
177  
178 Returns a single contact change task by id
179  
180 =over
181  
182 =item * Parameter: $task_id - id
183  
184 =item * Return: L<Webservice::OVH::Me::Task>
185  
186 =item * Synopsis: my $contact = $ovh->me->task_contact_change(1234567);
187  
188 =back
189  
190 =cut
191  
192 0 ▶sub task_contact_change {
Subroutine task_contact_change: not called CC=2 SCAR=17.9
Pod documented
193  
194 0 my ( $self, $task_id ) = @_;
195  
196 0 my $api = $self->{_api_wrapper};
197 0 ▶ my $task = $self->{_tasks_contact_change}{$task_id} = $self->{_tasks_contact_change}{$task_id} || Webservice::OVH::Me::Task->_new( wrapper => $api, type => "contact_change", id => $task_id, module => $self->{_module} );
Condition0%0/3
$self->{'_tasks_contact_change'}{$task_id} || 'Webservice::OVH::Me::Task'->_new('wrapper', $api, 'type', 'contact_change', 'id', $task_id, 'module', $self->{'_module'})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'_tasks_contact_change'}{$task_id} || 'Webservice::OVH::Me::Task'->_new('wrapper', $api, 'type', 'contact_change', 'id', $task_id, 'module', $self->{'_module'})
$self->{'_tasks_contact_change'}{$task_id} 'Webservice::OVH::Me::Task'->_new('wrapper', $api, 'type', 'contact_change', 'id', $task_id, 'module', $self->{'_module'})
Truth table0%0/3
A || B
A= $self->{'_tasks_contact_change'}{$task_id}B= 'Webservice::OVH::Me::Task'->_new('wrapper', $api, 'type', 'contact_change', 'id', $task_id, 'module', $self->{'_module'})
ABresult
1X1
011
000
198  
199 0 return $task;
200  
201 }
202  
203 =head2 orders
204  
205 Produces an array of all available orders.
206 Orders can be optionally filtered by date.
207  
208 =over
209  
210 =item * Parameter: $date_from - optional filter DateTime, $date_to - optional filter DateTime
211  
212 =item * Return: ARRAY
213  
214 =item * Synopsis: my $orders = $ovh->me->orders(DateTime->new(), DateTime->new());
215  
216 =back
217  
218 =cut
219  
220 0 ▶sub orders {
Subroutine orders: not called CC=6 SCAR=37.4
Pod documented
221  
222 0 my ( $self, $date_from, $date_to ) = @_;
223  
224 0 ▶ my $str_date_from = $date_from ? $date_from->strftime("%Y-%m-%d") : "";
Branch: 1 branch
BranchTrueFalseTotal
$date_from ? : 0 0 0
225 0 ▶ my $str_date_to = $date_to ? $date_to->strftime("%Y-%m-%d") : "";
Branch: 1 branch
BranchTrueFalseTotal
$date_to ? : 0 0 0
226 0 my $filter = Webservice::OVH::Helper->construct_filter( "date.from" => $str_date_from, "date.to" => $str_date_to );
227  
228 0 my $api = $self->{_api_wrapper};
229 0 my $response = $api->rawCall( method => 'get', path => "/me/order$filter", noSignature => 0 );
230 0 ▶ croak $response->error if $response->error;
Branch: 1 branch
BranchTrueFalseTotal
if $response->error 0 0 0
231  
232 0 my $order_ids = $response->content;
233 0 my $orders = [];
234  
235 0 foreach my $order_id (@$order_ids) {
236  
237 0 ▶ my $order = $self->{_orders}{$order_id} = $self->{_orders}{$order_id} || Webservice::OVH::Me::Order->_new( wrapper => $api, id => $order_id, module => $self->{_module} );
Condition0%0/3
$self->{'_orders'}{$order_id} || 'Webservice::OVH::Me::Order'->_new('wrapper', $api, 'id', $order_id, 'module', $self->{'_module'})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'_orders'}{$order_id} || 'Webservice::OVH::Me::Order'->_new('wrapper', $api, 'id', $order_id, 'module', $self->{'_module'})
$self->{'_orders'}{$order_id} 'Webservice::OVH::Me::Order'->_new('wrapper', $api, 'id', $order_id, 'module', $self->{'_module'})
Truth table0%0/3
A || B
A= $self->{'_orders'}{$order_id}B= 'Webservice::OVH::Me::Order'->_new('wrapper', $api, 'id', $order_id, 'module', $self->{'_module'})
ABresult
1X1
011
000
238 0 push @$orders, $order;
239 }
240  
241 0 return $orders;
242 }
243  
244 =head2 order
245  
246 Returns a single order by id
247  
248 =over
249  
250 =item * Parameter: $order_id - id
251  
252 =item * Return: L<Webservice::OVH::Me::Order>
253  
254 =item * Synopsis: my $order = $ovh->me->order(1234567);
255  
256 =back
257  
258 =cut
259  
260 0 ▶sub order {
Subroutine order: not called CC=2 SCAR=17.9
Pod documented
261  
262 0 my ( $self, $order_id ) = @_;
263  
264 0 my $api = $self->{_api_wrapper};
265 0 ▶ my $order = $self->{_orders}{$order_id} = $self->{_orders}{$order_id} || Webservice::OVH::Me::Order->_new( wrapper => $api, id => $order_id, module => $self->{_module} );
Condition0%0/3
$self->{'_orders'}{$order_id} || 'Webservice::OVH::Me::Order'->_new('wrapper', $api, 'id', $order_id, 'module', $self->{'_module'})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'_orders'}{$order_id} || 'Webservice::OVH::Me::Order'->_new('wrapper', $api, 'id', $order_id, 'module', $self->{'_module'})
$self->{'_orders'}{$order_id} 'Webservice::OVH::Me::Order'->_new('wrapper', $api, 'id', $order_id, 'module', $self->{'_module'})
Truth table0%0/3
A || B
A= $self->{'_orders'}{$order_id}B= 'Webservice::OVH::Me::Order'->_new('wrapper', $api, 'id', $order_id, 'module', $self->{'_module'})
ABresult
1X1
011
000
266  
267 0 return $order;
268 }
269  
270 =head2 bill
271  
272 Returns a single bill by id
273  
274 =over
275  
276 =item * Parameter: $bill_id - id
277  
278 =item * Return: L<Webservice::OVH::Me::Bill>
279  
280 =item * Synopsis: my $order = $ovh->me->bill(1234567);
281  
282 =back
283  
284 =cut
285  
286 0 ▶sub bill {
Subroutine bill: not called CC=2 SCAR=17.9
Pod documented
287  
288 0 my ( $self, $bill_id ) = @_;
289  
290 0 my $api = $self->{_api_wrapper};
291 0 ▶ my $bill = $self->{_bills}{$bill_id} = $self->{_bills}{$bill_id} || Webservice::OVH::Me::Bill->_new( wrapper => $api, id => $bill_id, module => $self->{_module} );
Condition0%0/3
$self->{'_bills'}{$bill_id} || 'Webservice::OVH::Me::Bill'->_new('wrapper', $api, 'id', $bill_id, 'module', $self->{'_module'})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'_bills'}{$bill_id} || 'Webservice::OVH::Me::Bill'->_new('wrapper', $api, 'id', $bill_id, 'module', $self->{'_module'})
$self->{'_bills'}{$bill_id} 'Webservice::OVH::Me::Bill'->_new('wrapper', $api, 'id', $bill_id, 'module', $self->{'_module'})
Truth table0%0/3
A || B
A= $self->{'_bills'}{$bill_id}B= 'Webservice::OVH::Me::Bill'->_new('wrapper', $api, 'id', $bill_id, 'module', $self->{'_module'})
ABresult
1X1
011
000
292  
293 0 return $bill;
294 }
295  
296 =head2 bills
297  
298 Produces an array of all available bills.
299 Bills can be optionally filtered by date.
300  
301 =over
302  
303 =item * Parameter: $date_from - optional filter DateTime, $date_to - optional filter DateTime
304  
305 =item * Return: ARRAY
306  
307 =item * Synopsis: my $bills = $ovh->me->bills(DateTime->new(), DateTime->new());
308  
309 =back
310  
311 =cut
312  
313 0 ▶sub bills {
Subroutine bills: not called CC=6 SCAR=37.4
Pod documented
314  
315 0 my ( $self, $date_from, $date_to ) = @_;
316  
317 0 ▶ my $str_date_from = $date_from ? $date_from->strftime("%Y-%m-%d") : "";
Branch: 1 branch
BranchTrueFalseTotal
$date_from ? : 0 0 0
318 0 ▶ my $str_date_to = $date_to ? $date_to->strftime("%Y-%m-%d") : "";
Branch: 1 branch
BranchTrueFalseTotal
$date_to ? : 0 0 0
319 0 my $filter = Webservice::OVH::Helper->construct_filter( "date.from" => $str_date_from, "date.to" => $str_date_to );
320  
321 0 my $api = $self->{_api_wrapper};
322 0 my $response = $api->rawCall( method => 'get', path => sprintf( "/me/bill%s", $filter ), noSignature => 0 );
323 0 ▶ croak $response->error if $response->error;
Branch: 1 branch
BranchTrueFalseTotal
if $response->error 0 0 0
324  
325 0 my $bill_ids = $response->content;
326 0 my $bills = [];
327  
328 0 foreach my $bill_id (@$bill_ids) {
329  
330 0 ▶ my $bill = $self->{_bills}{$bill_id} = $self->{_bills}{$bill_id} || Webservice::OVH::Me::Bill->_new( wrapper => $api, id => $bill_id, module => $self->{_module} );
Condition0%0/3
$self->{'_bills'}{$bill_id} || 'Webservice::OVH::Me::Bill'->_new('wrapper', $api, 'id', $bill_id, 'module', $self->{'_module'})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'_bills'}{$bill_id} || 'Webservice::OVH::Me::Bill'->_new('wrapper', $api, 'id', $bill_id, 'module', $self->{'_module'})
$self->{'_bills'}{$bill_id} 'Webservice::OVH::Me::Bill'->_new('wrapper', $api, 'id', $bill_id, 'module', $self->{'_module'})
Truth table0%0/3
A || B
A= $self->{'_bills'}{$bill_id}B= 'Webservice::OVH::Me::Bill'->_new('wrapper', $api, 'id', $bill_id, 'module', $self->{'_module'})
ABresult
1X1
011
000
331 0 push @$bills, $bill;
332 }
333  
334 0 return $bills;
335 }
336  
337 36 1;
« Webservice/OVH/Order/Email/Domain.pm ↑ Summary Webservice/OVH/Cloud/Project/IP.pm »