« lib/Webservice/OVH/Email/Domain/Domain/Task.pm
↑ Summary
blib/lib/Webservice/OVH/Email/Domain/Domain.pm »
| 1 | package Webservice::OVH::Domain::Service; | ||
| 2 | |||
| 3 | =encoding utf-8 | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | Webservice::OVH::Domain::Service | ||
| 8 | |||
| 9 | =head1 SYNOPSIS | ||
| 10 | |||
| 11 | use Webservice::OVH; | ||
| 12 | |||
| 13 | my $ovh = Webservice::OVH->new_from_json("credentials.json"); | ||
| 14 | |||
| 15 | my $service = $ovh->domain->service("mydomain.org"); | ||
| 16 | |||
| 17 | my $info = $service->service_info; | ||
| 18 | my $last_update = $service->last_update; | ||
| 19 | |||
| 20 | =head1 DESCRIPTION | ||
| 21 | |||
| 22 | Provieds basic functionality for Services | ||
| 23 | A service contact_change can be initialized. | ||
| 24 | |||
| 25 | =head1 METHODS | ||
| 26 | |||
| 27 | =cut | ||
| 28 | |||
| 29 | use strict; | ||
| 30 | use warnings; | ||
| 31 | use Carp qw{ carp croak }; | ||
| 32 | use DateTime; | ||
| 33 | use JSON; | ||
| 34 | |||
| 35 | our $VERSION = 0.47; | ||
| 36 | |||
| 37 | use Webservice::OVH::Helper; | ||
| 38 | use Webservice::OVH::Me::Contact; | ||
| 39 | |||
| 40 | =head2 _new | ||
| 41 | |||
| 42 | Internal Method to create the service object. | ||
| 43 | This method is not ment to be called external. | ||
| 44 | |||
| 45 | =over | ||
| 46 | |||
| 47 | =item * Parameter: $api_wrapper - ovh api wrapper object, $module - root object | ||
| 48 | |||
| 49 | =item * Return: L<Webservice::OVH::Domain::Zone> | ||
| 50 | |||
| 51 | =item * Synopsis: Webservice::OVH::Domain::Zone->_new($ovh_api_wrapper, $zone_name, $module); | ||
| 52 | |||
| 53 | =back | ||
| 54 | |||
| 55 | =cut | ||
| 56 | |||
| 57 | sub _new { | ||
| 58 | |||
| 59 | my ( $class, %params ) = @_; | ||
| 60 | |||
| 61 | die "Missing module" unless $params{module}; | ||
| 62 | die "Missing wrapper" unless $params{wrapper}; | ||
| 63 | die "Missing id" unless $params{id}; | ||
| 64 | |||
| 65 | my $module = $params{module}; | ||
| 66 | my $api_wrapper = $params{wrapper}; | ||
| 67 | my $service_name = $params{id}; | ||
| 68 | |||
| 69 | my $self = bless { _module => $module, _api_wrapper => $api_wrapper, _name => $service_name, _owner => undef, _service_info => undef, _properties => undef }, $class; | ||
| 70 | |||
| 71 | return $self; | ||
| 72 | } | ||
| 73 | |||
| 74 | =head2 name | ||
| 75 | |||
| 76 | Name is the unique identifier. | ||
| 77 | |||
| 78 | =over | ||
| 79 | |||
| 80 | =item * Return: VALUE | ||
| 81 | |||
| 82 | =item * Synopsis: my $name = $service->name; | ||
| 83 | |||
| 84 | =back | ||
| 85 | |||
| 86 | =cut | ||
| 87 | |||
| 88 | sub name { | ||
| 89 | |||
| 90 | my ($self) = @_; | ||
| 91 | |||
| 92 | return $self->{_name}; | ||
| 93 | } | ||
| 94 | |||
| 95 | =head2 service_infos | ||
| 96 | |||
| 97 | Retrieves additional infos about the service. | ||
| 98 | Infos that are not part of the properties | ||
| 99 | |||
| 100 | =over | ||
| 101 | |||
| 102 | =item * Return: HASH | ||
| 103 | |||
| 104 | =item * Synopsis: my $info = $service->service_info; | ||
| 105 | |||
| 106 | =back | ||
| 107 | |||
| 108 | =cut | ||
| 109 | |||
| 110 | sub service_infos { | ||
| 111 | |||
| 112 | my ($self) = @_; | ||
| 113 | |||
| 114 | my $api = $self->{_api_wrapper}; | ||
| 115 | my $service_name = $self->name; | ||
| 116 | my $response_service_info = $api->rawCall( method => 'get', path => "/domain/$service_name/serviceInfos", noSignature => 0 ); | ||
| 117 | |||
| 118 | croak $response_service_info->error if $response_service_info->error; | ||
| 119 | |||
| 120 | $self->{_service_info} = $response_service_info->content; | ||
| 121 | |||
| 122 | return $self->{_service_info}; | ||
| 123 | } | ||
| 124 | |||
| 125 | =head2 properties | ||
| 126 | |||
| 127 | Retrieves properties of the service. | ||
| 128 | This method updates the intern property variable. | ||
| 129 | |||
| 130 | =over | ||
| 131 | |||
| 132 | =item * Return: HASH | ||
| 133 | |||
| 134 | =item * Synopsis: my $properties = $service->properties; | ||
| 135 | |||
| 136 | =back | ||
| 137 | |||
| 138 | =cut | ||
| 139 | |||
| 140 | sub properties { | ||
| 141 | |||
| 142 | my ($self) = @_; | ||
| 143 | |||
| 144 | my $api = $self->{_api_wrapper}; | ||
| 145 | my $service_name = $self->name; | ||
| 146 | my $response_properties = $api->rawCall( method => 'get', path => "/domain/$service_name", noSignature => 0 ); | ||
| 147 | |||
| 148 | croak $response_properties->error if $response_properties->error; | ||
| 149 | |||
| 150 | $self->{_properties} = $response_properties->content; | ||
| 151 | |||
| 152 | return $self->{_properties}; | ||
| 153 | } | ||
| 154 | |||
| 155 | =head2 dnssec_supported | ||
| 156 | |||
| 157 | Exposed Property Value. Readonly. | ||
| 158 | |||
| 159 | =over | ||
| 160 | |||
| 161 | =item * Return: VALUE | ||
| 162 | |||
| 163 | =item * Synopsis: my $dnssec_supported = $service->dnssec_supported; | ||
| 164 | |||
| 165 | =back | ||
| 166 | |||
| 167 | =cut | ||
| 168 | |||
| 169 | sub dnssec_supported { | ||
| 170 | |||
| 171 | my ($self) = @_; | ||
| 172 | |||
| 173 | $self->properties unless $self->{_properties}; | ||
| 174 | |||
| 175 | return $self->{_properties}->{dnssecSupported} ? 1 : 0; | ||
| 176 | } | ||
| 177 | |||
| 178 | =head2 domain | ||
| 179 | |||
| 180 | Exposed Property Value. Readonly. | ||
| 181 | |||
| 182 | =over | ||
| 183 | |||
| 184 | =item * Return: VALUE | ||
| 185 | |||
| 186 | =item * Synopsis: my $domain = $service->domain; | ||
| 187 | |||
| 188 | =back | ||
| 189 | |||
| 190 | =cut | ||
| 191 | |||
| 192 | sub domain { | ||
| 193 | |||
| 194 | my ($self) = @_; | ||
| 195 | |||
| 196 | $self->properties unless $self->{_properties}; | ||
| 197 | |||
| 198 | return $self->{_properties}->{domain}; | ||
| 199 | } | ||
| 200 | |||
| 201 | =head2 glue_record_ipv6_supported | ||
| 202 | |||
| 203 | Exposed Property Value. Readonly. | ||
| 204 | |||
| 205 | =over | ||
| 206 | |||
| 207 | =item * Return: VALUE | ||
| 208 | |||
| 209 | =item * Synopsis: my $glue_record_ipv6_supported = $service->glue_record_ipv6_supported; | ||
| 210 | |||
| 211 | =back | ||
| 212 | |||
| 213 | =cut | ||
| 214 | |||
| 215 | sub glue_record_ipv6_supported { | ||
| 216 | |||
| 217 | my ($self) = @_; | ||
| 218 | |||
| 219 | $self->properties unless $self->{_properties}; | ||
| 220 | |||
| 221 | return $self->{_properties}->{glueRecordIpv6Supported} ? 1 : 0; | ||
| 222 | } | ||
| 223 | |||
| 224 | =head2 glue_record_multi_ip_supported | ||
| 225 | |||
| 226 | Exposed Property Value. Readonly. | ||
| 227 | |||
| 228 | =over | ||
| 229 | |||
| 230 | =item * Return: VALUE | ||
| 231 | |||
| 232 | =item * Synopsis: my $glue_record_multi_ip_supported = $service->glue_record_multi_ip_supported; | ||
| 233 | |||
| 234 | =back | ||
| 235 | |||
| 236 | =cut | ||
| 237 | |||
| 238 | sub glue_record_multi_ip_supported { | ||
| 239 | |||
| 240 | my ($self) = @_; | ||
| 241 | |||
| 242 | $self->properties unless $self->{_properties}; | ||
| 243 | |||
| 244 | return $self->{_properties}->{glueRecordMultiIpSupported} ? 1 : 0; | ||
| 245 | } | ||
| 246 | |||
| 247 | =head2 last_update | ||
| 248 | |||
| 249 | Exposed Property Value. Readonly. | ||
| 250 | |||
| 251 | =over | ||
| 252 | |||
| 253 | =item * Return: DateTime | ||
| 254 | |||
| 255 | =item * Synopsis: my $last_update = $service->last_update; | ||
| 256 | |||
| 257 | =back | ||
| 258 | |||
| 259 | =cut | ||
| 260 | |||
| 261 | sub last_update { | ||
| 262 | |||
| 263 | my ($self) = @_; | ||
| 264 | |||
| 265 | $self->properties unless $self->{_properties}; | ||
| 266 | |||
| 267 | my $str_datetime = $self->{_properties}->{lastUpdate}; | ||
| 268 | my $datetime = Webservice::OVH::Helper->parse_datetime($str_datetime); | ||
| 269 | return $datetime; | ||
| 270 | } | ||
| 271 | |||
| 272 | =head2 last_update | ||
| 273 | |||
| 274 | Exposed Property Value. Readonly. | ||
| 275 | |||
| 276 | =over | ||
| 277 | |||
| 278 | =item * Return: DateTime | ||
| 279 | |||
| 280 | =item * Synopsis: my $last_update = $service->last_update; | ||
| 281 | |||
| 282 | =back | ||
| 283 | |||
| 284 | =cut | ||
| 285 | |||
| 286 | sub expiration { | ||
| 287 | |||
| 288 | my ($self) = @_; | ||
| 289 | |||
| 290 | $self->service_infos unless $self->{_service_info}; | ||
| 291 | |||
| 292 | my $str_datetime = $self->{_service_info}->{expiration}; | ||
| 293 | my $datetime = Webservice::OVH::Helper->parse_date($str_datetime); | ||
| 294 | return $datetime; | ||
| 295 | } | ||
| 296 | |||
| 297 | =head2 name_server_type | ||
| 298 | |||
| 299 | Exposed Property Value. Readonly. | ||
| 300 | |||
| 301 | =over | ||
| 302 | |||
| 303 | =item * Return: VALUE | ||
| 304 | |||
| 305 | =item * Synopsis: my $name_server_type = $service->name_server_type; | ||
| 306 | |||
| 307 | =back | ||
| 308 | |||
| 309 | =cut | ||
| 310 | |||
| 311 | sub name_server_type { | ||
| 312 | |||
| 313 | my ($self) = @_; | ||
| 314 | |||
| 315 | $self->properties unless $self->{_properties}; | ||
| 316 | |||
| 317 | return $self->{_properties}->{nameServerType}; | ||
| 318 | } | ||
| 319 | |||
| 320 | =head2 offer | ||
| 321 | |||
| 322 | Exposed Property Value. Readonly. | ||
| 323 | |||
| 324 | =over | ||
| 325 | |||
| 326 | =item * Return: HASH | ||
| 327 | |||
| 328 | =item * Synopsis: my $offer = $service->offer; | ||
| 329 | |||
| 330 | =back | ||
| 331 | |||
| 332 | =cut | ||
| 333 | |||
| 334 | sub offer { | ||
| 335 | |||
| 336 | my ($self) = @_; | ||
| 337 | |||
| 338 | $self->properties unless $self->{_properties}; | ||
| 339 | |||
| 340 | return $self->{_properties}->{offer}; | ||
| 341 | } | ||
| 342 | |||
| 343 | =head2 owo_supported | ||
| 344 | |||
| 345 | Exposed Property Value. Readonly. | ||
| 346 | |||
| 347 | =over | ||
| 348 | |||
| 349 | =item * Return: VALUE | ||
| 350 | |||
| 351 | =item * Synopsis: my $owo_supported = $service->owo_supported; | ||
| 352 | |||
| 353 | =back | ||
| 354 | |||
| 355 | =cut | ||
| 356 | |||
| 357 | sub owo_supported { | ||
| 358 | |||
| 359 | my ($self) = @_; | ||
| 360 | |||
| 361 | $self->properties unless $self->{_properties}; | ||
| 362 | |||
| 363 | return $self->{_properties}->{owoSupported} ? 1 : 0; | ||
| 364 | } | ||
| 365 | |||
| 366 | =head2 parent_service | ||
| 367 | |||
| 368 | Exposed Property Value. Readonly. | ||
| 369 | |||
| 370 | =over | ||
| 371 | |||
| 372 | =item * Return: VALUE | ||
| 373 | |||
| 374 | =item * Synopsis: my $parent_service = $service->parent_service; | ||
| 375 | |||
| 376 | =back | ||
| 377 | |||
| 378 | =cut | ||
| 379 | |||
| 380 | sub parent_service { | ||
| 381 | |||
| 382 | my ($self) = @_; | ||
| 383 | |||
| 384 | $self->properties unless $self->{_properties}; | ||
| 385 | |||
| 386 | return $self->{_properties}->{parentService}; | ||
| 387 | } | ||
| 388 | |||
| 389 | =head2 transfer_lock_status | ||
| 390 | |||
| 391 | Exposed Property Value. Readonly. | ||
| 392 | |||
| 393 | =over | ||
| 394 | |||
| 395 | =item * Return: VALUE | ||
| 396 | |||
| 397 | =item * Synopsis: my $transfer_lock_status = $service->transfer_lock_status; | ||
| 398 | |||
| 399 | =back | ||
| 400 | |||
| 401 | =cut | ||
| 402 | |||
| 403 | sub transfer_lock_status { | ||
| 404 | |||
| 405 | my ($self) = @_; | ||
| 406 | |||
| 407 | $self->properties unless $self->{_properties}; | ||
| 408 | |||
| 409 | return $self->{_properties}->{transferLockStatus}; | ||
| 410 | } | ||
| 411 | |||
| 412 | =head2 whois_owner | ||
| 413 | |||
| 414 | Exposed Property Value. Readonly. | ||
| 415 | |||
| 416 | =over | ||
| 417 | |||
| 418 | =item * Return: L<Webservice::Me::Contact> | ||
| 419 | |||
| 420 | =item * Synopsis: my $owner = $service->whois_owner; | ||
| 421 | |||
| 422 | =back | ||
| 423 | |||
| 424 | =cut | ||
| 425 | |||
| 426 | sub whois_owner { | ||
| 427 | |||
| 428 | my ($self) = @_; | ||
| 429 | |||
| 430 | my $api = $self->{_api_wrapper}; | ||
| 431 | my $properties = $self->{_properties} || $self->properties; | ||
| 432 | my $owner_id = $properties->{whoisOwner}; | ||
| 433 | my $owner = $self->{_owner} = $self->{_owner} || Webservice::OVH::Me::Contact->_new_existing( wrapper => $api, id => $owner_id, module => $self->{_module} ); | ||
| 434 | |||
| 435 | return $self->{_owner}; | ||
| 436 | } | ||
| 437 | |||
| 438 | =head2 change_contact | ||
| 439 | |||
| 440 | Initializes a change_contact procedure. | ||
| 441 | This generates a task. An email is sent to the other account- | ||
| 442 | |||
| 443 | =over | ||
| 444 | |||
| 445 | =item * Parameter: %params - key => value contact_billing contact_admin contact_tech - ovh account names | ||
| 446 | |||
| 447 | =item * Return: L<Webservice::Me::Task> | ||
| 448 | |||
| 449 | =item * Synopsis: $service->change_contact(contact_tech => 'otheraccount-ovh'); | ||
| 450 | |||
| 451 | =back | ||
| 452 | |||
| 453 | =cut | ||
| 454 | |||
| 455 | sub change_contact { | ||
| 456 | |||
| 457 | my ( $self, %params ) = @_; | ||
| 458 | |||
| 459 | croak "at least one parameter needed: contact_billing contact_admin contact_tech" unless %params; | ||
| 460 | |||
| 461 | my $api = $self->{_api_wrapper}; | ||
| 462 | my $service_name = $self->name; | ||
| 463 | my $body = {}; | ||
| 464 | $body->{contactBilling} = $params{contact_billing} if exists $params{contact_billing}; | ||
| 465 | $body->{contactAdmin} = $params{contact_admin} if exists $params{contact_admin}; | ||
| 466 | $body->{contactTech} = $params{contact_tech} if exists $params{contact_tech}; | ||
| 467 | my $response = $api->rawCall( method => 'post', path => "/domain/$service_name/changeContact", body => $body, noSignature => 0 ); | ||
| 468 | |||
| 469 | croak $response->error if $response->error; | ||
| 470 | |||
| 471 | my $tasks = []; | ||
| 472 | my $task_ids = $response->content; | ||
| 473 | foreach my $task_id (@$task_ids) { | ||
| 474 | |||
| 475 | my $task = $api->me->task_contact_change($task_id); | ||
| 476 | push @$tasks, $task; | ||
| 477 | } | ||
| 478 | |||
| 479 | return $tasks; | ||
| 480 | } | ||
| 481 | |||
| 482 | =head2 change_service_infos | ||
| 483 | |||
| 484 | Change service_infos let you change the autorenewal method for this service | ||
| 485 | |||
| 486 | =over | ||
| 487 | |||
| 488 | =item * Parameter: %params - key => value renew(required) => { automatic(required), delete_at_expiration(required), forced(required), period(required) } | ||
| 489 | |||
| 490 | =item * Synopsis: $service->change_service_infos(renew => { automatic => 'yes', delete_at_expiration => 'yes', forced => 'yes', period => 12 }); | ||
| 491 | |||
| 492 | =back | ||
| 493 | |||
| 494 | =cut | ||
| 495 | |||
| 496 | sub change_service_infos { | ||
| 497 | |||
| 498 | my ( $self, %params ) = @_; | ||
| 499 | |||
| 500 | croak "Missing parameter: renew" unless $params{renew}; | ||
| 501 | |||
| 502 | my @keys = qw{ automatic delete_at_expiration forced period }; | ||
| 503 | if ( my @missing_parameters = grep { not exists $params{renew}{$_} } @keys ) { | ||
| 504 | |||
| 505 | croak "Missing parameter: @missing_parameters"; | ||
| 506 | } | ||
| 507 | |||
| 508 | my $options = {}; | ||
| 509 | $options->{automatic} = $params{renew}{automatic} eq 'true' || $params{renew}{automatic} eq 'yes' || $params{renew}{automatic} eq '1' ? JSON::true : JSON::false; | ||
| 510 | $options->{deleteAtExpiration} = $params{renew}{delete_at_expiration} eq 'true' || $params{renew}{delete_at_expiration} eq 'yes' || $params{renew}{delete_at_expiration} eq '1' ? JSON::true : JSON::false; | ||
| 511 | $options->{forced} = $params{renew}{forced} eq 'true' || $params{renew}{forced} eq 'yes' || $params{renew}{forced} eq '1' ? JSON::true : JSON::false; | ||
| 512 | |||
| 513 | my $api = $self->{_api_wrapper}; | ||
| 514 | my $service_name = $self->name; | ||
| 515 | my $body = {}; | ||
| 516 | $body->{renew}{period} = $params{renew}{period}; | ||
| 517 | $body->{renew}{automatic} = $options->{automatic}; | ||
| 518 | $body->{renew}{deleteAtExpiration} = $options->{deleteAtExpiration}; | ||
| 519 | $body->{renew}{forced} = $options->{forced}; | ||
| 520 | |||
| 521 | my $response = $api->rawCall( method => 'put', body => $body, path => "/domain/$service_name/serviceInfos", noSignature => 0 ); | ||
| 522 | croak $response->error if $response->error; | ||
| 523 | |||
| 524 | } | ||
| 525 | |||
| 526 | 1; |