File Coverage

blib/lib/WWW/LogicBoxes/Contact.pm
Criterion Covered Total %
statement 27 31 87.1
branch 7 20 35.0
condition n/a
subroutine 8 9 88.8
pod 2 2 100.0
total 44 62 70.9


line stmt bran cond sub pod time code
1             package WWW::LogicBoxes::Contact;
2              
3 47     47   407322 use strict;
  47         121  
  47         1450  
4 47     47   258 use warnings;
  47         113  
  47         1187  
5              
6 47     47   732 use Moose;
  47         141190  
  47         396  
7 47     47   313714 use MooseX::StrictConstructor;
  47         138102  
  47         380  
8 47     47   182445 use namespace::autoclean;
  47         117  
  47         396  
9              
10 47     47   5203 use WWW::LogicBoxes::Types qw(Int Str EmailAddress PhoneNumber ContactType);
  47         123  
  47         364  
11              
12 47     47   498188 use WWW::LogicBoxes::PhoneNumber;
  47         201  
  47         27812  
13              
14             our $VERSION = '1.10.0'; # VERSION
15             # ABSTRACT: LogicBoxes Contact
16              
17             has 'id' => (
18             is => 'ro',
19             isa => Int,
20             required => 0,
21             predicate => 'has_id',
22             writer => '_set_id',
23             );
24              
25             has 'name' => (
26             is => 'ro',
27             isa => Str,
28             required => 1,
29             );
30              
31             has 'company' => (
32             is => 'ro',
33             isa => Str,
34             required => 1,
35             );
36              
37             has 'email' => (
38             is => 'ro',
39             isa => EmailAddress,
40             required => 1,
41             );
42              
43             has 'address1' => (
44             is => 'ro',
45             isa => Str,
46             required => 1,
47             );
48              
49             has 'address2' => (
50             is => 'ro',
51             isa => Str,
52             required => 0,
53             predicate => 'has_address2',
54             );
55              
56             has 'address3' => (
57             is => 'ro',
58             isa => Str,
59             required => 0,
60             predicate => 'has_address3',
61             );
62              
63             has 'city' => (
64             is => 'ro',
65             isa => Str,
66             required => 1,
67             );
68              
69             has 'state' => (
70             is => 'ro',
71             isa => Str,
72             required => 0,
73             predicate => 'has_state',
74             );
75              
76             has 'country' => (
77             is => 'ro',
78             isa => Str,
79             required => 1,
80             );
81              
82             has 'zipcode' => (
83             is => 'ro',
84             isa => Str,
85             required => 1,
86             );
87              
88             has 'phone_number' => (
89             is => 'ro',
90             isa => PhoneNumber,
91             required => 1,
92             coerce => 1,
93             );
94              
95             has 'fax_number' => (
96             is => 'ro',
97             isa => PhoneNumber,
98             required => 0,
99             coerce => 1,
100             predicate => 'has_fax_number',
101             );
102              
103             has 'type' => (
104             is => 'ro',
105             isa => ContactType,
106             required => 0,
107             default => 'Contact',
108             );
109              
110             has 'customer_id' => (
111             is => 'ro',
112             isa => Int,
113             required => 1,
114             );
115              
116             sub construct_creation_request {
117 0     0 1 0 my $self = shift;
118              
119             return {
120 0 0       0 name => $self->name,
    0          
    0          
    0          
121             company => $self->company,
122             email => $self->email,
123              
124             'address-line-1' => $self->address1,
125             ( $self->has_address2 ) ? ( 'address-line-2' => $self->address2 ) : ( ),
126             ( $self->has_address3 ) ? ( 'address-line-3' => $self->address3 ) : ( ),
127             city => $self->city,
128             ( $self->has_state ) ? ( state => $self->state ) : ( ),
129             country => $self->country,
130             zipcode => $self->zipcode,
131              
132             'phone-cc' => $self->phone_number->country_code,
133             phone => $self->phone_number->number,
134             ( $self->has_fax_number )
135             ? ('fax-cc' => $self->fax_number->country_code,
136             fax => $self->fax_number->number,
137             ) : ( ),
138              
139             type => $self->type,
140             'customer-id' => $self->customer_id,
141             };
142             }
143              
144             sub construct_from_response {
145 7     7 1 25 my $self = shift;
146 7         15 my $response = shift;
147              
148 7 50       22 if(!defined $response) {
149 0         0 return;
150             }
151              
152 7 50       50 if( $response->{currentstatus} eq 'Deleted' ) {
153 0         0 return;
154             }
155              
156             my $contact = $self->new({
157             id => $response->{contactid},
158             name => $response->{name},
159             company => $response->{company},
160             email => $response->{emailaddr},
161              
162             address1 => $response->{address1},
163             ( exists $response->{address2} ) ? ( address2 => $response->{address2} ) : ( ),
164             ( exists $response->{address3} ) ? ( address3 => $response->{address3} ) : ( ),
165             city => $response->{city},
166             ( exists $response->{state} ) ? ( state => $response->{state} ) : ( ),
167             country => $response->{country},
168             zipcode => $response->{zip},
169              
170             phone_number => ( $response->{telnocc} . $response->{telno} ),
171             ( exists $response->{faxnocc} )
172             ? ( fax_number => ( $response->{faxnocc} . $response->{faxno} ) )
173             : ( ),
174              
175             type => $response->{type},
176             customer_id => $response->{customerid},
177 7 100       315 });
    50          
    50          
    50          
178              
179 7         82 return $contact;
180             }
181              
182             __PACKAGE__->meta->make_immutable;
183              
184             1;
185              
186             __END__
187             =pod
188              
189             =head1 NAME
190              
191             WWW::LogicBoxes::Contact - Representation of Domain Contact
192              
193             =head1 SYNOPSIS
194              
195             use strict;
196             use warnings;
197              
198             use WWW::LogicBoxes::Customer;
199             use WWW::LogicBoxes::Contact;
200              
201             my $customer = WWW::LogicBoxes::Customer->new( ... ); # Valid LogicBoxes Customer
202              
203             my $contact = WWW::LogicBoxes::Contact->new(
204             id => 42,
205             name => 'Edsger Dijkstra',
206             company => 'University of Texas at Austin',
207             email => 'depth.first@search.com',
208             address1 => 'University of Texas',
209             address2 => '42 Main St',
210             city => 'Austin',
211             state => 'Texas',
212             country => 'US',
213             zipcode => '78713',
214             phone_number => '18005551212',
215             fax_number => '18005551212',
216             type => 'Contact',
217             customer_id => $customer->id,
218             );
219              
220             =head1 DESCRIPTION
221              
222             Representation of a L<LogicBoxes|http://www.logicboxes.com> domain contact.
223              
224             =head1 ATTRIBUTES
225              
226             =head2 id
227              
228             Contacts that have actually been created will have an id assigned for them. A predicate exists 'has_id' that can be used to check to see if an id has been assigned to this contact. A private writer of _set_id is also provided.
229              
230             =head2 B<name>
231              
232             =head2 B<company>
233              
234             Company of the contact. This is a required field so if there is no company some sentinal string of "None" or something similiar should be used.
235              
236             =head2 B<email>
237              
238             =head2 B<address1>
239              
240             =head2 address2
241              
242             Predicate of has_address2.
243              
244             =head2 address3
245              
246             Predicate of has_address3.
247              
248             =head2 B<city>
249              
250             =head2 state
251              
252             This is the full name of the state, so Texas rather than TX should be used. Not all regions in the world have states so this is not a required field, a predicate of has_state exists.
253              
254             =head2 B<country>
255              
256             The ISO-3166 code for the country. For more information on ISO-3166 please see L<Wikipedia|https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2>.
257              
258             =head2 B<zipcode>
259              
260             =head2 B<phone_number>
261              
262             Be sure to include the country code. When it comes to the phone number a string or L<Number::Phone> object can be provided and it will be coerced into the L<WWW::LogicBoxes::PhoneNumber> internal representation used.
263              
264             =head2 fax_number
265              
266             Predicate of has_fax_number
267              
268             =head2 type
269              
270             The type of contact, B<NOT TO BE CONFUSED> with what this contact is being used for on a domain. This B<IS NOT> Registrant, Billing, Admin, or Technical. The default value is 'Contact' and you almost never want to change this.
271              
272             =head2 B<customer_id>
273              
274             The id of the customer that this contact is assoicated with.
275              
276             =head1 METHODS
277              
278             These methods are used internally, it's fairly unlikely that consumers will ever call them directly.
279              
280             =head2 construct_creation_request
281              
282             my $logic_boxes = WWW::LogicBoxes->new( ... );
283             my $contact = WWW::LogicBoxes::Contact->new( ... );
284              
285             my $response = $logic_boxes->submit({
286             method => 'contacts__add',
287             params => $contact->construct_creation_request(),
288             });
289              
290             Converts $self into a HashRef suitable for creation of a contact with L<LogicBoxes|http://www.logicboxes.com>
291              
292             =head2 construct_from_response
293              
294             my $logic_boxes = WWW::LogicBoxes->new( ... );
295              
296             my $response = $logic_boxes->submit({
297             method => 'contacts__details',
298             params => {
299             'contact-id' => 42,
300             }
301             });
302              
303             my $contact = WWW::LogicBoxes::Contact->construct_from_response( $response );
304              
305             Creates an instance of $self from a L<LogicBoxes|http://www.logicboxes.com> response.
306              
307             =head1 SEE ALSO
308              
309             For .us domains L<WWW::LogicBoxes::Contact::US> must be used for at least the registrant contact.
310              
311             =cut