File Coverage

lib/Webservice/OVH/Email/Domain/Domain/Task.pm
Criterion Covered Total %
statement 18 119 15.1
branch 0 42 0.0
condition 0 33 0.0
subroutine 6 17 35.2
pod 0 10 0.0
total 24 221 10.8


line stmt bran cond sub pod time code
1             package Webservice::OVH::Email::Domain::Domain::Task;
2              
3 36     36   258 use strict;
  36         101  
  36         1016  
4 36     36   184 use warnings;
  36         78  
  36         1026  
5 36     36   271 use Carp qw{ carp croak };
  36         117  
  36         2755  
6              
7             our $VERSION = 0.48;
8              
9 36     36   16520 use Webservice::OVH::Email::Domain::Domain::Task::Account;
  36         121  
  36         1213  
10 36     36   15651 use Webservice::OVH::Email::Domain::Domain::Task::Mailinglist;
  36         102  
  36         1202  
11 36     36   15972 use Webservice::OVH::Email::Domain::Domain::Task::Redirection;
  36         112  
  36         55584  
12              
13             sub _new {
14              
15 0     0     my ( $class, %params ) = @_;
16              
17 0 0         die "Missing module" unless $params{module};
18 0 0         die "Missing wrapper" unless $params{wrapper};
19 0 0         die "Missing domain" unless $params{domain};
20              
21 0           my $module = $params{module};
22 0           my $api_wrapper = $params{wrapper};
23 0           my $domain = $params{domain};
24              
25 0           my $self = bless {
26             _module => $module,
27             _wrapper => $api_wrapper,
28             _tasks_account => {},
29             _tasks_mailinglist => {},
30             _tasks_redirection => {},
31             _domain => $domain,
32             }, $class;
33              
34 0           return $self;
35             }
36              
37             sub domain {
38              
39 0     0 0   my ($self) = @_;
40              
41 0           return $self->{_domain};
42             }
43              
44             sub mailinglist_tasks {
45              
46 0     0 0   my ($self) = @_;
47 0           my $api = $self->{_wrapper};
48 0           my $domain_name = $self->domain->name;
49              
50 0           my $response = $api->rawCall( method => 'get', path => "/email/domain/$domain_name/task/mailinglist", noSignature => 0 );
51 0 0         croak $response->error if $response->error;
52              
53 0           my $ids = $response->content;
54 0           my $objects = [];
55              
56 0           foreach my $id (@$ids) {
57              
58 0   0       my $object = $self->{_tasks_mailinglist}{$id} = $self->{_tasks_mailinglist}{$id} || Webservice::OVH::Email::Domain::Domain::Task::Mailinglist->_new_existing( wrapper => $api, domain => $self->domain, id => $id, module => $self->{_module} );
59 0           push @$objects, $object;
60             }
61              
62 0           return $objects;
63             }
64              
65             sub mailinglist_task_by_id {
66              
67 0     0 0   my ( $self, $id ) = @_;
68              
69 0 0         croak "Missing id" unless $id;
70              
71 0           my $api = $self->{_wrapper};
72 0 0 0       my $from_object_array = $self->{_tasks_mailinglist}{$id} if $self->{_tasks_mailinglist}{$id} && $self->{_tasks_mailinglist}{$id}->is_valid;
73 0   0       my $account = $self->{_tasks_mailinglist}{$id} = $from_object_array || Webservice::OVH::Email::Domain::Domain::Task::Mailinglist->_new_existing( wrapper => $api, domain => $self->domain, id => $id, module => $self->{_module} );
74              
75 0           return $account;
76             }
77              
78             sub mailinglist_tasks_by_name {
79              
80 0     0 0   my ( $self, $mailinglist_name ) = @_;
81              
82 0 0         croak "Missing mailinglist_name" unless $mailinglist_name;
83              
84 0           my $domain_name = $self->domain->name;
85 0           my $api = $self->{_wrapper};
86              
87 0           my $response = $api->rawCall( method => 'get', path => sprintf( "/email/domain/$domain_name/task/mailinglist?account=%s", $mailinglist_name ), noSignature => 0 );
88 0 0         croak $response->error if $response->error;
89              
90 0           my $ids = $response->content;
91 0           my $objects = [];
92              
93 0           foreach my $id (@$ids) {
94              
95 0   0       my $object = $self->{_tasks_mailinglist}{$id} = $self->{_tasks_mailinglist}{$id} || Webservice::OVH::Email::Domain::Domain::Task::Mailinglist->_new_existing( wrapper => $api, domain => $self->domain, id => $id, module => $self->{_module} );
96 0           push @$objects, $object;
97             }
98              
99 0 0         return unless scalar @$objects;
100              
101 0           return $objects;
102             }
103              
104             sub account_tasks {
105              
106 0     0 0   my ($self) = @_;
107              
108 0           my $api = $self->{_wrapper};
109 0           my $domain_name = $self->domain->name;
110              
111 0           my $response = $api->rawCall( method => 'get', path => "/email/domain/$domain_name/task/account", noSignature => 0 );
112 0 0         croak $response->error if $response->error;
113              
114 0           my $ids = $response->content;
115 0           my $objects = [];
116              
117 0           foreach my $id (@$ids) {
118              
119 0   0       my $object = $self->{_tasks_account}{$id} = $self->{_tasks_account}{$id} || Webservice::OVH::Email::Domain::Domain::Task::Account->_new_existing( wrapper => $api, domain => $self->domain, id => $id, module => $self->{_module} );
120 0           push @$objects, $object;
121             }
122              
123 0           return $objects;
124             }
125              
126             sub account_task_by_id {
127              
128 0     0 0   my ( $self, $id ) = @_;
129              
130 0 0         croak "Missing id" unless $id;
131              
132 0           my $api = $self->{_wrapper};
133 0 0         my $from_object_array = $self->{_tasks_account}{$id} if $self->{_tasks_account}{$id};
134 0   0       my $account = $self->{_tasks_account}{$id} = $from_object_array || Webservice::OVH::Email::Domain::Domain::Task::Account->_new_existing( wrapper => $api, domain => $self->domain, id => $id, module => $self->{_module} );
135              
136 0           return $account;
137             }
138              
139             sub account_tasks_by_name {
140              
141 0     0 0   my ( $self, $account_name ) = @_;
142              
143 0 0         croak "Missing mailinglist_name" unless $account_name;
144              
145 0           my $domain_name = $self->domain->name;
146 0           my $api = $self->{_wrapper};
147              
148 0           my $response = $api->rawCall( method => 'get', path => sprintf( "/email/domain/$domain_name/task/account?name=%s", $account_name ), noSignature => 0 );
149 0 0         croak $response->error if $response->error;
150              
151 0           my $ids = $response->content;
152 0           my $objects = [];
153              
154 0           foreach my $id (@$ids) {
155              
156 0   0       my $object = $self->{_tasks_account}{$id} = $self->{_tasks_account}{$id} || Webservice::OVH::Email::Domain::Domain::Task::Account->_new_existing( wrapper => $api, domain => $self->domain, id => $id, module => $self->{_module} );
157 0           push @$objects, $object;
158             }
159              
160 0 0         return unless scalar @$objects;
161              
162 0           return $objects;
163             }
164              
165             sub redirection_tasks {
166              
167 0     0 0   my ($self) = @_;
168              
169 0           my $api = $self->{_wrapper};
170 0           my $domain_name = $self->domain->name;
171              
172 0           my $response = $api->rawCall( method => 'get', path => "/email/domain/$domain_name/task/redirection", noSignature => 0 );
173 0 0         croak $response->error if $response->error;
174              
175 0           my $ids = $response->content;
176 0           my $objects = [];
177              
178 0           foreach my $id (@$ids) {
179              
180 0   0       my $object = $self->{_tasks_redirection}{$id} = $self->{_tasks_redirection}{$id} || Webservice::OVH::Email::Domain::Domain::Task::Redirection->_new_existing( wrapper => $api, domain => $self->domain, id => $id, module => $self->{_module} );
181 0           push @$objects, $object;
182             }
183              
184 0           return $objects;
185             }
186              
187             sub redirection_task_by_id {
188              
189 0     0 0   my ( $self, $id ) = @_;
190              
191 0 0         croak "Missing id" unless $id;
192              
193 0           my $api = $self->{_wrapper};
194 0 0 0       my $from_object_array = $self->{_tasks_redirection}{$id} if $self->{_tasks_redirection}{$id} && $self->{_tasks_redirection}{$id}->is_valid;
195 0   0       my $account = $self->{_tasks_redirection}{$id} = $from_object_array || Webservice::OVH::Email::Domain::Domain::Task::Redirection->_new_existing( wrapper => $api, domain => $self->domain, id => $id, module => $self->{_module} );
196              
197 0           return $account;
198             }
199              
200             sub redirection_tasks_by_name {
201              
202 0     0 0   my ( $self, $redirection_id ) = @_;
203              
204 0 0         croak "Missing mailinglist_name" unless $redirection_id;
205              
206 0           my $domain_name = $self->domain->name;
207 0           my $api = $self->{_wrapper};
208              
209 0           my $response = $api->rawCall( method => 'get', path => sprintf( "/email/domain/$domain_name/task/redirection?account=%s", $redirection_id ), noSignature => 0 );
210 0 0         croak $response->error if $response->error;
211              
212 0           my $ids = $response->content;
213 0           my $objects = [];
214              
215 0           foreach my $id (@$ids) {
216              
217 0   0       my $object = $self->{_tasks_redirection}{$id} = $self->{_tasks_redirection}{$id} || Webservice::OVH::Email::Domain::Domain::Task::Redirection->_new_existing( wrapper => $api, domain => $self->domain, id => $id, module => $self->{_module} );
218 0           push @$objects, $object;
219             }
220              
221 0 0         return unless scalar @$objects;
222              
223 0           return $objects;
224             }
225              
226             1;