File Coverage

blib/lib/WWW/LogicBoxes/Domain.pm
Criterion Covered Total %
statement 33 57 57.8
branch 0 18 0.0
condition 0 5 0.0
subroutine 11 13 84.6
pod 1 2 50.0
total 45 95 47.3


line stmt bran cond sub pod time code
1             package WWW::LogicBoxes::Domain;
2              
3 39     39   355298 use strict;
  39         133  
  39         1124  
4 39     39   203 use warnings;
  39         92  
  39         884  
5              
6 39     39   690 use Moose;
  39         145527  
  39         309  
7 39     39   259396 use MooseX::StrictConstructor;
  39         40375  
  39         379  
8 39     39   132334 use namespace::autoclean;
  39         101  
  39         407  
9              
10 39         346 use WWW::LogicBoxes::Types qw(
11             Bool DateTime DomainName DomainNames DomainStatus Int IRTPDetail PrivateNameServers Str VerificationStatus
12 39     39   5003 );
  39         94  
13              
14 39     39   457485 use WWW::LogicBoxes::IRTPDetail;
  39         174  
  39         1881  
15 39     39   24173 use WWW::LogicBoxes::PrivateNameServer;
  39         179  
  39         1739  
16              
17 39     39   358 use DateTime;
  39         92  
  39         872  
18 39     39   213 use Carp;
  39         91  
  39         2999  
19 39     39   37829 use Mozilla::PublicSuffix qw( public_suffix );
  39         873160  
  39         28155  
20              
21             our $VERSION = '1.10.1'; # VERSION
22             # ABSTRACT: LogicBoxes Domain Representation
23              
24             has id => (
25             is => 'ro',
26             isa => Int,
27             required => 1,
28             );
29              
30             has name => (
31             is => 'ro',
32             isa => DomainName,
33             required => 1,
34             );
35              
36             has customer_id => (
37             is => 'ro',
38             isa => Int,
39             required => 1,
40             );
41              
42             has status => (
43             is => 'ro',
44             isa => DomainStatus,
45             required => 1,
46             );
47              
48             has verification_status => (
49             is => 'ro',
50             isa => VerificationStatus,
51             required => 1,
52             );
53              
54             has is_locked => (
55             is => 'ro',
56             isa => Bool,
57             required => 1,
58             );
59              
60             has is_private => (
61             is => 'ro',
62             isa => Bool,
63             required => 1,
64             );
65              
66             has created_date => (
67             is => 'ro',
68             isa => DateTime,
69             required => 1,
70             );
71              
72             has expiration_date => (
73             is => 'ro',
74             isa => DateTime,
75             required => 1,
76             );
77              
78             has ns => (
79             is => 'ro',
80             isa => DomainNames,
81             required => 1,
82             );
83              
84             has registrant_contact_id => (
85             is => 'ro',
86             isa => Int,
87             required => 1,
88             );
89              
90             has admin_contact_id => (
91             is => 'ro',
92             isa => Int,
93             required => 1,
94             );
95              
96             has technical_contact_id => (
97             is => 'ro',
98             isa => Int,
99             required => 1,
100             );
101              
102             has billing_contact_id => (
103             is => 'ro',
104             isa => Int,
105             required => 0,
106             predicate => 'has_billing_contact_id',
107             );
108              
109             has epp_key => (
110             is => 'ro',
111             isa => Str,
112             required => 1,
113             );
114              
115             has private_nameservers => (
116             is => 'ro',
117             isa => PrivateNameServers,
118             required => 0,
119             predicate => 'has_private_nameservers',
120             );
121              
122             has irtp_detail => (
123             is => 'ro',
124             isa => IRTPDetail,
125             predicate => 'has_irtp_detail',
126             );
127              
128             sub BUILD {
129 0     0 0   my $self = shift;
130              
131 0           my $tld = public_suffix( $self->name );
132              
133 0 0         if( $tld eq 'ca' ) {
    0          
134 0 0         if( $self->has_billing_contact_id ) {
135 0           croak 'CA domains do not have a billing contact';
136             }
137             }
138             elsif( !$self->has_billing_contact_id ) {
139 0           croak 'A billing_contact_id is required';
140             }
141              
142 0           return $self;
143             }
144              
145             sub construct_from_response {
146 0     0 1   my $self = shift;
147 0           my $response = shift;
148              
149 0 0         if( !$response ) {
150 0           return;
151             }
152              
153 0           my @private_nameservers;
154 0           for my $private_nameserver_name ( keys %{ $response->{cns} } ) {
  0            
155             push @private_nameservers, WWW::LogicBoxes::PrivateNameServer->new(
156             domain_id => $response->{orderid},
157             name => $private_nameserver_name,
158 0           ips => $response->{cns}{$private_nameserver_name},
159             );
160             }
161              
162 0           my $irtp_detail;
163 0 0         if( exists $response->{irtp_status} ) {
164 0           $irtp_detail = WWW::LogicBoxes::IRTPDetail->construct_from_response( $response->{irtp_status} );
165             }
166              
167             return $self->new(
168             id => $response->{orderid},
169             name => $response->{domainname},
170             customer_id => $response->{customerid},
171             status => $response->{currentstatus},
172             verification_status => $response->{raaVerificationStatus} // 'NA',
173 0 0         is_locked => !!( grep { $_ && $_ eq 'transferlock' } @{ $response->{orderstatus} } ),
  0            
174             is_private => $response->{isprivacyprotected} && $response->{isprivacyprotected} eq 'true',
175             created_date => DateTime->from_epoch( epoch => $response->{creationtime}, time_zone => 'UTC' ),
176             expiration_date => DateTime->from_epoch( epoch => $response->{endtime}, time_zone => 'UTC' ),
177 0           ns => [ map { $response->{ $_ } } sort ( grep { $_ =~ m/^ns/ } keys %{ $response } ) ],
  0            
  0            
178             epp_key => $response->{domsecret},
179             scalar @private_nameservers ? ( private_nameservers => \@private_nameservers ) : ( ),
180             registrant_contact_id => $response->{registrantcontact}{contactid},
181             admin_contact_id => $response->{admincontact}{contactid},
182             technical_contact_id => $response->{techcontact}{contactid},
183 0 0 0       $response->{billingcontact} ? ( billing_contact_id => $response->{billingcontact}{contactid} ) : ( ),
    0 0        
    0          
184             $irtp_detail ? ( irtp_detail => $irtp_detail ) : ( ),
185             );
186             }
187              
188             __PACKAGE__->meta->make_immutable;
189             1;
190              
191             __END__
192             =pod
193              
194             =head1 NAME
195              
196             WWW::LogicBoxes::Domain - Representation of Registered LogicBoxes Domain
197              
198             =head1 SYNOPSIS
199              
200             use WWW::LogicBoxes;
201              
202             my $logic_boxes = WWW::LogicBoxes->new( ... );
203              
204             my $domain = $logic_boxes->get_domain_by_name( 'test-domain.com' );
205              
206             print 'ID For domain test-domain.com is ' . $domain->id . "\n";
207              
208             =head1 DESCRIPTION
209              
210             Represents L<LogicBoxes|http://www.logicboxes.com> domains, containing all related information. For most operations this will be the base object that is used to represent the data.
211              
212             =head1 ATTRIBUTES
213              
214             =head2 B<id>
215              
216             The order_id of the domain in L<LogicBoxes|http://www.logicboxes.com>'s system.
217              
218             =head2 B<name>
219              
220             The full domain name ( test-domain.com ).
221              
222             =head2 B<customer_id>
223              
224             The id of the L<customer|WWW::LogicBoxes::Customer> who owns this domain in L<LogicBoxes|http://www.logicboxes.com>.
225              
226             =head2 B<status>
227              
228             Current status of the domain with L<LogicBoxes|http://www.logicboxes.com>. Will be one of the following values:
229              
230             =over 4
231              
232             =item InActive
233              
234             =item Active
235              
236             =item Suspended
237              
238             =item Pending Delete Restorable
239              
240             =item QueuedForDeletion
241              
242             =item Deleted
243              
244             =item Archived
245              
246             =back
247              
248             =head2 B<verification_status>
249              
250             According to ICANN rules, all new gTLD domains that were registered after January 1st, 2014 must be verified. verification_status describes the current state of this verification and will be one of the following values:
251              
252             =over 4
253              
254             =item Verified
255              
256             =item Pending
257              
258             =item Suspended
259              
260             =back
261              
262             For details on the ICANN policy please see the riveting ICANN Registrar Agreement L<https://www.icann.org/resources/pages/approved-with-specs-2013-09-17-en>.
263              
264             =head2 B<is_locked>
265              
266             Boolean indicating if the domain is currently locked, preventing transfer.
267              
268             =head2 B<is_private>
269              
270             Boolean indicating if this domain uses WHOIS Privacy.
271              
272             =head2 B<created_date>
273              
274             Date this domain registration was created.
275              
276             =head2 B<expiration_date>
277              
278             Date this domain registration expires.
279              
280             =head2 B<ns>
281              
282             ArrayRef of Domain Names that are the authorizative nameservers for this domain.
283              
284             =head2 B<registrant_contact_id>
285              
286             A L<Contact|WWW::LogicBoxes::Contact> id for the Registrant.
287              
288             =head2 B<admin_contact_id>
289              
290             A L<Contact|WWW::LogicBoxes::Contact> id for the Admin.
291              
292             =head2 B<technical_contact_id>
293              
294             A L<Contact|WWW::LogicBoxes::Contact> id for the Technical.
295              
296             =head2 billing_contact_id
297              
298             A L<Contact|WWW::LogicBoxes::Contact> id for the Billing. Offers a predicate of has_billing_contact_id.
299              
300             Almost all TLDs require a billing contact, however for .ca domains it B<must not> be provided.
301              
302             =head2 B<epp_key>
303              
304             The secret key needed in order to transfer a domain to another registrar.
305              
306             =head2 private_nameserves
307              
308             ArrayRef of L<WWW::LogicBoxes::PrivateNameServer> objects that contains any created private name servers. Predicate of has_private_nameservers.
309              
310             =head2 irtp_detail
311              
312             If an IRTP Verification is in process for this domain, this attribute will contain a fully formed L<WWW::LogicBoxes::IRTPDetail> object. If there is no pending IRTP Verification this attribute will not be set. A predicate of has_irtp_detail is provided.
313              
314             =head1 METHODS
315              
316             These methods are used internally, it's fairly unlikely that consumers will ever call them directly.
317              
318             =head2 construct_from_response
319              
320             my $logic_boxes = WWW::LogicBoxes->new( ... );
321              
322             my $response = $logic_boxes->submit({
323             method => 'domains__details_by_name',
324             params => {
325             'domain-name' => 'test-domain.com',
326             'options' => [qw( All )],
327             },
328             });
329              
330             my $domain = WWW::LogicBoxes::Domain->construct_from_response( $response );
331              
332             Constructs an instance of $self from a L<LogicBoxes|http://www.logicboxes.com> response.
333              
334             =cut