« blib/lib/Webservice/OVH/Domain/Service.pm
↑ Summary
blib/lib/Webservice/OVH/Cloud/Project/Network/Private.pm »
| 1 | package Webservice::OVH::Email::Domain::Domain; | ||
| 2 | |||
| 3 | =encoding utf-8 | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | Webservice::OVH::Email::Domain::Domain | ||
| 8 | |||
| 9 | =head1 SYNOPSIS | ||
| 10 | |||
| 11 | use Webservice::OVH; | ||
| 12 | |||
| 13 | my $ovh = Webservice::OVH->new_from_json("credentials.json"); | ||
| 14 | |||
| 15 | my $email_domain = $ovh->email->domain->domain('testdomain.de'); | ||
| 16 | |||
| 17 | =head1 DESCRIPTION | ||
| 18 | |||
| 19 | Provides access to api email-domain methods like mailinglists, accounts and redirections. | ||
| 20 | |||
| 21 | =head1 METHODS | ||
| 22 | |||
| 23 | =cut | ||
| 24 | |||
| 25 | use strict; | ||
| 26 | use warnings; | ||
| 27 | use Carp qw{ carp croak }; | ||
| 28 | |||
| 29 | our $VERSION = 0.47; | ||
| 30 | |||
| 31 | use Webservice::OVH::Email::Domain::Domain::Redirection; | ||
| 32 | use Webservice::OVH::Email::Domain::Domain::Account; | ||
| 33 | use Webservice::OVH::Email::Domain::Domain::MailingList; | ||
| 34 | use Webservice::OVH::Email::Domain::Domain::Task; | ||
| 35 | use Webservice::OVH::Helper; | ||
| 36 | |||
| 37 | =head2 _new | ||
| 38 | |||
| 39 | Internal Method to create the domain object. | ||
| 40 | This method is not ment to be called external. | ||
| 41 | |||
| 42 | =over | ||
| 43 | |||
| 44 | =item * Parameter: $api_wrapper - ovh api wrapper object, $module - root object | ||
| 45 | |||
| 46 | =item * Return: L<Webservice::OVH::Email::Domain> | ||
| 47 | |||
| 48 | =item * Synopsis: Webservice::OVH::Email::Domain->_new($ovh_api_wrapper, $zone_name, $module); | ||
| 49 | |||
| 50 | =back | ||
| 51 | |||
| 52 | =cut | ||
| 53 | |||
| 54 | sub _new { | ||
| 55 | |||
| 56 | my ( $class, %params ) = @_; | ||
| 57 | |||
| 58 | die "Missing module" unless $params{module}; | ||
| 59 | die "Missing wrapper" unless $params{wrapper}; | ||
| 60 | die "Missing id" unless $params{id}; | ||
| 61 | |||
| 62 | my $module = $params{module}; | ||
| 63 | my $api_wrapper = $params{wrapper}; | ||
| 64 | my $domain = $params{id}; | ||
| 65 | |||
| 66 | croak "Missing domain name" unless $domain; | ||
| 67 | |||
| 68 | my $self = bless { | ||
| 69 | _module => $module, | ||
| 70 | _api_wrapper => $api_wrapper, | ||
| 71 | _name => $domain, | ||
| 72 | _service_infos => undef, | ||
| 73 | _properties => undef, | ||
| 74 | _redirections => {}, | ||
| 75 | _accounts => {}, | ||
| 76 | _mailing_lists => {}, | ||
| 77 | }, $class; | ||
| 78 | |||
| 79 | my $task = Webservice::OVH::Email::Domain::Domain::Task->_new( module => $module, wrapper => $api_wrapper, domain => $self ); | ||
| 80 | $self->{_task} = $task; | ||
| 81 | |||
| 82 | return $self; | ||
| 83 | } | ||
| 84 | |||
| 85 | =head2 service_infos | ||
| 86 | |||
| 87 | Retrieves additional infos about the email-domain. | ||
| 88 | Not part of the properties | ||
| 89 | |||
| 90 | =over | ||
| 91 | |||
| 92 | =item * Return: HASH | ||
| 93 | |||
| 94 | =item * Synopsis: my $info = $email_domain->service_infos; | ||
| 95 | |||
| 96 | =back | ||
| 97 | |||
| 98 | =cut | ||
| 99 | |||
| 100 | sub service_infos { | ||
| 101 | |||
| 102 | my ($self) = @_; | ||
| 103 | |||
| 104 | my $api = $self->{_api_wrapper}; | ||
| 105 | my $domain = $self->name; | ||
| 106 | my $response_service_info = $api->rawCall( method => 'get', path => "/email/domain/$domain/serviceInfos", noSignature => 0 ); | ||
| 107 | |||
| 108 | croak $response_service_info->error if $response_service_info->error; | ||
| 109 | |||
| 110 | $self->{_service_infos} = $response_service_info->content; | ||
| 111 | |||
| 112 | return $self->{_service_infos}; | ||
| 113 | } | ||
| 114 | |||
| 115 | =head2 quota | ||
| 116 | |||
| 117 | Retrieves info about quotas. | ||
| 118 | Not part of the properties | ||
| 119 | |||
| 120 | =over | ||
| 121 | |||
| 122 | =item * Return: HASH | ||
| 123 | |||
| 124 | =item * Synopsis: my $info = $email_domain->quota; | ||
| 125 | |||
| 126 | =back | ||
| 127 | |||
| 128 | =cut | ||
| 129 | |||
| 130 | sub quota { | ||
| 131 | |||
| 132 | my ($self) = @_; | ||
| 133 | |||
| 134 | my $api = $self->{_api_wrapper}; | ||
| 135 | my $domain = $self->name; | ||
| 136 | my $response = $api->rawCall( method => 'get', path => "/email/domain/$domain/quota", noSignature => 0 ); | ||
| 137 | |||
| 138 | croak $response->error if $response->error; | ||
| 139 | return $response->content; | ||
| 140 | } | ||
| 141 | |||
| 142 | =head2 name | ||
| 143 | |||
| 144 | Name is the unique identifier. | ||
| 145 | |||
| 146 | =over | ||
| 147 | |||
| 148 | =item * Return: VALUE | ||
| 149 | |||
| 150 | =item * Synopsis: my $name = $email_domain->name; | ||
| 151 | |||
| 152 | =back | ||
| 153 | |||
| 154 | =cut | ||
| 155 | |||
| 156 | sub name { | ||
| 157 | |||
| 158 | my ($self) = @_; | ||
| 159 | |||
| 160 | return $self->{_name}; | ||
| 161 | } | ||
| 162 | |||
| 163 | =head2 properties | ||
| 164 | |||
| 165 | Retrieves properties of the email-domain. | ||
| 166 | This method updates the intern property variable. | ||
| 167 | |||
| 168 | =over | ||
| 169 | |||
| 170 | =item * Return: HASH | ||
| 171 | |||
| 172 | =item * Synopsis: my $properties = $email_domain->properties; | ||
| 173 | |||
| 174 | =back | ||
| 175 | |||
| 176 | =cut | ||
| 177 | |||
| 178 | sub properties { | ||
| 179 | |||
| 180 | my ($self) = @_; | ||
| 181 | |||
| 182 | my $api = $self->{_api_wrapper}; | ||
| 183 | my $domain = $self->name; | ||
| 184 | my $response_properties = $api->rawCall( method => 'get', path => "/email/domain/$domain", noSignature => 0 ); | ||
| 185 | croak $response_properties->error if $response_properties->error; | ||
| 186 | |||
| 187 | $self->{_properties} = $response_properties->content; | ||
| 188 | |||
| 189 | return $self->{_properties}; | ||
| 190 | } | ||
| 191 | |||
| 192 | =head2 allowed_account_size | ||
| 193 | |||
| 194 | Exposed Property Value. Readonly. | ||
| 195 | |||
| 196 | =over | ||
| 197 | |||
| 198 | =item * Return: VALUE | ||
| 199 | |||
| 200 | =item * Synopsis: my $allowed_account_size = $email_domain->allowed_account_size; | ||
| 201 | |||
| 202 | =back | ||
| 203 | |||
| 204 | =cut | ||
| 205 | |||
| 206 | sub allowed_account_size { | ||
| 207 | |||
| 208 | my ($self) = @_; | ||
| 209 | |||
| 210 | return $self->{_properties}->{allowedAccountSize}; | ||
| 211 | } | ||
| 212 | |||
| 213 | =head2 creation_date | ||
| 214 | |||
| 215 | Exposed Property Value. Readonly. | ||
| 216 | |||
| 217 | =over | ||
| 218 | |||
| 219 | =item * Return: DateTime | ||
| 220 | |||
| 221 | =item * Synopsis: my $creation_date = $email_domain->creation_date; | ||
| 222 | |||
| 223 | =back | ||
| 224 | |||
| 225 | =cut | ||
| 226 | |||
| 227 | sub creation_date { | ||
| 228 | |||
| 229 | my ($self) = @_; | ||
| 230 | |||
| 231 | my $str_datetime = $self->{_properties}->{creationDate}; | ||
| 232 | my $datetime = Webservice::OVH::Helper->parse_datetime($str_datetime); | ||
| 233 | return $datetime; | ||
| 234 | } | ||
| 235 | |||
| 236 | =head2 filerz | ||
| 237 | |||
| 238 | Exposed Property Value. Readonly. | ||
| 239 | |||
| 240 | =over | ||
| 241 | |||
| 242 | =item * Return: VALUE | ||
| 243 | |||
| 244 | =item * Synopsis: my $filerz = $email_domain->filerz; | ||
| 245 | |||
| 246 | =back | ||
| 247 | |||
| 248 | =cut | ||
| 249 | |||
| 250 | sub filerz { | ||
| 251 | |||
| 252 | my ($self) = @_; | ||
| 253 | |||
| 254 | return $self->{_properties}->{filerz}; | ||
| 255 | } | ||
| 256 | |||
| 257 | =head2 status | ||
| 258 | |||
| 259 | Exposed Property Value. Readonly. | ||
| 260 | |||
| 261 | =over | ||
| 262 | |||
| 263 | =item * Return: VALUE | ||
| 264 | |||
| 265 | =item * Synopsis: my $status = $email_domain->status; | ||
| 266 | |||
| 267 | =back | ||
| 268 | |||
| 269 | =cut | ||
| 270 | |||
| 271 | sub status { | ||
| 272 | |||
| 273 | my ($self) = @_; | ||
| 274 | |||
| 275 | return $self->{_properties}->{status}; | ||
| 276 | } | ||
| 277 | |||
| 278 | sub redirections_count { | ||
| 279 | |||
| 280 | my ($self) = @_; | ||
| 281 | |||
| 282 | my $api = $self->{_api_wrapper}; | ||
| 283 | my $domain_name = $self->name; | ||
| 284 | my $response = $api->rawCall( method => 'get', path => "/email/domain/$domain_name/redirection", noSignature => 0 ); | ||
| 285 | croak $response->error if $response->error; | ||
| 286 | |||
| 287 | return scalar @{ $response->content }; | ||
| 288 | } | ||
| 289 | |||
| 290 | =head2 redirections | ||
| 291 | |||
| 292 | Produces an array of all available redirections that are connected to the email-domain. | ||
| 293 | |||
| 294 | =over | ||
| 295 | |||
| 296 | =item * Return: L<ARRAY> | ||
| 297 | |||
| 298 | =item * Synopsis: my $redirections = $email_domain->redirections(); | ||
| 299 | |||
| 300 | =back | ||
| 301 | |||
| 302 | =cut | ||
| 303 | |||
| 304 | sub redirections { | ||
| 305 | |||
| 306 | my ( $self, %filter ) = @_; | ||
| 307 | |||
| 308 | my $filter_from = ( exists $filter{from} && !$filter{from} ) ? "_empty_" : $filter{from}; | ||
| 309 | my $filter_to = ( exists $filter{to} && !$filter{to} ) ? "_empty_" : $filter{to}; | ||
| 310 | my $filter = Webservice::OVH::Helper->construct_filter( "from" => $filter_from, "to" => $filter_to ); | ||
| 311 | |||
| 312 | my $api = $self->{_api_wrapper}; | ||
| 313 | my $domain_name = $self->name; | ||
| 314 | my $response = $api->rawCall( method => 'get', path => sprintf( "/email/domain/$domain_name/redirection%s", $filter ), noSignature => 0 ); | ||
| 315 | croak $response->error if $response->error; | ||
| 316 | |||
| 317 | my $redirection_ids = $response->content; | ||
| 318 | my $redirections = []; | ||
| 319 | |||
| 320 | foreach my $redirection_id (@$redirection_ids) { | ||
| 321 | |||
| 322 | my $redirection = $self->{_redirections}{$redirection_id} = $self->{_redirections}{$redirection_id} || Webservice::OVH::Email::Domain::Domain::Redirection->_new_existing( wrapper => $api, domain => $self, id => $redirection_id, module => $self->{_module} ); | ||
| 323 | push @$redirections, $redirection; | ||
| 324 | } | ||
| 325 | |||
| 326 | return $redirections; | ||
| 327 | } | ||
| 328 | |||
| 329 | sub redirection_exists { | ||
| 330 | |||
| 331 | my ( $self, $redirection_id ) = @_; | ||
| 332 | |||
| 333 | croak "Missing redirection_id" unless $redirection_id; | ||
| 334 | |||
| 335 | my $api = $self->{_api_wrapper}; | ||
| 336 | my $domain_name = $self->name; | ||
| 337 | |||
| 338 | my $response = $api->rawCall( method => 'get', path => "/email/domain/$domain_name/redirection/$redirection_id", noSignature => 0 ); | ||
| 339 | |||
| 340 | return $response->error ? 0 : 1; | ||
| 341 | } | ||
| 342 | |||
| 343 | =head2 redirection | ||
| 344 | |||
| 345 | Returns a single redirection by id | ||
| 346 | |||
| 347 | =over | ||
| 348 | |||
| 349 | =item * Parameter: $redirection_id - id | ||
| 350 | |||
| 351 | =item * Return: L<Webservice::OVH::Email::Domain::Domain::Redirection> | ||
| 352 | |||
| 353 | =item * Synopsis: my $service = $email_domain->redirection(12345); | ||
| 354 | |||
| 355 | =back | ||
| 356 | |||
| 357 | =cut | ||
| 358 | |||
| 359 | sub redirection { | ||
| 360 | |||
| 361 | my ( $self, $redirection_id ) = @_; | ||
| 362 | |||
| 363 | croak "Missing redirection_id" unless $redirection_id; | ||
| 364 | |||
| 365 | if ( $self->redirection_exists($redirection_id) ) { | ||
| 366 | |||
| 367 | my $api = $self->{_api_wrapper}; | ||
| 368 | my $from_array_redirection = $self->{_redirections}{$redirection_id} if $self->{_redirections}{$redirection_id} && $self->{_redirections}{$redirection_id}->is_valid; | ||
| 369 | my $redirection = $self->{_redirections}{$redirection_id} = $from_array_redirection || Webservice::OVH::Email::Domain::Domain::Redirection->_new_existing( wrapper => $api, domain => $self, id => $redirection_id, module => $self->{_module} ); | ||
| 370 | |||
| 371 | return $redirection; | ||
| 372 | |||
| 373 | } else { | ||
| 374 | |||
| 375 | return undef; | ||
| 376 | } | ||
| 377 | } | ||
| 378 | |||
| 379 | =head2 new_redirection | ||
| 380 | |||
| 381 | Creates a new redirection. | ||
| 382 | |||
| 383 | =over | ||
| 384 | |||
| 385 | =item * Parameter: %params - key => value from to local_copy | ||
| 386 | |||
| 387 | =item * Return: L<Webservice::Email::Domain::Domain::Redirection> | ||
| 388 | |||
| 389 | =item * Synopsis: my $redirection = $email_domain->new_redirection(from => 'test@test.de', to => 'test2@test.de', local_copy => 'false'); | ||
| 390 | |||
| 391 | =back | ||
| 392 | |||
| 393 | =cut | ||
| 394 | |||
| 395 | sub new_redirection { | ||
| 396 | |||
| 397 | my ( $self, %params ) = @_; | ||
| 398 | |||
| 399 | my $api = $self->{_api_wrapper}; | ||
| 400 | my $redirection = Webservice::OVH::Email::Domain::Domain::Redirection->_new( wrapper => $api, domain => $self, module => $self->{_module}, %params ); | ||
| 401 | |||
| 402 | return $redirection; | ||
| 403 | } | ||
| 404 | |||
| 405 | sub accounts_count { | ||
| 406 | |||
| 407 | my ($self) = @_; | ||
| 408 | |||
| 409 | my $api = $self->{_api_wrapper}; | ||
| 410 | my $domain_name = $self->name; | ||
| 411 | my $response = $api->rawCall( method => 'get', path => "/email/domain/$domain_name/account", noSignature => 0 ); | ||
| 412 | croak $response->error if $response->error; | ||
| 413 | |||
| 414 | return scalar @{ $response->content }; | ||
| 415 | } | ||
| 416 | |||
| 417 | =head2 accounts | ||
| 418 | |||
| 419 | Produces an array of all available accounts that are connected to the email-domain. | ||
| 420 | |||
| 421 | =over | ||
| 422 | |||
| 423 | =item * Return: L<ARRAY> | ||
| 424 | |||
| 425 | =item * Synopsis: my $accounts = $email_domain->accounts(); | ||
| 426 | |||
| 427 | =back | ||
| 428 | |||
| 429 | =cut | ||
| 430 | |||
| 431 | sub accounts { | ||
| 432 | |||
| 433 | my ($self) = @_; | ||
| 434 | |||
| 435 | my $api = $self->{_api_wrapper}; | ||
| 436 | my $domain_name = $self->name; | ||
| 437 | my $response = $api->rawCall( method => 'get', path => "/email/domain/$domain_name/account", noSignature => 0 ); | ||
| 438 | croak $response->error if $response->error; | ||
| 439 | |||
| 440 | my $account_names = $response->content; | ||
| 441 | my $accounts = []; | ||
| 442 | |||
| 443 | foreach my $account_name (@$account_names) { | ||
| 444 | my $account = $self->{_accounts}{$account_name} = $self->{_accounts}{$account_name} || Webservice::OVH::Email::Domain::Domain::Account->_new_existing( wrapper => $api, domain => $self, id => $account_name, module => $self->{_module} ); | ||
| 445 | push @$accounts, $account; | ||
| 446 | } | ||
| 447 | |||
| 448 | return $accounts; | ||
| 449 | } | ||
| 450 | |||
| 451 | sub account_exists { | ||
| 452 | |||
| 453 | my ( $self, $account_name ) = @_; | ||
| 454 | |||
| 455 | croak "Missing account_name" unless $account_name; | ||
| 456 | |||
| 457 | my $api = $self->{_api_wrapper}; | ||
| 458 | my $domain_name = $self->name; | ||
| 459 | |||
| 460 | my $response = $api->rawCall( method => 'get', path => "/email/domain/$domain_name/account/$account_name", noSignature => 0 ); | ||
| 461 | |||
| 462 | return $response->error ? 0 : 1; | ||
| 463 | } | ||
| 464 | |||
| 465 | =head2 account | ||
| 466 | |||
| 467 | Returns a single account by name | ||
| 468 | |||
| 469 | =over | ||
| 470 | |||
| 471 | =item * Parameter: $account_name - name | ||
| 472 | |||
| 473 | =item * Return: L<Webservice::OVH::Email::Domain::Domain::Account> | ||
| 474 | |||
| 475 | =item * Synopsis: my $account = $email_domain->account('testaccount'); | ||
| 476 | |||
| 477 | =back | ||
| 478 | |||
| 479 | =cut | ||
| 480 | |||
| 481 | sub account { | ||
| 482 | |||
| 483 | my ( $self, $account_name ) = @_; | ||
| 484 | |||
| 485 | croak "Missing account_name" unless $account_name; | ||
| 486 | |||
| 487 | $account_name = lc $account_name; | ||
| 488 | |||
| 489 | if ( $self->account_exists($account_name) ) { | ||
| 490 | |||
| 491 | my $api = $self->{_api_wrapper}; | ||
| 492 | my $from_array_account = $self->{_accounts}{$account_name} if $self->{_accounts}{$account_name} && $self->{_accounts}{$account_name}->is_valid; | ||
| 493 | my $account = $self->{_accounts}{$account_name} = $from_array_account || Webservice::OVH::Email::Domain::Domain::Account->_new_existing( wrapper => $api, domain => $self, id => $account_name, module => $self->{_module} ); | ||
| 494 | |||
| 495 | return $account; | ||
| 496 | |||
| 497 | } else { | ||
| 498 | |||
| 499 | return undef; | ||
| 500 | } | ||
| 501 | } | ||
| 502 | |||
| 503 | =head2 new_account | ||
| 504 | |||
| 505 | Creates a new account. | ||
| 506 | |||
| 507 | =over | ||
| 508 | |||
| 509 | =item * Parameter: %params - key => value account_name password description size | ||
| 510 | |||
| 511 | =item * Return: L<Webservice::Email::Domain::Domain::Account> | ||
| 512 | |||
| 513 | =item * Synopsis: my $account = $email_domain->new_account(account_name => 'testaccount', password => $password, description => 'a test account', size => 5000000 ); | ||
| 514 | |||
| 515 | =back | ||
| 516 | |||
| 517 | =cut | ||
| 518 | |||
| 519 | sub new_account { | ||
| 520 | |||
| 521 | my ( $self, %params ) = @_; | ||
| 522 | |||
| 523 | my $api = $self->{_api_wrapper}; | ||
| 524 | my ( $account, $task ) = Webservice::OVH::Email::Domain::Domain::Account->_new( wrapper => $api, domain => $self, module => $self->{_module}, %params ); | ||
| 525 | |||
| 526 | return ( $account, $task ); | ||
| 527 | } | ||
| 528 | |||
| 529 | sub mailing_lists_count { | ||
| 530 | |||
| 531 | my ($self) = @_; | ||
| 532 | |||
| 533 | my $api = $self->{_api_wrapper}; | ||
| 534 | my $domain_name = $self->name; | ||
| 535 | my $response = $api->rawCall( method => 'get', path => "/email/domain/$domain_name/mailingList", noSignature => 0 ); | ||
| 536 | croak $response->error if $response->error; | ||
| 537 | |||
| 538 | return scalar @{ $response->content }; | ||
| 539 | } | ||
| 540 | |||
| 541 | sub mailing_lists_names { | ||
| 542 | |||
| 543 | my ($self) = @_; | ||
| 544 | |||
| 545 | my $api = $self->{_api_wrapper}; | ||
| 546 | my $domain_name = $self->name; | ||
| 547 | my $response = $api->rawCall( method => 'get', path => "/email/domain/$domain_name/mailingList", noSignature => 0 ); | ||
| 548 | croak $response->error if $response->error; | ||
| 549 | |||
| 550 | return $response->content; | ||
| 551 | } | ||
| 552 | |||
| 553 | =head2 mailing_lists | ||
| 554 | |||
| 555 | Produces an array of all available mailing_lists that are connected to the email-domain. | ||
| 556 | |||
| 557 | =over | ||
| 558 | |||
| 559 | =item * Return: L<ARRAY> | ||
| 560 | |||
| 561 | =item * Synopsis: my $mailing_lists = $email_domain->mailing_lists(); | ||
| 562 | |||
| 563 | =back | ||
| 564 | |||
| 565 | =cut | ||
| 566 | |||
| 567 | sub mailing_lists { | ||
| 568 | |||
| 569 | my ($self) = @_; | ||
| 570 | |||
| 571 | my $api = $self->{_api_wrapper}; | ||
| 572 | my $domain_name = $self->name; | ||
| 573 | my $response = $api->rawCall( method => 'get', path => "/email/domain/$domain_name/mailingList", noSignature => 0 ); | ||
| 574 | croak $response->error if $response->error; | ||
| 575 | |||
| 576 | my $mailing_list_names = $response->content; | ||
| 577 | my $mailing_lists = []; | ||
| 578 | |||
| 579 | foreach my $mailing_list_name (@$mailing_list_names) { | ||
| 580 | |||
| 581 | my $mailing_list = $self->{_mailing_lists}{$mailing_list_name} = $self->{_mailing_lists}{$mailing_list_name} || Webservice::OVH::Email::Domain::Domain::MailingList->_new_existing( wrapper => $api, domain => $self, id => $mailing_list_name, module => $self->{_module} ); | ||
| 582 | push @$mailing_lists, $mailing_list; | ||
| 583 | } | ||
| 584 | |||
| 585 | return $mailing_lists; | ||
| 586 | } | ||
| 587 | |||
| 588 | sub mailinglist_exists { | ||
| 589 | |||
| 590 | my ( $self, $mailinglist_name ) = @_; | ||
| 591 | |||
| 592 | croak "Missing mailinglist_name" unless $mailinglist_name; | ||
| 593 | |||
| 594 | my $api = $self->{_api_wrapper}; | ||
| 595 | my $domain_name = $self->name; | ||
| 596 | |||
| 597 | my $response = $api->rawCall( method => 'get', path => "/email/domain/$domain_name/mailingList/$mailinglist_name", noSignature => 0 ); | ||
| 598 | |||
| 599 | return $response->error ? 0 : 1; | ||
| 600 | } | ||
| 601 | |||
| 602 | =head2 mailing_list | ||
| 603 | |||
| 604 | Returns a single account by name | ||
| 605 | |||
| 606 | =over | ||
| 607 | |||
| 608 | =item * Parameter: $mailing_list_name - name | ||
| 609 | |||
| 610 | =item * Return: L<Webservice::OVH::Email::Domain::Domain::MailingList> | ||
| 611 | |||
| 612 | =item * Synopsis: my $mailing_list = $email_domain->mailing_list('subscriber_list'); | ||
| 613 | |||
| 614 | =back | ||
| 615 | |||
| 616 | =cut | ||
| 617 | |||
| 618 | sub mailing_list { | ||
| 619 | |||
| 620 | my ( $self, $mailing_list_name ) = @_; | ||
| 621 | |||
| 622 | croak "Missing mailing_list_name" unless $mailing_list_name; | ||
| 623 | |||
| 624 | if ( $self->mailinglist_exists($mailing_list_name) ) { | ||
| 625 | |||
| 626 | my $api = $self->{_api_wrapper}; | ||
| 627 | my $from_array_mailing_list = $self->{_mailing_lists}{$mailing_list_name} if $self->{_mailing_lists}{$mailing_list_name} && $self->{_mailing_lists}{$mailing_list_name}->is_valid; | ||
| 628 | my $mailing_list = $self->{_mailing_lists}{$mailing_list_name} = $from_array_mailing_list || Webservice::OVH::Email::Domain::Domain::MailingList->_new_existing( wrapper => $api, domain => $self, id => $mailing_list_name, module => $self->{_module} ); | ||
| 629 | |||
| 630 | return $mailing_list; | ||
| 631 | |||
| 632 | } else { | ||
| 633 | |||
| 634 | return undef; | ||
| 635 | } | ||
| 636 | } | ||
| 637 | |||
| 638 | =head2 new_mailing_list | ||
| 639 | |||
| 640 | Creates a new mailing list. | ||
| 641 | |||
| 642 | =over | ||
| 643 | |||
| 644 | =item * Parameter: %params - key => value language name options owner_email reply_to | ||
| 645 | |||
| 646 | =item * Return: L<Webservice::Email::Domain::Domain::MailingList> | ||
| 647 | |||
| 648 | =item * Synopsis: my $mailing_list = $email_domain->new_mailing_list(language 'DE', name => 'infos', options => {}, owner_email => 'owner@test.de', reply_to => 'test@test.de' ); | ||
| 649 | |||
| 650 | =back | ||
| 651 | |||
| 652 | =cut | ||
| 653 | |||
| 654 | sub new_mailing_list { | ||
| 655 | |||
| 656 | my ( $self, %params ) = @_; | ||
| 657 | |||
| 658 | my $api = $self->{_api_wrapper}; | ||
| 659 | my ( $mailing_list, $task ) = Webservice::OVH::Email::Domain::Domain::MailingList->_new( wrapper => $api, domain => $self, module => $self->{_module}, %params ); | ||
| 660 | |||
| 661 | return ( $mailing_list, $task ); | ||
| 662 | } | ||
| 663 | |||
| 664 | sub task { | ||
| 665 | |||
| 666 | my ($self) = @_; | ||
| 667 | |||
| 668 | return $self->{_task}; | ||
| 669 | } | ||
| 670 | |||
| 671 | 1; |