| 1 | package WWW::eNom::Role::Command::Contact; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 47 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 47 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 47 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 47 | ▶ | use MooseX::Params::Validate; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 47 | ▶ | use WWW::eNom::Types qw( Bool Contact DomainName HashRef Str ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 47 | ▶ | use WWW::eNom::Contact; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 47 | ▶ | use Data::Util qw( is_string ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 47 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 47 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 47 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 47 | Readonly my $ENOM_CONTACT_TYPE_MAPPING => { | |||||||||||||||||||||||||||
| 19 | Registrant => 'registrant_contact', | ||||||||||||||||||||||||||||
| 20 | Admin => 'admin_contact', | ||||||||||||||||||||||||||||
| 21 | Tech => 'technical_contact', | ||||||||||||||||||||||||||||
| 22 | AuxBilling => 'billing_contact', | ||||||||||||||||||||||||||||
| 23 | }; | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 47 | Readonly my $CONTACT_TYPE_ENOM_MAPPING => { reverse %{ $ENOM_CONTACT_TYPE_MAPPING } }; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 47 | requires 'submit'; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 47 | our $VERSION = 'v2.7.0'; # VERSION | |||||||||||||||||||||||||||
| 30 | # ABSTRACT: Contact Related Operations | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub get_contacts_by_domain_name { | ||||||||||||||||||||||||||
|
Subroutine
get_contacts_by_domain_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 34 | 0 | my ( $domain_name ) = pos_validated_list( \@_, { isa => DomainName } ); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | return try { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||
| 37 | 0 | my $response = $self->submit({ | |||||||||||||||||||||||||||
| 38 | method => 'GetContacts', | ||||||||||||||||||||||||||||
| 39 | params => { | ||||||||||||||||||||||||||||
| 40 | Domain => $domain_name | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | }); | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if( $response->{ErrCount} > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if( grep { $_ eq 'Domain name not found' } @{ $response->{errors} } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | croak 'Domain not found in your account'; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | croak 'Unknown error'; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | my $billing_party_id = $response->{GetContacts}{Billing}{BillingPartyID}; | |||||||||||||||||||||||||||
| 53 | my $billing_party_contact = WWW::eNom::Contact->construct_from_response( | ||||||||||||||||||||||||||||
| 54 | $self->_extract_common_contact_format( | ||||||||||||||||||||||||||||
| 55 | contact_type => 'Billing', | ||||||||||||||||||||||||||||
| 56 | raw_contact_response => $response->{GetContacts}{Billing}, | ||||||||||||||||||||||||||||
| 57 | ) | ||||||||||||||||||||||||||||
| 58 | 0 | ); | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | my $contacts; | |||||||||||||||||||||||||||
| 61 | 0 | for my $contact_type ( keys %{ $ENOM_CONTACT_TYPE_MAPPING } ) { | |||||||||||||||||||||||||||
| 62 | my $common_contact_response = $self->_extract_common_contact_format( | ||||||||||||||||||||||||||||
| 63 | contact_type => $contact_type, | ||||||||||||||||||||||||||||
| 64 | 0 | raw_contact_response => $response->{GetContacts}{$contact_type}, | |||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # If no other contact has been provided then MY information (the reseller) | ||||||||||||||||||||||||||||
| 68 | # is used. Treat this as no info. | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if( defined $common_contact_response->{PartyID} && $common_contact_response->{PartyID} eq $billing_party_id ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $common_contact_response->{"PartyID"} and $common_contact_response->{"PartyID"} eq $billing_party_id
MC/DC0%0/2
defined $common_contact_response->{"PartyID"} and $common_contact_response->{"PartyID"} eq $billing_party_id
defined $common_contact_response->{"PartyID"}
$common_contact_response->{"PartyID"} eq $billing_party_id
Truth table0%0/3
A and B
A= defined $common_contact_response->{"PartyID"}B= $common_contact_response->{"PartyID"} eq $billing_party_id
| |||||||||||||||||||||||||||||
| 70 | 0 | next; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | $contacts->{ $ENOM_CONTACT_TYPE_MAPPING->{ $contact_type} } = | |||||||||||||||||||||||||||
| 74 | WWW::eNom::Contact->construct_from_response( $common_contact_response ); | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # Check for anyone who used the reseller's contact info for a contact and replace | ||||||||||||||||||||||||||||
| 78 | # it with the registrant contact data. | ||||||||||||||||||||||||||||
| 79 | 0 | for my $contact_type ( values %{ $ENOM_CONTACT_TYPE_MAPPING } ) { | |||||||||||||||||||||||||||
| 80 | 0 | ▶ | if( !exists $contacts->{ $contact_type } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | # Do I have any other contacts that I can use? | ||||||||||||||||||||||||||||
| 82 | 0 | for my $replacement_contact_type ( grep { $_ ne $contact_type } ( values %{ $ENOM_CONTACT_TYPE_MAPPING } ) ) { | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | if( exists $contacts->{$replacement_contact_type} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | $contacts->{ $contact_type } = $contacts->{ $replacement_contact_type }; | |||||||||||||||||||||||||||
| 85 | 0 | last; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | # If I didn't find one, begrugingly use the billing one | ||||||||||||||||||||||||||||
| 90 | 0 | ▶ | $contacts->{ $contact_type } //= $billing_party_contact; | ||||||||||||||||||||||||||
|
Condition0%0/3
$contacts->{$contact_type} //= $billing_party_contact
MC/DC0%0/2
$contacts->{$contact_type} //= $billing_party_contact
$contacts->{$contact_type}
$billing_party_contact
Truth table0%0/3
A //= B
A= $contacts->{$contact_type}B= $billing_party_contact
| |||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | $contacts->{is_pending_irtp} = $response->{GetContacts}{PendingVerification} eq 'True'; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | return $contacts; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | 0 | ▶ | catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 99 | 0 | croak $_; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | 0 | } | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | sub _extract_common_contact_format { | ||||||||||||||||||||||||||
|
Subroutine
_extract_common_contact_format: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 104 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 105 | 0 | my ( %args ) = validated_hash( | |||||||||||||||||||||||||||
| 106 | \@_, | ||||||||||||||||||||||||||||
| 107 | contact_type => { isa => Str }, | ||||||||||||||||||||||||||||
| 108 | raw_contact_response => { isa => HashRef }, | ||||||||||||||||||||||||||||
| 109 | ); | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | my $common_contact_response; | |||||||||||||||||||||||||||
| 112 | 0 | for my $field ( keys %{ $args{raw_contact_response} } ) { | |||||||||||||||||||||||||||
| 113 | 0 | ▶ | if( $field !~ m/${\( $args{contact_type} )}/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | next; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | # If the value is not a string then consider it undefined | ||||||||||||||||||||||||||||
| 118 | $common_contact_response->{ substr( $field, length( $args{contact_type} ) ) } = | ||||||||||||||||||||||||||||
| 119 | 0 | ▶ | is_string( $args{raw_contact_response}->{ $field } ) ? $args{raw_contact_response}->{ $field } : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | # Try harder to create a valid contact for the Billing contact (the Reseller) | ||||||||||||||||||||||||||||
| 123 | # We do this since if we have no other (valid) contacts we can't build the domain, | ||||||||||||||||||||||||||||
| 124 | # better to have something rather than nothing | ||||||||||||||||||||||||||||
| 125 | 0 | ▶ | if( $args{contact_type} eq 'Billing' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | if( $common_contact_response->{OrganizationName} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | $common_contact_response->{JobTitle} //= 'Reseller'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$common_contact_response->{"JobTitle"} //= "Reseller"
MC/DC0%0/1
$common_contact_response->{"JobTitle"} //= "Reseller"
$common_contact_response->{"JobTitle"}
Truth table0%0/2
A
A= $common_contact_response->{"JobTitle"}
| |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | $common_contact_response->{Fax} //= $common_contact_response->{Phone}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$common_contact_response->{"Fax"} //= $common_contact_response->{"Phone"}
MC/DC0%0/2
$common_contact_response->{"Fax"} //= $common_contact_response->{"Phone"}
$common_contact_response->{"Fax"}
$common_contact_response->{"Phone"}
Truth table0%0/3
A //= B
A= $common_contact_response->{"Fax"}B= $common_contact_response->{"Phone"}
| |||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | return $common_contact_response; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | ▶ | sub update_contacts_for_domain_name { | ||||||||||||||||||||||||||
|
Subroutine
update_contacts_for_domain_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 136 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 137 | 0 | my ( %args ) = validated_hash( | |||||||||||||||||||||||||||
| 138 | \@_, | ||||||||||||||||||||||||||||
| 139 | domain_name => { isa => DomainName }, | ||||||||||||||||||||||||||||
| 140 | registrant_contact => { isa => Contact, optional => 1 }, | ||||||||||||||||||||||||||||
| 141 | admin_contact => { isa => Contact, optional => 1 }, | ||||||||||||||||||||||||||||
| 142 | technical_contact => { isa => Contact, optional => 1 }, | ||||||||||||||||||||||||||||
| 143 | billing_contact => { isa => Contact, optional => 1 }, | ||||||||||||||||||||||||||||
| 144 | is_transfer_locked => { isa => Bool, default => 1 }, | ||||||||||||||||||||||||||||
| 145 | ); | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | ▶ | try { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 148 | # The not for is_transfer_locked is because eNom treats this as opt out | ||||||||||||||||||||||||||||
| 149 | # while I'm treating the input as just if it should lock or not | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | # Replace all contacts at once | ||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if( ( scalar grep { exists $args{$_} && defined $args{$_} } values %{ $ENOM_CONTACT_TYPE_MAPPING } ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $args{$_} && defined $args{$_}
MC/DC0%0/2
exists $args{$_} && defined $args{$_}
exists $args{$_}
defined $args{$_}
Truth table0%0/3
A && B
A= exists $args{$_}B= defined $args{$_}
| |||||||||||||||||||||||||||||
| 153 | 0 | == ( scalar values %{ $ENOM_CONTACT_TYPE_MAPPING } ) ) { | |||||||||||||||||||||||||||
| 154 | $self->_update_contacts({ | ||||||||||||||||||||||||||||
| 155 | payload => { | ||||||||||||||||||||||||||||
| 156 | Domain => $args{domain_name}, | ||||||||||||||||||||||||||||
| 157 | IRTPOptOut => ( !$args{is_transfer_locked} ? 'true' : 'false' ), | ||||||||||||||||||||||||||||
| 158 | 0 | %{ $args{registrant_contact}->construct_creation_request('Registrant') }, | |||||||||||||||||||||||||||
| 159 | 0 | %{ $args{admin_contact}->construct_creation_request('Admin') }, | |||||||||||||||||||||||||||
| 160 | 0 | %{ $args{technical_contact}->construct_creation_request('Tech') }, | |||||||||||||||||||||||||||
| 161 | 0 | ▶ | %{ $args{billing_contact}->construct_creation_request('AuxBilling') }, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | }); | ||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | # Replace contacts one at a time | ||||||||||||||||||||||||||||
| 166 | else { | ||||||||||||||||||||||||||||
| 167 | 0 | for my $contact_type ( values %{ $ENOM_CONTACT_TYPE_MAPPING } ) { | |||||||||||||||||||||||||||
| 168 | 0 | ▶ | if( !exists $args{ $contact_type } || !defined $args{ $contact_type } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $args{$contact_type} and defined $args{$contact_type}
MC/DC0%0/2
exists $args{$contact_type} and defined $args{$contact_type}
exists $args{$contact_type}
defined $args{$contact_type}
Truth table0%0/3
A and B
A= exists $args{$contact_type}B= defined $args{$contact_type}
| |||||||||||||||||||||||||||||
| 169 | 0 | next; | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | $self->_update_contacts({ | ||||||||||||||||||||||||||||
| 173 | payload => { | ||||||||||||||||||||||||||||
| 174 | Domain => $args{domain_name}, | ||||||||||||||||||||||||||||
| 175 | IRTPOptOut => ( !$args{is_transfer_locked} ? 'True' : 'False' ), | ||||||||||||||||||||||||||||
| 176 | ContactType => uc $CONTACT_TYPE_ENOM_MAPPING->{ $contact_type }, | ||||||||||||||||||||||||||||
| 177 | 0 | ▶ | %{ $args{ $contact_type }->construct_creation_request( $CONTACT_TYPE_ENOM_MAPPING->{ $contact_type } ) }, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | }); | ||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | 0 | ▶ | catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 184 | 0 | croak $_; | |||||||||||||||||||||||||||
| 185 | 0 | }; | |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 0 | return $self->get_contacts_by_domain_name( $args{domain_name} ); | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 0 | ▶ | sub _update_contacts { | ||||||||||||||||||||||||||
|
Subroutine
_update_contacts: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 191 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 192 | 0 | my ( %args ) = validated_hash( | |||||||||||||||||||||||||||
| 193 | \@_, | ||||||||||||||||||||||||||||
| 194 | payload => { isa => HashRef }, | ||||||||||||||||||||||||||||
| 195 | ); | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | my $response = $self->submit({ | ||||||||||||||||||||||||||||
| 198 | method => 'Contacts', | ||||||||||||||||||||||||||||
| 199 | params => $args{payload}, | ||||||||||||||||||||||||||||
| 200 | 0 | }); | |||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 0 | ▶ | if( $response->{ErrCount} > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | 0 | ▶ | if( grep { $_ eq 'Domain name ID not found' } @{ $response->{errors} } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | 0 | croak 'Domain not found in your account'; | |||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 0 | croak 'Unknown error'; | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 0 | return $response; | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 47 | 1; | |||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | __END__ | ||||||||||||||||||||||||||||