blib/lib/WWW/LogicBoxes/Role/Command/Contact.pm

filter: Statementstmt 41.5% 27 / 65 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 44.4% 8 / 18 Podpod 100% 4 / 4 totaltotal 35.7% 39 / 109 CC 9 SCAR 17.5
CC
9
Cov
33%
__ANON__
12.0
__ANON__
12.0
__ANON__
12.0
CRAP 5.8
« blib/lib/WWW/LogicBoxes/Role/Command/Domain/Transfer.pm ↑ Summary blib/lib/WWW/LogicBoxes/DomainRequest/Transfer.pm »
1 package WWW::LogicBoxes::Role::Command::Contact;
2  
3 37 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 37 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 37 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 37 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 37 ▶use WWW::LogicBoxes::Types qw( Contact Int );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 37 ▶use WWW::LogicBoxes::Contact;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 37 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 37 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 37 requires 'submit';
17  
18 37 our $VERSION = '1.2.0'; # VERSION
19 # ABSTRACT: Contact API Calls
20  
21 sub create_contact {
22 0 ▶ my $self = shift;
Subroutine create_contact: not called CC=2 SCAR=17.9
Pod documented
23 0 my (%args) = validated_hash(
24 \@_,
25 contact => { isa => Contact, coerce => 1 },
26 );
27  
28 0 ▶ if( $args{contact}->has_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"contact"}->has_id) 0 0 0
29 0 croak "Contact already exists (it has an id)";
30 }
31  
32 my $response = $self->submit({
33 method => 'contacts__add',
34 0 params => $args{contact}->construct_creation_request(),
35 });
36  
37 0 $args{contact}->_set_id($response->{id});
38  
39 0 return $args{contact};
40 }
41  
42 sub get_contact_by_id {
43 0 ▶ my $self = shift;
Subroutine get_contact_by_id: not called CC=1 SCAR=6.9
Pod documented
44 0 my ( $id ) = pos_validated_list( \@_, { isa => Int } );
45  
46 return try {
47 0 ▶ my $response = $self->submit({
Subroutine __ANON__: not called CC=3 SCAR=24.8
48 method => 'contacts__details',
49 params => {
50 'contact-id' => $id,
51 },
52 });
53  
54 # TODO: Abstract this into a Factory that can contain multiple sets of attributes
55 # Because we only have normal and .us right now this works for now.
56 0 ▶ if( scalar @{ $response->{contacttype} } == 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @{$response->{'contacttype'};} == 0) { } 0 0 0
elsif (grep {$_ eq 'domus';} @{$$response{'contacttype'};}) { } 0 0 0
57 0 return WWW::LogicBoxes::Contact->construct_from_response($response);
58 }
59 0 elsif( grep { $_ eq 'domus' } @{ $response->{contacttype} } ) {
60 0 return WWW::LogicBoxes::Contact::US->construct_from_response($response);
61 }
62 else {
63 0 croak 'Unknown contact type';
64 }
65 }
66 catch {
67 0 ▶ if( $_ =~ m/^Invalid contact-id/ || $_ =~ m/^No Entity found/ ) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^Invalid contact-id/ or $_ =~ /^No Entity found/) 0 0 0
Condition0%0/3
$_ =~ /^Invalid contact-id/ or $_ =~ /^No Entity found/
l!l&&r!l&&!r
000
MC/DC0%0/2
$_ =~ /^Invalid contact-id/ or $_ =~ /^No Entity found/
$_ =~ /^Invalid contact-id/ $_ =~ /^No Entity found/
Truth table0%0/3
A or B
A= $_ =~ /^Invalid contact-id/B= $_ =~ /^No Entity found/
ABresult
1X1
011
000
68 0 return;
69 }
70  
71 0 croak $_;
72 0 };
73 }
74  
75 sub update_contact {
76 0 ▶ my $self = shift;
Subroutine update_contact: not called CC=2 SCAR=17.9
Pod documented
77 0 my (%args) = validated_hash(
78 \@_,
79 contact => { isa => Contact, coerce => 1 },
80 );
81  
82 0 ▶ if( !$args{contact}->has_id ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"contact"}->has_id) 0 0 0
83 0 croak "Contact does not exist (it lacks an id)";
84 }
85  
86 return try {
87 $self->submit({
88 method => 'contacts__modify',
89 params => {
90 'contact-id' => $args{contact}->id,
91 0 ▶ %{ $args{contact}->construct_creation_request() },
Subroutine __ANON__: not called CC=1 SCAR=6.9
92 }
93 });
94  
95 0 return $self->get_contact_by_id( $args{contact}->id );
96 }
97 catch {
98 0 ▶ if( $_ =~ m/^Invalid contact-id/ || $_ =~ m/^No Entity found/ ) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^Invalid contact-id/ or $_ =~ /^No Entity found/) 0 0 0
Condition0%0/3
$_ =~ /^Invalid contact-id/ or $_ =~ /^No Entity found/
l!l&&r!l&&!r
000
MC/DC0%0/2
$_ =~ /^Invalid contact-id/ or $_ =~ /^No Entity found/
$_ =~ /^Invalid contact-id/ $_ =~ /^No Entity found/
Truth table0%0/3
A or B
A= $_ =~ /^Invalid contact-id/B= $_ =~ /^No Entity found/
ABresult
1X1
011
000
99 0 croak 'Invalid Contact ID';
100 }
101  
102 0 croak $_;
103 0 };
104 }
105  
106 sub delete_contact_by_id {
107 0 ▶ my $self = shift;
Subroutine delete_contact_by_id: not called CC=1 SCAR=6.9
Pod documented
108 0 my ( $id ) = pos_validated_list( \@_, { isa => Int } );
109  
110 return try {
111 0 ▶ $self->submit({
Subroutine __ANON__: not called CC=1 SCAR=6.9
112 method => 'contacts__delete',
113 params => {
114 'contact-id' => $id,
115 },
116 });
117  
118 0 return;
119 }
120 catch {
121 0 ▶ croak $_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
122 0 };
123 }
124  
125 37 1;
126  
127 __END__
128 =pod
129  
130 =head1 NAME
131  
132 WWW::LogicBoxes::Role::Command::Contact - Contact Related Operations
133  
134 =head1 SYNOPSIS
135  
136 use WWW::LogicBoxes;
137 use WWW::LogicBoxes::Customer;
138 use WWW::LogicBoxes::Contact;
139  
140 my $customer = WWW::LogicBoxes::Customer->new( ... );
141 my $contact = WWW::LogicBoxes::Contact->new( ... );
142  
143 # Creation
144 my $logic_boxes = WWW::LogicBoxes->new( ... );
145 $logic_boxes->create_contact( contact => $contact );
146  
147 # Retrieval
148 my $retrieved_contact = $logic_boxes->get_contact_by_id( $contact->id );
149  
150 # Update
151 my $old_contact = $logic_boxes->get_contact_by_id( 42 );
152 my $contact = WWW::LogicBoxes::Contact->new(
153 id => $old_contact->id,
154 ...
155 );
156  
157 $logic_boxes->update_contact( contact => $contact );
158  
159 # Deletion
160 $logic_boxes->delete_contact_by_id( $contact->id );
161  
162 =head1 REQURIES
163  
164 submit
165  
166 =head1 DESCRIPTION
167  
168 Implements contact related operations with the L<LogicBoxes's|http://www.logicboxes.com> API.
169  
170 =head1 METHODS
171  
172 =head2 create_contact
173  
174 use WWW::LogicBoxes;
175 use WWW::LogicBoxes::Customer;
176 use WWW::LogicBoxes::Contact;
177  
178 my $customer = WWW::LogicBoxes::Customer->new( ... );
179 my $contact = WWW::LogicBoxes::Contact->new( ... );
180  
181 my $logic_boxes = WWW::LogicBoxes->new( ... );
182 $logic_boxes->create_contact( contact => $contact );
183  
184 print 'New contact id: ' . $contact->id . "\n";
185  
186 Given a L<WWW::LogicBoxes::Contact> or a HashRef that can be coerced into a L<WWW::LogicBoxes::Contact>, creates the specified contact with LogicBoxes.
187  
188 =head2 get_contact_by_id
189  
190 use WWW::LogicBoxes;
191 use WWW::LogicBoxes::Contact;
192  
193 my $logic_boxes = WWW::LogicBoxes->new( ... );
194 my $contact = $logic_boxes->get_contact_by_id( 42 );
195  
196 Given an Integer ID, will return an instance of L<WWW::LogicBoxes::Contact> (or one of it's subclass for specialized contacts). Returns undef if there is no matching L<contact|WWW::LogicBoxes::Contact> with the specified id.
197  
198 =head2 update_contact
199  
200 use WWW::LogicBoxes;
201 use WWW::LogicBoxes::Customer;
202 use WWW::LogicBoxes::Contact;
203  
204 my $logic_boxes = WWW::LogicBoxes->new( ... );
205  
206 my $old_contact = $logic_boxes->get_contact_by_id( 42 );
207 my $contact = WWW::LogicBoxes::Contact->new(
208 id => $old_contact->id,
209 ...
210 );
211  
212 $logic_boxes->update_contact( contact => $contact );
213  
214 Given a L<WWW::LogicBoxes::Contact> or a HashRef that can be coerced into a L<WWW::LogicBoxes::Contact>, updates the contact with the specified id with L<LogicBoxes|http://www.logicboxes.com>.
215  
216 =head2 delete_contact_by_id
217  
218 use WWW::LogicBoxes;
219 use WWW::LogicBoxes::Contact;
220  
221 my $logic_boxes = WWW::LogicBoxes->new( ... );
222 $logic_boxes->delete_contact_by_id( 42 );
223  
224 Given an Integer ID, will delete the L<contact|WWW::LogicBoxes::Contact> with L<LogicBoxes|http://www.logicboxes.com>.
225  
226 This method will croak if the contact is in use (assigned to a domain).
227  
228 =cut
229  
« blib/lib/WWW/LogicBoxes/Role/Command/Domain/Transfer.pm ↑ Summary blib/lib/WWW/LogicBoxes/DomainRequest/Transfer.pm »