| 1 | package WWW::eNom::Role::Command::Contact; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 44 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 44 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 44 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 44 | ▶ | use MooseX::Params::Validate; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 44 | ▶ | use WWW::eNom::Types qw( Contact DomainName HashRef ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 44 | ▶ | use WWW::eNom::Contact; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 44 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 44 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 44 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 44 | Readonly my $ENOM_CONTACT_TYPE_MAPPING => { | |||||||||||||||||||||||||||
| 18 | Registrant => 'registrant_contact', | ||||||||||||||||||||||||||||
| 19 | Admin => 'admin_contact', | ||||||||||||||||||||||||||||
| 20 | Tech => 'technical_contact', | ||||||||||||||||||||||||||||
| 21 | AuxBilling => 'billing_contact', | ||||||||||||||||||||||||||||
| 22 | }; | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 44 | Readonly my $CONTACT_TYPE_ENOM_MAPPING => { reverse %{ $ENOM_CONTACT_TYPE_MAPPING } }; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 44 | requires 'submit'; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 44 | our $VERSION = 'v2.0.0'; # VERSION | |||||||||||||||||||||||||||
| 29 | # ABSTRACT: Contact Related Operations | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | sub get_contacts_by_domain_name { | ||||||||||||||||||||||||||||
| 32 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_contacts_by_domain_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | 0 | my ( $domain_name ) = pos_validated_list( \@_, { isa => DomainName } ); | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | return try { | ||||||||||||||||||||||||||||
| 36 | 0 | ▶ | my $response = $self->submit({ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||
| 37 | method => 'GetContacts', | ||||||||||||||||||||||||||||
| 38 | params => { | ||||||||||||||||||||||||||||
| 39 | Domain => $domain_name | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | }); | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if( $response->{ErrCount} > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if( grep { $_ eq 'Domain name not found' } @{ $response->{errors} } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | croak 'Domain not found in your account'; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | croak 'Unknown error'; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | my $billing_party_id = $response->{GetContacts}{Billing}{BillingPartyID}; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | my $contacts; | |||||||||||||||||||||||||||
| 54 | 0 | for my $contact_type ( keys %{ $ENOM_CONTACT_TYPE_MAPPING } ) { | |||||||||||||||||||||||||||
| 55 | 0 | my $raw_contact_response = $response->{GetContacts}{$contact_type}; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | my $common_contact_response; | |||||||||||||||||||||||||||
| 58 | 0 | for my $field ( keys %{ $raw_contact_response } ) { | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | if( $field !~ m/$contact_type/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | next; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | $common_contact_response->{ substr( $field, length( $contact_type ) ) } = | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | $raw_contact_response->{ $field } // { }; | ||||||||||||||||||||||||||
|
Condition0%0/2
$raw_contact_response->{$field} // {}
MC/DC0%0/1
$raw_contact_response->{$field} // {}
$raw_contact_response->{$field}
Truth table0%0/2
A
A= $raw_contact_response->{$field}
| |||||||||||||||||||||||||||||
| 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( $common_contact_response->{PartyID} eq $billing_party_id ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 0 | $contacts->{ $contact_type } = $contacts->{registrant_contact}; | |||||||||||||||||||||||||||
| 82 | # TODO: Save this contact back, a sort of just in time repair | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | return $contacts; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | catch { | ||||||||||||||||||||||||||||
| 89 | 0 | ▶ | croak $_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | 0 | } | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | sub update_contacts_for_domain_name { | ||||||||||||||||||||||||||||
| 94 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
update_contacts_for_domain_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | 0 | my ( %args ) = validated_hash( | |||||||||||||||||||||||||||
| 96 | \@_, | ||||||||||||||||||||||||||||
| 97 | domain_name => { isa => DomainName }, | ||||||||||||||||||||||||||||
| 98 | registrant_contact => { isa => Contact, optional => 1 }, | ||||||||||||||||||||||||||||
| 99 | admin_contact => { isa => Contact, optional => 1 }, | ||||||||||||||||||||||||||||
| 100 | technical_contact => { isa => Contact, optional => 1 }, | ||||||||||||||||||||||||||||
| 101 | billing_contact => { isa => Contact, optional => 1 }, | ||||||||||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | try { | ||||||||||||||||||||||||||||
| 105 | # Replace all contacts at once | ||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if( ( scalar grep { exists $args{$_} && defined $args{$_} } values %{ $ENOM_CONTACT_TYPE_MAPPING } ) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 107 | 0 | == ( scalar values %{ $ENOM_CONTACT_TYPE_MAPPING } ) ) { | |||||||||||||||||||||||||||
| 108 | $self->_update_contacts({ | ||||||||||||||||||||||||||||
| 109 | payload => { | ||||||||||||||||||||||||||||
| 110 | Domain => $args{domain_name}, | ||||||||||||||||||||||||||||
| 111 | 0 | %{ $args{registrant_contact}->construct_creation_request('Registrant') }, | |||||||||||||||||||||||||||
| 112 | 0 | %{ $args{admin_contact}->construct_creation_request('Admin') }, | |||||||||||||||||||||||||||
| 113 | 0 | %{ $args{technical_contact}->construct_creation_request('Tech') }, | |||||||||||||||||||||||||||
| 114 | 0 | %{ $args{billing_contact}->construct_creation_request('AuxBilling') }, | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | }); | ||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | # Replace contacts one at a time | ||||||||||||||||||||||||||||
| 119 | else { | ||||||||||||||||||||||||||||
| 120 | 0 | for my $contact_type ( values %{ $ENOM_CONTACT_TYPE_MAPPING } ) { | |||||||||||||||||||||||||||
| 121 | 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}
| |||||||||||||||||||||||||||||
| 122 | 0 | next; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | $self->_update_contacts({ | ||||||||||||||||||||||||||||
| 126 | payload => { | ||||||||||||||||||||||||||||
| 127 | Domain => $args{domain_name}, | ||||||||||||||||||||||||||||
| 128 | ContactType => uc $CONTACT_TYPE_ENOM_MAPPING->{ $contact_type }, | ||||||||||||||||||||||||||||
| 129 | 0 | %{ $args{ $contact_type }->construct_creation_request( $CONTACT_TYPE_ENOM_MAPPING->{ $contact_type } ) }, | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | }); | ||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | catch { | ||||||||||||||||||||||||||||
| 136 | 0 | ▶ | croak $_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 137 | 0 | }; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | return $self->get_contacts_by_domain_name( $args{domain_name} ); | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | sub _update_contacts { | ||||||||||||||||||||||||||||
| 143 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_update_contacts: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 144 | 0 | my ( %args ) = validated_hash( | |||||||||||||||||||||||||||
| 145 | \@_, | ||||||||||||||||||||||||||||
| 146 | payload => { isa => HashRef }, | ||||||||||||||||||||||||||||
| 147 | ); | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | my $response = $self->submit({ | ||||||||||||||||||||||||||||
| 150 | method => 'Contacts', | ||||||||||||||||||||||||||||
| 151 | params => $args{payload}, | ||||||||||||||||||||||||||||
| 152 | 0 | }); | |||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | ▶ | if( $response->{ErrCount} > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 0 | ▶ | if( grep { $_ eq 'Domain name ID not found' } @{ $response->{errors} } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 0 | croak 'Domain not found in your account'; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 0 | croak 'Unknown error'; | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 0 | return $response; | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 44 | 1; | |||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | __END__ | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | =head1 NAME | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | WWW::eNom::Role::Command::Contact - Contact Related Operations | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | use WWW::eNom; | ||||||||||||||||||||||||||||
| 176 | use WWW::eNom::Contact; | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | my $api = WWW::eNom->new( ... ); | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | # Get Contacts for a Domain | ||||||||||||||||||||||||||||
| 181 | my $contacts = $api->get_contacts_by_domain_name( 'drzigman.com' ); | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | for my $contact_type (qw( registrant_contact admin_contact technical_contact billing_contact )) { | ||||||||||||||||||||||||||||
| 184 | print "Email Address of $contact_type is: " . $contacts->{$contact_type}->email . "\n"; | ||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | # Update Contacts | ||||||||||||||||||||||||||||
| 188 | my $new_registrant_contact = WWW::eNom::Contact->new( ... ); | ||||||||||||||||||||||||||||
| 189 | my $new_admin_contact = WWW::eNom::Contact->new( ... ); | ||||||||||||||||||||||||||||
| 190 | my $new_technical_contact = WWW::eNom::Contact->new( ... ); | ||||||||||||||||||||||||||||
| 191 | my $new_billing_contact = WWW::eNom::Contact->new( ... ); | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | my $updated_contacts = $api->update_contacts_for_domain_name( | ||||||||||||||||||||||||||||
| 194 | domain_name => 'drzigman.com', | ||||||||||||||||||||||||||||
| 195 | registrant_contact => $new_registrant_contact, # Optional | ||||||||||||||||||||||||||||
| 196 | admin_contact => $new_admin_contact, # Optional | ||||||||||||||||||||||||||||
| 197 | technical_contact => $new_technical_contact, # Optional | ||||||||||||||||||||||||||||
| 198 | billing_contact => $new_billing_contact, # Optional | ||||||||||||||||||||||||||||
| 199 | ); | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | =head1 REQUIRES | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | =over 4 | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | =item submit | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | =back | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | Implements contact related operations with L<eNom|https://www.enom.com>'s API. | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | =head1 METHODS | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | =head2 get_contacts_by_domain_name | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | my $contacts = $api->get_contacts_by_domain_name( 'drzigman.com' ); | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | for my $contact_type (qw( registrant_contact admin_contact technical_contact billing_contact )) { | ||||||||||||||||||||||||||||
| 220 | print "Email Address of $contact_type is: " . $contacts->{$contact_type}->email . "\n"; | ||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | Abstraction of the L<GetContacts|https://www.enom.com/api/API%20topics/api_GetContacts.htm> eNom API Call. Given a FQDN, returns a HashRef of contacts for that domain. The keys for the returned HashRef are: | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | =over 4 | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | =item registrant_contact | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | =item admin_contact | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | =item technical_contact | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | =item billing_contact | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | =back | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | Each of these keys point to a value which is an instance of L<WWW::eNom::Contact>. | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | =head2 update_contacts_for_domain_name | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | my $updated_contacts = $api->update_contacts_for_domain_name( | ||||||||||||||||||||||||||||
| 242 | domain_name => 'drzigman.com', | ||||||||||||||||||||||||||||
| 243 | registrant_contact => $new_registrant_contact, # Optional | ||||||||||||||||||||||||||||
| 244 | admin_contact => $new_admin_contact, # Optional | ||||||||||||||||||||||||||||
| 245 | technical_contact => $new_technical_contact, # Optional | ||||||||||||||||||||||||||||
| 246 | billing_contact => $new_billing_contact, # Optional | ||||||||||||||||||||||||||||
| 247 | ); | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | Abstraction of the L<Contacts|https://www.enom.com/api/API%20topics/api_Contacts.htm> eNom API Call. Given a FQDN and new contacts to use, updates the specified contacts to match those provided. Returned is a HashRef of Contacts (see L<get_contacts_by_domain_name> for response format). | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | One interesting thing about this method is that you only need specify the contacts you wish to update. If you wish to update registrant, admin, technical, and billing great! Go for it and include all of them in one call. If you wish to update only a subset of the contacts (1, 2 or 3 of them) you should pass only the contacts to be updated. | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | =cut | ||||||||||||||||||||||||||||