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