« blib/lib/WWW/LogicBoxes/Contact.pm
↑ Summary
blib/lib/WWW/LogicBoxes/Role/Command/Domain/PrivateNameServer.pm »
| 1 | package WWW::LogicBoxes::Role::Command::Customer; | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | 36 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 36 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||
| 6 | 36 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | 36 | ▶ | use MooseX::Params::Validate; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||
| 9 | 36 | ▶ | use WWW::LogicBoxes::Types qw( Customer EmailAddress Int Password ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||
| 11 | 36 | ▶ | use WWW::LogicBoxes::Customer; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||
| 13 | 36 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 14 | 36 | ▶ | use Carp; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||
| 16 | 36 | requires 'submit'; | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||
| 18 | 36 | our $VERSION = '1.1.0'; # VERSION | |||||||||||||||||||||||||||||
| 19 | # ABSTRACT: Customer API Calls | ||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||
| 21 | sub create_customer { | ||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
create_customer: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||
| 23 | 0 | my ( %args ) = validated_hash( | |||||||||||||||||||||||||||||
| 24 | \@_, | ||||||||||||||||||||||||||||||
| 25 | customer => { isa => Customer, coerce => 1 }, | ||||||||||||||||||||||||||||||
| 26 | password => { isa => Password }, | ||||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | if( $args{customer}->has_id ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 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 | ▶ | }); | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 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 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
get_customer_by_id: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 76 | 0 | my ( $customer_id ) = pos_validated_list( \@_, { isa => Int } ); | |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||
| 78 | return try { | ||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | my $response = $self->submit({ | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 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 | ▶ | if( $_ =~ m/^Invalid customer-id/ ) { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 90 | 0 | return; | |||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||
| 93 | 0 | croak $_; | |||||||||||||||||||||||||||||
| 94 | 0 | }; | |||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||
| 97 | sub get_customer_by_username { | ||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
get_customer_by_username: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 99 | 0 | my ( $username ) = pos_validated_list( \@_, { isa => EmailAddress } ); | |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||
| 101 | return try { | ||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | my $response = $self->submit({ | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 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 | ▶ | if( $_ =~ m/Customer [^\s]* not found/ ) { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 113 | 0 | return; | |||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||
| 116 | 0 | croak $_; | |||||||||||||||||||||||||||||
| 117 | 0 | }; | |||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||
| 120 | 36 | 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 | ||||||||||||||||||||||||||||||