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

filter: Statementstmt 37.8% 36 / 95 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 47.8% 11 / 23 Podpod 100% 4 / 4 totaltotal 34.6% 51 / 147 CC 13 SCAR 23.7
CC
13
Cov
31%
__ANON__
30.0
__ANON__
20.0
__ANON__
20.0
CRAP 10.7
« blib/lib/WWW/eNom/DomainTransfer.pm ↑ Summary Build »
1 package WWW::eNom::Role::Command::Domain::Transfer;
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( DomainName DomainTransfer PositiveInt );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 44 ▶use WWW::eNom::DomainRequest::Transfer;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 44 ▶use WWW::eNom::DomainTransfer;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 44 ▶use Data::Util qw( is_array_ref );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 44 ▶use Math::Currency;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 44 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 44 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 44 requires 'submit', 'get_domain_privacy_wholesale_price';
19  
20 44 our $VERSION = 'v2.0.0'; # VERSION
21 # ABSTRACT: Domain Transfer API Calls
22  
23 sub transfer_domain {
24 0 ▶ my $self = shift;
Subroutine transfer_domain: not called CC=1 SCAR=6.9
Pod documented
25 0 my ( %args ) = validated_hash(
26 \@_,
27 request => { isa => DomainTransfer, coerce => 1 },
28 );
29  
30 return try {
31 0 ▶ my $domain_privacy_price;
Subroutine __ANON__: not called CC=4 SCAR=30.0
32 0 ▶ if( $args{request}->is_private ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"request"}->is_private) 0 0 0
33 0 $domain_privacy_price = $self->get_domain_privacy_wholesale_price();
34 }
35  
36 my $response = $self->submit({
37 method => 'TP_CreateOrder',
38 params => {
39 0 ▶ %{ $args{request}->construct_request() },
Branch: 1 branch
BranchTrueFalseTotal
$domain_privacy_price ? : 0 0 0
40 $domain_privacy_price ? ( IDPPrice => $domain_privacy_price->as_float ) : ( ),
41 },
42 });
43  
44 0 ▶ if( $response->{ErrCount} > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->{"ErrCount"} > 0) 0 0 0
45 0 croak 'Unknown error';
46 }
47  
48 0 $self->get_transfer_by_order_id( $response->{transferorder}{transferorderdetail}{transferorderdetailid} );
49 }
50 catch {
51 0 ▶ croak $_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
52 0 };
53 }
54  
55 sub get_transfer_by_order_id {
56 0 ▶ my $self = shift;
Subroutine get_transfer_by_order_id: not called CC=1 SCAR=6.9
Pod documented
57 0 my ( $order_id ) = pos_validated_list( \@_, { isa => PositiveInt } );
58  
59 return try {
60 0 ▶ my $response = $self->submit({
Subroutine __ANON__: not called CC=4 SCAR=30.0
61 method => 'TP_GetOrderDetail',
62 params => {
63 TransferOrderDetailID => $order_id,
64 }
65 });
66  
67 0 ▶ if( $response->{ErrCount} > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->{"ErrCount"} > 0) 0 0 0
68 0 ▶ if( ( grep { $_ eq 'Transfer Order Detail record does not exist.' } @{ $response->{errors} } )
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "Transfer Order Detail record does not exist.";} @{$$response{"errors"};} or grep {$_ eq "Invalid Transfer Order Detail ID";} @{$$response{"errors"};}) 0 0 0
Condition0%0/3
grep {$_ eq "Transfer Order Detail record does not exist.";} @{$$response{"errors"};} or grep {$_ eq "Invalid Transfer Order Detail ID";} @{$$response{"errors"};}
l!l&&r!l&&!r
000
MC/DC0%0/2
grep {$_ eq "Transfer Order Detail record does not exist.";} @{$$response{"errors"};} or grep {$_ eq "Invalid Transfer Order Detail ID";} @{$$response{"errors"};}
grep {$_ eq "Transfer Order Detail record does not exist.";} @{$$response{"errors"};} grep {$_ eq "Invalid Transfer Order Detail ID";} @{$$response{"errors"};}
Truth table0%0/3
A or B
A= grep {$_ eq "Transfer Order Detail record does not exist.";} @{$$response{"errors"};}B= grep {$_ eq "Invalid Transfer Order Detail ID";} @{$$response{"errors"};}
ABresult
1X1
011
000
69 0 || ( grep { $_ eq 'Invalid Transfer Order Detail ID' } @{ $response->{errors} } ) ) {
70 0 croak 'No transfer found in your account with specified id';
71 }
72  
73 0 croak 'Unknown error';
74 }
75  
76 0 return WWW::eNom::DomainTransfer->construct_from_response( transfer_detail => $response->{transferorderdetail} );
77 }
78 catch {
79 0 ▶ croak $_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
80 0 };
81 }
82  
83 sub get_transfer_by_name {
84 0 ▶ my $self = shift;
Subroutine get_transfer_by_name: not called CC=1 SCAR=6.9
Pod documented
85 0 my ( $domain_name ) = pos_validated_list( \@_, { isa => DomainName } );
86  
87 return try {
88 0 ▶ my $response = $self->submit({
Subroutine __ANON__: not called CC=5 SCAR=34.0
89 method => 'TP_GetDetailsByDomain',
90 params => {
91 Domain => $domain_name,
92 }
93 });
94  
95 0 ▶ if( $response->{ErrCount} > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->{"ErrCount"} > 0) 0 0 0
96 0 ▶ if( grep { $_ eq 'There are no transfer order details' } @{ $response->{errors} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "There are no transfer order details";} @{$$response{"errors"};}) 0 0 0
97 0 croak 'No transfer found for specified domain name';
98 }
99  
100 0 croak 'Unknown error';
101 }
102  
103 0 my @raw_transfer_orders;
104 0 ▶ if( is_array_ref( $response->{TransferOrder} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_array_ref($response->{'TransferOrder'})) { } 0 0 0
105 0 @raw_transfer_orders = @{ $response->{TransferOrder} };
106 }
107 else {
108 0 @raw_transfer_orders = ( $response->{TransferOrder} );
109 }
110  
111 0 my @transfers;
112 0 for my $transfer_order ( @raw_transfer_orders ) {
113 0 my $order_id = $self->get_transfer_order_id_from_parent_order_id( $transfer_order->{orderid} );
114 0 push @transfers, $self->get_transfer_by_order_id( $order_id );
115 }
116  
117 0 return \@transfers;
118 }
119 catch {
120 0 ▶ croak $_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
121 0 };
122 }
123  
124 sub get_transfer_order_id_from_parent_order_id {
125 0 ▶ my $self = shift;
Subroutine get_transfer_order_id_from_parent_order_id: not called CC=1 SCAR=6.9
Pod documented
126 0 my ( $parent_order_id ) = pos_validated_list( \@_, { isa => PositiveInt } );
127  
128 return try {
129 0 ▶ my $response = $self->submit({
Subroutine __ANON__: not called CC=3 SCAR=24.8
130 method => 'TP_GetOrder',
131 params => {
132 TransferOrderID => $parent_order_id,
133 }
134 });
135  
136 0 ▶ if( $response->{ErrCount} > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->{"ErrCount"} > 0) 0 0 0
137 0 ▶ if( grep { $_ eq 'Transfer Order does not exist.' } @{ $response->{errors} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "Transfer Order does not exist.";} @{$$response{"errors"};}) 0 0 0
138 0 croak 'No transfer found for specified parent order id';
139 }
140  
141 0 croak 'Unknown error';
142 }
143  
144 0 return $response->{transferorder}{transferorderdetail}{transferorderdetailid};
145 }
146 catch {
147 0 ▶ croak $_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
148 0 };
149 }
150  
151 44 1;
152  
153 __END__
154  
155 =pod
156  
157 =head1 NAME
158  
159 WWW::eNom::Role::Command::Domain::Transfer - Domain Transfer API Calls
160  
161 =head1 SYNOPSIS
162  
163 use WWW::eNom;
164 use WWW::eNom::DomainRequest::Transfer;
165 use WWW::eNom::DomainTransfer;
166  
167 my $api = WWW::eNom->new( ... );
168  
169 # Start a Domain Transfer
170 my $transfer_request = WWW::eNom::DomainRequest::Transfer->new( ... );
171 my $transfer = $api->transfer_domain( request => $transfer_request );
172  
173 # Get the Status of An In Progress Transfer
174 my $in_progress_transfer = WWW::eNom::DomainTransfer->new( ... );
175 my $updated_transfer = $api->get_transfer_by_order_id( $in_progress_transfer->order_id );
176  
177 # Get history of transfer attempts for a domain
178 my $transfers = $api->get_transfer_by_name( 'drzigman.com' );
179  
180 for my $transfer (@{ $transfers }) {
181 print 'Transfer Order ID: ' . $transfer->order_id . "\n";
182 print 'Transfer Status: ' . $transfer->status . "\n";
183 }
184  
185 # Get a Transfer's order_id by the parent order id
186 my $order_id = $api->get_transfer_order_id_from_parent_order_id( 42 );
187 my $transfer = $api->get_transfer_by_order_id( $order_id );
188  
189 =head1 REQUIRES
190  
191 =over 4
192  
193 =item submit
194  
195 =item get_domain_privacy_wholesale_price
196  
197 This is needed in order to purchase domain privacy for instances of L<WWW::eNom::DomainRequest::Transfer> that have is_private set to true.
198  
199 =back
200  
201 =head1 DESCRIPTION
202  
203 Implements domain transfer operations with the L<eNom|https://www.enom.com> API.
204  
205 =head1 METHODS
206  
207 =head2 transfer_domain
208  
209 my $transfer_request = WWW::eNom::DomainRequest::Transfer->new( ... );
210 my $transfer = $api->transfer_domain( request => $transfer_request );
211  
212 Abstraction of the L<TP_CreateOrder|https://www.enom.com/api/API%20Topics/API_TP_CreateOrder.htm> eNom API Call. Given a L<WWW::eNom::DomainRequest::Transfer> or a HashRef that can be coerced into a L<WWW::eNom::DomainRequest::Transfer>, attempts to start the domain transfer process to move the domain to L<eNom|https://www.enom.com>. Returned is a provisional L<WWW::eNom::DomainTransfer> object.
213  
214 B<NOTE> Unfortunately, eNom does not process it's transfer requests live, meaning if there are errors with the request (bad EPP Key, domain is not actually registered, etc) you won't find that out for several minutes after submitting the transfer request. That's why a "provisional" L<WWW::eNom::DomainTransfer> object is returned. It is recommended that you periodically check the status of the transfer by using the L<get_transfer_by_order_id> method, paying attention to the L<status|WWW::eNom::DomainTransfer/status> and L<status_id|WWW::eNom::DomainTransfer/status_id> to ensure the transfer is proceeding smoothly.
215  
216 B<FURTHER NOTE> If a domain transfer fails for some reason you will have to submit an entirely new L<transfer_domain> request. There is no way to "restart" a failed transfer.
217  
218 =head2 get_transfer_by_order_id
219  
220 my $in_progress_transfer = WWW::eNom::DomainTransfer->new( ... );
221 my $updated_transfer = $api->get_transfer_by_order_id( $in_progress_transfer->order_id );
222  
223 Abstract of the L<TP_GetOrderDetail|https://www.enom.com/api/API%20topics/api_TP_GetOrderDetail.htm> eNom API Call. Given the order_id of an in progress domain transfer, returns an instance of L<WWW::eNom::DomainTransfer> with the latest available information.
224  
225 Please pay special attention to pass the right order_id (a WWW::eNom::DomainTransfer->order_id is always the right order_id). See L<WWW::eNom::DomainTransfer/order_id> for a discussion on the different types of order_ids.
226  
227 =head2 get_transfer_by_name
228  
229 my $transfers = $api->get_transfer_by_name( 'drzigman.com' );
230  
231 for my $transfer (@{ $transfers }) {
232 print 'Transfer Order ID: ' . $transfer->order_id . "\n";
233 print 'Transfer Status: ' . $transfer->status . "\n";
234 }
235  
236 Abstraction of the L<TP_GetDetailsByDomain|https://www.enom.com/api/API%20topics/api_TP_GetDetailsByDomain.htm> eNom API Call. Usually you want to make use of L<get_transfer_by_order_id> however there are several reasons why you make use of get_transfer_by_name.
237  
238 =over 4
239  
240 =item You don't know the order_id
241  
242 You really should be saving the order_id but if you don't know it you can search by domain name
243  
244 =item You want the fully history of all transfer attempts
245  
246 The ArrayRef of L<WWW::eNom::DomainTransfer> objects returned contains the full history and what happened with each transfer attempt.
247  
248 =back
249  
250 Given a FQDN, returns an ArrayRef of L<WWW::eNom::DomainTransfer> objects representing all of the attempted transfers of the specified FQDN.
251  
252 =head2 get_transfer_order_id_from_parent_order_id
253  
254 my $order_id = $api->get_transfer_order_id_from_parent_order_id( 42 );
255 my $transfer = $api->get_transfer_by_order_id( $order_id );
256  
257 Abstraction of the L<TP_GetOrder|https://www.enom.com/api/API%20topics/api_TP_GetOrder.htm> eNom API Call. If you only have the parent_order_id for a domain transfer and not the actual transfer's order_id, this method will accept that parent_order_id and provide you with the correct order_id (for usage in methods such as get_transfer_by_order_id).
258  
259 For a discussion about the different types of order_ids please see L<WWW::eNom::DomainTransfer/order_id>
260  
261 =cut
« blib/lib/WWW/eNom/DomainTransfer.pm ↑ Summary Build »