| 1 | package WWW::DNSMadeEasy::ManagedDomain; | ||||||||||||||||||||||||||||
| 2 | 8 | our $VERSION = '0.100'; | |||||||||||||||||||||||||||
| 3 | 8 | our $AUTHORITY = 'cpan:GETTY'; | |||||||||||||||||||||||||||
| 4 | # ABSTRACT: A managed domain in the DNSMadeEasy API | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use String::CamelSnakeKebab qw/lower_camel_case/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 8 | ▶ | use WWW::DNSMadeEasy::ManagedDomain::Record; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 8 | has dme => ( | |||||||||||||||||||||||||||
| 11 | is => 'ro', | ||||||||||||||||||||||||||||
| 12 | required => 1, | ||||||||||||||||||||||||||||
| 13 | handles => { | ||||||||||||||||||||||||||||
| 14 | request => 'request', | ||||||||||||||||||||||||||||
| 15 | path => 'domain_path', | ||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 8 | has name => (is => 'ro', required => 1); | |||||||||||||||||||||||||||
| 20 | 8 | has as_hashref => (is => 'rw', builder => 1, lazy => 1, clearer => 1); | |||||||||||||||||||||||||||
| 21 | 8 | has response => (is => 'rw', builder => 1, lazy => 1, clearer => 1); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 6 | ▶ | sub _build_as_hashref { shift->response->as_hashref } | ||||||||||||||||||||||||||
|
Subroutine
_build_as_hashref: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 6 | ▶ | sub _build_response { $_[0]->request(GET => $_[0]->path . 'id/' . $_[0]->name) } | ||||||||||||||||||||||||||
|
Subroutine
_build_response: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub active_third_parties { shift->as_hashref->{activeThirdParties} } | ||||||||||||||||||||||||||
|
Subroutine
active_third_parties: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub created { shift->as_hashref->{created} } | ||||||||||||||||||||||||||
|
Subroutine
created: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub delegate_name_servers { shift->as_hashref->{delegateNameServers} } | ||||||||||||||||||||||||||
|
Subroutine
delegate_name_servers: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub folder_id { shift->as_hashref->{folderId} } | ||||||||||||||||||||||||||
|
Subroutine
folder_id: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub gtd_enabled { shift->as_hashref->{gtdEnabled} } | ||||||||||||||||||||||||||
|
Subroutine
gtd_enabled: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 7 | ▶ | sub id { shift->as_hashref->{id} } | ||||||||||||||||||||||||||
|
Subroutine
id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub name_servers { shift->as_hashref->{nameServers} } | ||||||||||||||||||||||||||
|
Subroutine
name_servers: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub pending_action_id { shift->as_hashref->{pendingActionId} } | ||||||||||||||||||||||||||
|
Subroutine
pending_action_id: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub process_multi { shift->as_hashref->{processMulti} } | ||||||||||||||||||||||||||
|
Subroutine
process_multi: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub updated { shift->as_hashref->{updated} } | ||||||||||||||||||||||||||
|
Subroutine
updated: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub delete { | ||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 39 | 0 | $self->request(DELETE => $self->path . $self->id); | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub update { | ||||||||||||||||||||||||||
|
Subroutine
update: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 0 | my ($self, $data) = @_; | |||||||||||||||||||||||||||
| 44 | 0 | $self->clear_as_hashref; | |||||||||||||||||||||||||||
| 45 | 0 | my $res = $self->request(PUT => $self->path . $self->id, $data); | |||||||||||||||||||||||||||
| 46 | 0 | $self->response($res); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub wait_for_delete { | ||||||||||||||||||||||||||
|
Subroutine
wait_for_delete: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 50 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 51 | 0 | while (1) { | |||||||||||||||||||||||||||
| 52 | 0 | $self->clear_response; | |||||||||||||||||||||||||||
| 53 | 0 | $self->clear_as_hashref; | |||||||||||||||||||||||||||
| 54 | 0 | eval { $self->response() }; | |||||||||||||||||||||||||||
| 55 | 0 | ▶ | last if $@ && $@ =~ /(404|400)/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$@ and $@ =~ /(404|400)/
MC/DC0%0/2
$@ and $@ =~ /(404|400)/
$@
$@ =~ /(404|400)/
Truth table0%0/3
A and B
A= $@B= $@ =~ /(404|400)/
| |||||||||||||||||||||||||||||
| 56 | 0 | sleep 10; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub wait_for_pending_action { | ||||||||||||||||||||||||||
|
Subroutine
wait_for_pending_action: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 62 | 0 | while (1) { | |||||||||||||||||||||||||||
| 63 | 0 | $self->clear_response; | |||||||||||||||||||||||||||
| 64 | 0 | $self->clear_as_hashref; | |||||||||||||||||||||||||||
| 65 | 0 | ▶ | last if $self->pending_action_id == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | sleep 10; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # | ||||||||||||||||||||||||||||
| 71 | # RECORDS | ||||||||||||||||||||||||||||
| 72 | # | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 5 | ▶ | sub records_path { $_[0]->path . $_[0]->id . '/records/' } | ||||||||||||||||||||||||||
|
Subroutine
records_path: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 1 | ▶ | sub create_record { | ||||||||||||||||||||||||||
|
Subroutine
create_record: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 77 | 1 | my ( $self, %data ) = @_; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 1 | my %req; | |||||||||||||||||||||||||||
| 80 | 1 | for my $old (keys %data) { | |||||||||||||||||||||||||||
| 81 | 5 | my $new = lower_camel_case($old); | |||||||||||||||||||||||||||
| 82 | 5 | $req{$new} = $data{$old}; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 1 | return WWW::DNSMadeEasy::ManagedDomain::Record->new( | |||||||||||||||||||||||||||
| 86 | response => $self->request(POST => $self->records_path, \%req), | ||||||||||||||||||||||||||||
| 87 | domain => $self, | ||||||||||||||||||||||||||||
| 88 | ); | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # TODO | ||||||||||||||||||||||||||||
| 92 | # - do multiple gets when max number of records is reached | ||||||||||||||||||||||||||||
| 93 | # - save the request as part of the Record obj | ||||||||||||||||||||||||||||
| 94 | 3 | ▶ | sub records { | ||||||||||||||||||||||||||
|
Subroutine
records: called CC=8 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | 3 | my ($self, %args) = @_; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | # TODO should switch to URI->query_form() but that requires changing DME->request() | ||||||||||||||||||||||||||||
| 98 | 3 | my $path = $self->records_path; | |||||||||||||||||||||||||||
| 99 | 3 | ▶ | $path .= '?type=' . $args{type} if defined $args{type} && !defined $args{name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $args{"type"} and not defined $args{"name"}
MC/DC0%0/2
defined $args{"type"} and not defined $args{"name"}
defined $args{"type"}
not defined $args{"name"}
Truth table33%1/3
A and not(B)
A= defined $args{"type"}B= not defined $args{"name"}
| |||||||||||||||||||||||||||||
| 100 | 3 | ▶ | $path .= '?recordName=' . $args{name} if defined $args{name} && !defined $args{type}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $args{"name"} and not defined $args{"type"}
MC/DC0%0/2
defined $args{"name"} and not defined $args{"type"}
defined $args{"name"}
not defined $args{"type"}
Truth table33%1/3
A and not(B)
A= defined $args{"name"}B= not defined $args{"type"}
| |||||||||||||||||||||||||||||
| 101 | $path .= '?recordName=' . $args{name} . | ||||||||||||||||||||||||||||
| 102 | 3 | ▶ | '&type=' . $args{type} if defined $args{name} && defined $args{type}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $args{"name"} and defined $args{"type"}
MC/DC0%0/2
defined $args{"name"} and defined $args{"type"}
defined $args{"name"}
defined $args{"type"}
Truth table33%1/3
A and B
A= defined $args{"name"}B= defined $args{"type"}
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 3 | my $arrayref = $self->request(GET => $path)->data->{data}; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 3 | my @records; | |||||||||||||||||||||||||||
| 107 | 3 | for my $hashref (@$arrayref) { | |||||||||||||||||||||||||||
| 108 | 6 | push @records, WWW::DNSMadeEasy::ManagedDomain::Record | |||||||||||||||||||||||||||
| 109 | ->new(as_hashref => $hashref, domain => $self); | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 3 | return @records; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 8 | 1; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | __END__ | ||||||||||||||||||||||||||||