blib/lib/WWW/eNom/Role/Command/Domain/Registration.pm

filter: Statementstmt 57.4% 27 / 47 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 61.5% 8 / 13 Podpod 100% 1 / 1 totaltotal 50.7% 36 / 71 CC 6 SCAR 27.0
CC
6
Cov
47%
__ANON__
42.0
register_domain
2.0
__ANON__
2.0
CRAP 14.9
« blib/lib/WWW/eNom/Role/Command/Service.pm ↑ Summary blib/lib/WWW/eNom/DomainTransfer.pm »
1 package WWW::eNom::Role::Command::Domain::Registration;
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( DomainRegistration );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 44 ▶use WWW::eNom::DomainRequest::Registration;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 44 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 44 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 44 requires 'submit', 'purchase_domain_privacy_for_domain';
16  
17 44 our $VERSION = 'v2.0.0'; # VERSION
18 # ABSTRACT: Domain Registration API Calls
19  
20 sub register_domain {
21 0 ▶ my $self = shift;
Subroutine register_domain: not called CC=1 SCAR=6.9
Pod documented
22 0 my ( %args ) = validated_hash(
23 \@_,
24 request => { isa => DomainRegistration, coerce => 1 },
25 );
26  
27 return try {
28 my $response = $self->submit({
29 method => 'Purchase',
30 0 ▶ params => $args{request}->construct_request(),
Subroutine __ANON__: not called CC=6 SCAR=37.4
31 });
32  
33 0 ▶ if( $response->{ErrCount} > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->{"ErrCount"} > 0) 0 0 0
34 0 ▶ if( grep { $_ eq 'Domain name not available' } @{ $response->{errors} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "Domain name not available";} @{$$response{"errors"};}) 0 0 0
35 0 croak 'Domain not available for registration';
36 }
37  
38 0 croak 'Unknown error';
39 }
40  
41 0 ▶ if( $args{request}->is_private ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"request"}->is_private) 0 0 0
42 $self->purchase_domain_privacy_for_domain({
43 domain_name => $args{request}->name,
44 years => $args{request}->years,
45 is_auto_renew => $args{request}->is_auto_renew,
46 0 });
47 }
48  
49 # Because there can be some lag between domain creation and being able to
50 # fetch the data from eNom, give it a few tries before calling it a failure
51 0 ▶ for ( my $attempt_number = 1; $attempt_number <= 5; $attempt_number++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attempt_number <= 5) 0 0 0
52 0 my $domain;
53 try {
54 $domain = $self->get_domain_by_name( $args{request}->name )
55 0 ▶ }
Subroutine __ANON__: not called CC=1 SCAR=6.9
56 catch {
57 0 ▶ sleep $attempt_number;
Subroutine __ANON__: not called CC=1 SCAR=6.9
58 0 };
59  
60 0 ▶ $domain and return $domain;
Branch: 1 branch
BranchTrueFalseTotal
$domain and return $domain 0 0 0
61 }
62  
63 0 croak 'Domain registered but unable to retrieve it';
64 }
65 catch {
66 0 ▶ croak $_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
67 0 };
68 }
69  
70 44 1;
71  
72 __END__
73  
74 =pod
75  
76 =head1 NAME
77  
78 WWW::eNom::Role::Command::Domain::Registration - Domain Registration API Calls
79  
80 =head1 SYNOPSIS
81  
82 use WWW::eNom;
83 use WWW::eNom::Domain;
84 use WWW::eNom::DomainRequest::Registration;
85  
86 my $api = WWW::eNom->new( ... );
87  
88 # Register a new domain
89 my $registration_request = WWW::eNom::DomainRequest::Registration->new( ... );
90 my $domain = $api->register_domain( request => $registration_request );
91  
92 =head1 REQUIRES
93  
94 =over 4
95  
96 =item submit
97  
98 =item purchase_domain_privacy_for_domain
99  
100 This is needed in order to purchase domain privacy for instances of L<WWW::eNom::DomainRequest::Registration> that have is_private set to true.
101  
102 =back
103  
104 =head1 DESCRIPTION
105  
106 Implements domain registration operations with the L<eNom|https://www.enom.com> API.
107  
108 =head1 METHODS
109  
110 =head2 register_domain
111  
112 my $registration_request = WWW::eNom::DomainRequest::Registration->new( ... );
113 my $domain = $api->register_domain( request => $registration_request );
114  
115 Abstraction of the L<Purchase|https://www.enom.com/api/API%20topics/api_Purchase.htm> eNom API Call. Given a L<WWW::eNom::DomainRequest::Registration> or a HashRef that can be coerced into a L<WWW::eNom::DomainRequest::Registration>, attempts to register the domain with L<eNom|https://www.enom.com>. If the domain you attempted to register is unavailable (because you don't sell that public suffix or because it's already taken) this method will croak with details about the error.
116  
117 Returned is a fully formed L<WWW::eNom::Domain> object.
118  
119 B<NOTE> This call is fairly slow (several seconds to complete). This is because, in addition to requesting the domain registration, several API calls are made to fetch back out the recently created domain registration and populate a L<WWW::eNom::Domain> object.
120  
121 B<FURTHER NOTE> It is possible for the domain registration to succeed but this method fail to retrieve the L<WWW::eNom::Domain>. When that occurs this method will croak with 'Domain registered but unable to retrieve it'. In this case you can either just move on (if you don't care about inspecting the L<WWW::eNom::Domain>) or you can request it again using L<WWW::eNom::Role::Command::Domain/get_domain_by_name>.
122  
123 =cut
« blib/lib/WWW/eNom/Role/Command/Service.pm ↑ Summary blib/lib/WWW/eNom/DomainTransfer.pm »