line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::LogicBoxes::Role::Command::Customer; |
2
|
|
|
|
|
|
|
|
3
|
38
|
|
|
38
|
|
379605
|
use strict; |
|
38
|
|
|
|
|
105
|
|
|
38
|
|
|
|
|
1333
|
|
4
|
38
|
|
|
38
|
|
214
|
use warnings; |
|
38
|
|
|
|
|
86
|
|
|
38
|
|
|
|
|
1246
|
|
5
|
|
|
|
|
|
|
|
6
|
38
|
|
|
38
|
|
568
|
use Moose::Role; |
|
38
|
|
|
|
|
147333
|
|
|
38
|
|
|
|
|
347
|
|
7
|
38
|
|
|
38
|
|
227150
|
use MooseX::Params::Validate; |
|
38
|
|
|
|
|
70279
|
|
|
38
|
|
|
|
|
354
|
|
8
|
|
|
|
|
|
|
|
9
|
38
|
|
|
38
|
|
19960
|
use WWW::LogicBoxes::Types qw( Customer EmailAddress Int Password ); |
|
38
|
|
|
|
|
98
|
|
|
38
|
|
|
|
|
381
|
|
10
|
|
|
|
|
|
|
|
11
|
38
|
|
|
38
|
|
409339
|
use WWW::LogicBoxes::Customer; |
|
38
|
|
|
|
|
185
|
|
|
38
|
|
|
|
|
1812
|
|
12
|
|
|
|
|
|
|
|
13
|
38
|
|
|
38
|
|
360
|
use Try::Tiny; |
|
38
|
|
|
|
|
88
|
|
|
38
|
|
|
|
|
2775
|
|
14
|
38
|
|
|
38
|
|
277
|
use Carp; |
|
38
|
|
|
|
|
86
|
|
|
38
|
|
|
|
|
23236
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
requires 'submit'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '1.10.1'; # VERSION |
19
|
|
|
|
|
|
|
# ABSTRACT: Customer API Calls |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub create_customer { |
22
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
23
|
0
|
|
|
|
|
|
my ( %args ) = validated_hash( |
24
|
|
|
|
|
|
|
\@_, |
25
|
|
|
|
|
|
|
customer => { isa => Customer, coerce => 1 }, |
26
|
|
|
|
|
|
|
password => { isa => Password }, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
0
|
0
|
|
|
|
|
if( $args{customer}->has_id ) { |
30
|
0
|
|
|
|
|
|
croak "Customer already exists (it has an id)"; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $response = $self->submit({ |
34
|
|
|
|
|
|
|
method => 'customers__signup', |
35
|
|
|
|
|
|
|
params => { |
36
|
|
|
|
|
|
|
username => $args{customer}->username, |
37
|
|
|
|
|
|
|
passwd => $args{password}, |
38
|
|
|
|
|
|
|
name => $args{customer}->name, |
39
|
|
|
|
|
|
|
company => $args{customer}->company, |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
'address-line-1' => $args{customer}->address1, |
42
|
|
|
|
|
|
|
( $args{customer}->has_address2 ) ? ( 'address-line-2' => $args{customer}->address2 ) : ( ), |
43
|
|
|
|
|
|
|
( $args{customer}->has_address3 ) ? ( 'address-line-3' => $args{customer}->address3 ) : ( ), |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
city => $args{customer}->city, |
46
|
|
|
|
|
|
|
( $args{customer}->has_state ) ? ( state => $args{customer}->state ) : ( state => 'Not Applicable', 'other-state' => ''), |
47
|
|
|
|
|
|
|
country => $args{customer}->country, |
48
|
|
|
|
|
|
|
zipcode => $args{customer}->zipcode, |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
'phone-cc' => $args{customer}->phone_number->country_code, |
51
|
|
|
|
|
|
|
'phone' => $args{customer}->phone_number->number, |
52
|
|
|
|
|
|
|
($args{customer}->has_fax_number) ? |
53
|
|
|
|
|
|
|
( 'fax-cc' => $args{customer}->fax_number->country_code, |
54
|
|
|
|
|
|
|
'fax' => $args{customer}->fax_number->number, |
55
|
|
|
|
|
|
|
) : (), |
56
|
|
|
|
|
|
|
($args{customer}->has_alt_phone_number) ? |
57
|
|
|
|
|
|
|
( 'alt-phone-cc' => $args{customer}->alt_phone_number->country_code, |
58
|
|
|
|
|
|
|
'alt-phone' => $args{customer}->alt_phone_number->number, |
59
|
|
|
|
|
|
|
) : (), |
60
|
|
|
|
|
|
|
($args{customer}->has_mobile_phone_number) ? |
61
|
|
|
|
|
|
|
( 'mobile-cc' => $args{customer}->mobile_phone_number->country_code, |
62
|
|
|
|
|
|
|
'mobile' => $args{customer}->mobile_phone_number->number, |
63
|
|
|
|
|
|
|
) : (), |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
'lang-pref' => $args{customer}->language_preference, |
66
|
|
|
|
|
|
|
}, |
67
|
0
|
0
|
|
|
|
|
}); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$args{customer}->_set_id( $response->{id} ); |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
return $args{customer}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub get_customer_by_id { |
75
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
76
|
0
|
|
|
|
|
|
my ( $customer_id ) = pos_validated_list( \@_, { isa => Int } ); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
return try { |
79
|
0
|
|
|
0
|
|
|
my $response = $self->submit({ |
80
|
|
|
|
|
|
|
method => 'customers__details_by_id', |
81
|
|
|
|
|
|
|
params => { |
82
|
|
|
|
|
|
|
'customer-id' => $customer_id, |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
}); |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
return WWW::LogicBoxes::Customer->construct_from_response( $response ); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
catch { |
89
|
0
|
0
|
|
0
|
|
|
if( $_ =~ m/^Invalid customer-id/ ) { |
90
|
0
|
|
|
|
|
|
return; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
croak $_; |
94
|
0
|
|
|
|
|
|
}; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub get_customer_by_username { |
98
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
99
|
0
|
|
|
|
|
|
my ( $username ) = pos_validated_list( \@_, { isa => EmailAddress } ); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
return try { |
102
|
0
|
|
|
0
|
|
|
my $response = $self->submit({ |
103
|
|
|
|
|
|
|
method => 'customers__details', |
104
|
|
|
|
|
|
|
params => { |
105
|
|
|
|
|
|
|
'username' => $username, |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
}); |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
return WWW::LogicBoxes::Customer->construct_from_response( $response ); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
catch { |
112
|
0
|
0
|
|
0
|
|
|
if( $_ =~ m/Customer [^\s]* not found/ ) { |
113
|
0
|
|
|
|
|
|
return; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
croak $_; |
117
|
0
|
|
|
|
|
|
}; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
__END__ |
123
|
|
|
|
|
|
|
=pod |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 NAME |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
WWW::LogicBoxes::Role::Command::Customer - Customer Related Operations |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 SYNPOSIS |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
use WWW::LogicBoxes; |
132
|
|
|
|
|
|
|
use WWW::LogicBoxes::Customer; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
my $logic_boxes = WWW::LogicBoxes->new( ... ); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# Creation |
137
|
|
|
|
|
|
|
my $customer = WWW::LogicBoxes->new( ... ); |
138
|
|
|
|
|
|
|
$logic_boxes->create_customer( |
139
|
|
|
|
|
|
|
customer => $customer, |
140
|
|
|
|
|
|
|
password => 'Top Secret!', |
141
|
|
|
|
|
|
|
); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# Retrieval |
144
|
|
|
|
|
|
|
my $retrieved_customer = $logic_boxes->get_customer_by_id( $customer->id ); |
145
|
|
|
|
|
|
|
my $retrieved_customer = $logic_boxes->get_customer_by_username( $customer->username ); # An email address |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 REQUIRES |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
submit |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 DESCRIPTION |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Implements customer related operations with the L<LogicBoxes's|http://www.logicboxes.com> API. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 METHODS |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 create_customer |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
use WWW::LogicBoxes; |
160
|
|
|
|
|
|
|
use WWW::LogicBoxes::Customer; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
my $logic_boxes = WWW::LogicBoxes->new( ... ); |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
my $customer = WWW::LogicBoxes->new( ... ); |
165
|
|
|
|
|
|
|
$logic_boxes->create_customer( |
166
|
|
|
|
|
|
|
customer => $customer, |
167
|
|
|
|
|
|
|
password => 'Top Secret!', |
168
|
|
|
|
|
|
|
); |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
print 'New customer id: ' . $customer->id . "\n"; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Given a L<WWW::LogicBoxes::Customer> or a HashRef that can coerced into a L<WWW::LogicBoxes::Customer> and a password, creates the specified customer. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head2 get_customer_by_id |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
use WWW::LogicBoxes; |
177
|
|
|
|
|
|
|
use WWW::LogicBoxes::Customer; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
my $logic_boxes = WWW::LogicBoxes->new( ... ); |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
my $retrieved_customer = $logic_boxes->get_customer_by_id( 42 ); |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Given an Integer ID, will return an instace of L<WWW::LogicBoxes::Customer>. Returns undef if there is no matching L<WWW::LogicBoxes::Customer> with the specified id. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head2 get_customer_by_username |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
use WWW::LogicBoxes; |
188
|
|
|
|
|
|
|
use WWW::LogicBoxes::Customer; |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
my $logic_boxes = WWW::LogicBoxes->new( ... ); |
191
|
|
|
|
|
|
|
my $retrieved_customer = $logic_boxes->get_customer_by_username( |
192
|
|
|
|
|
|
|
'domainbuyer@test-domain.com' |
193
|
|
|
|
|
|
|
); |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Given an Email Address of a customer, will return an instance of L<WWW::LogicBoxes::Customer>. Returns undef if there is no matching L<WWW::LogicBoxes::Customer> with the specified email address. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=cut |