File Coverage

blib/lib/WebService/SmartyStreets.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 20 20 100.0


line stmt bran cond sub pod time code
1             package WebService::SmartyStreets;
2             $WebService::SmartyStreets::VERSION = '0.0102';
3 2     2   97660 use Moo;
  2         35915  
  2         1169  
4             with 'WebService::BaseClientRole';
5              
6             # VERSION
7              
8 2     2   5887 use aliased 'WebService::SmartyStreets::Exception::AddressNotFound';
  2         1527  
  2         26  
9 2     2   206 use aliased 'WebService::SmartyStreets::Exception::AddressMissingInformation';
  2         4  
  2         15  
10              
11 2     2   12197 use Function::Parameters ':strict';
  2         7578  
  2         15  
12 2     2   3166 use URI;
  2         10148  
  2         25640  
13              
14             has auth_id => ( is => 'ro', required => 1 );
15             has auth_token => ( is => 'ro', required => 1 );
16              
17             has '+base_url' => (
18             default => sub {
19             my $self = shift;
20             my $uri = URI->new('https://api.smartystreets.com/street-address');
21             $uri->query_form(
22             'auth-id' => $self->auth_id,
23             'auth-token' => $self->auth_token,
24             );
25             return $uri->as_string;
26             },
27             );
28              
29             method verify_address(
30             Str :$street,
31             Str :$street2 = '',
32             Str :$city,
33             Str :$state,
34             Str :$zipcode = '',
35             Int :$candidates = 2
36             ) {
37             my $results = $self->post($self->base_url, [{
38             street => $street,
39             street2 => $street2,
40             city => $city,
41             state => $state,
42             zipcode => $zipcode,
43             candidates => $candidates,
44             }]);
45              
46             AddressNotFound->throw unless $results and @$results;
47             AddressMissingInformation->throw if @$results == 1
48             and $results->[0]{analysis}{dpv_match_code} eq 'D';
49              
50             return [
51             map {{
52             street => $_->{delivery_line_1},
53             (street2 => $_->{delivery_line_2}) x!! $_->{delivery_line_2},
54             city => $_->{components}{city_name},
55             state => $_->{components}{state_abbreviation},
56             zipcode => $_->{components}{zipcode} . '-' . $_->{components}{plus4_code},
57             }} @$results
58             ];
59             }
60              
61              
62             1;
63              
64             __END__