Business-US-USPS-WebTools-1.11/0000755000076500007650000000000010712777041016330 5ustar brianbrian00000000000000Business-US-USPS-WebTools-1.11/Changes0000644000076500007650000000160010712777035017623 0ustar brianbrian000000000000000.10 - Sat Sep 16 03:42:40 2006 * This is the initial release of a group of modules which implement the web services of the US Postal Service. This isn't screen scraping! * See http://www.usps.com/webtools/ 1.11 - Sat Nov 3 00:49:12 2007 * cleanups to move from CVS to SVN * now requires perl 5.6 * cleanups to the disto; no need to upgrade if you already have this 0.00 - Thu Oct 25 22:04:42 2007 * distro adjustments. no big whoop. 1.09 - Mon Feb 5 18:16:12 2007 * Jay Buffington noted I wasn't escaping the query strings correctly (meaning, at all), so I fixed that. * This is an important fix that everyone should upgrade too. 1.06 - Wed Jan 10 00:13:28 2007 * First official release :) 0.10 - Tue Sep 26 16:21:58 2006 * Changed namespace to Business::US::USPS::* * More docs to point out you need the USPS UserID to use any of this * See http://www.usps.com/webtools/ Business-US-USPS-WebTools-1.11/examples/0000755000076500007650000000000010712777041020146 5ustar brianbrian00000000000000Business-US-USPS-WebTools-1.11/examples/address_standardization.pl0000644000076500007650000000172610562747350025417 0ustar brianbrian00000000000000#!/usr/bin/perl use Business::US::USPS::WebTools::AddressStandardization; my $verifier = Business::US::USPS::WebTools::AddressStandardization->new( { UserID => $ENV{USPS_WEBTOOLS_USERID}, Password => $ENV{USPS_WEBTOOLS_PASSWORD}, # Testing => 1, } ); my $address1 = prompt( "Address1" ); my $address2 = prompt( "Address2" ); my $city = prompt( "City" ); my $state = prompt( "State" ); my $zip5 = prompt( "Zip Code" ); my $hash = $verifier->verify_address( FirmName => '', Address1 => $address1, Address2 => $address2, City => $city, State => $state, Zip5 => $zip5, Zip4 => '', ); if( $verifier->is_error ) { warn "Oops!\n"; print $verifier->response; print "\n"; } else { print <<"HERE"; $hash->{FirmName} $hash->{Address1} $hash->{Address2} $hash->{City} $hash->{State} $hash->{Zip5} $hash->{Zip4} HERE } sub prompt { my $prompt = shift; print "$prompt > "; my $line = ; chomp( $line ); $line; }Business-US-USPS-WebTools-1.11/examples/README0000644000076500007650000000010510562747350021025 0ustar brianbrian00000000000000See the tests in the t/ directory for examples until I add some more.Business-US-USPS-WebTools-1.11/examples/zip_code_lookup.pl0000644000076500007650000000157210562747350023700 0ustar brianbrian00000000000000#!/usr/bin/perl use Business::US::USPS::WebTools::ZipCodeLookup; my $verifier = Business::US::USPS::WebTools::ZipCodeLookup->new( { UserID => $ENV{USPS_WEBTOOLS_USERID}, Password => $ENV{USPS_WEBTOOLS_PASSWORD}, # Testing => 1, } ); my $address2 = prompt( "Address2" ); my $city = prompt( "City" ); my $state = prompt( "State" ); my $hash = $verifier->lookup_zipcode( FirmName => '', Address1 => $address1, Address2 => $address2, City => $city, State => $state, Zip5 => $zip5, Zip4 => '', ); if( $verifier->is_error ) { warn "Oops!\n"; print $verifier->response; print "\n"; } else { print <<"HERE"; $hash->{FirmName} $hash->{Address1} $hash->{Address2} $hash->{City} $hash->{State} $hash->{Zip5} $hash->{Zip4} HERE } sub prompt { my $prompt = shift; print "$prompt > "; my $line = ; chomp( $line ); $line; }Business-US-USPS-WebTools-1.11/lib/0000755000076500007650000000000010712777041017076 5ustar brianbrian00000000000000Business-US-USPS-WebTools-1.11/lib/AddressStandardization.pm0000644000076500007650000000716210712776674024121 0ustar brianbrian00000000000000# $Id: AddressStandardization.pm 2360 2007-11-03 04:48:52Z comdog $ package Business::US::USPS::WebTools::AddressStandardization; use strict; no warnings 'uninitialized'; use base qw(Business::US::USPS::WebTools); use subs qw(); use vars qw($VERSION); $VERSION = 1.11; =head1 NAME Business::US::USPS::WebTools::AddressStandardization - canonicalize a US address =head1 SYNOPSIS use Business::US::USPS::WebTools::AddressStandardization; my $verifier = Business::US::USPS::WebTools::AddressStandardization->new( { UserID => $ENV{USPS_WEBTOOLS_USERID}, Password => $ENV{USPS_WEBTOOLS_PASSWORD}, Testing => 1, } ); my $hash = $verifier->verify_address( FirmName => '', Address1 => '', Address2 => '6406 Ivy Lane', City => 'Greenbelt', State => 'MD', Zip5 => '', Zip4 => '', ); if( $verifier->is_error ) { warn "Oh No! $verifier->{error}{description}\n"; } else { print join "\n", map { "$_: $hash->{$_}" } qw(FirmName Address1 Address2 City State Zip5 Zip4); } =head1 DESCRIPTION *** THIS IS ALPHA SOFTWARE *** This module implements the Address Standardization web service from the US Postal Service. It is a subclass of Business::US::USPS::WebTools. =cut =over 4 =cut sub _fields { qw( FirmName Address1 Address2 City State Zip5 Zip4 ) } sub _required { qw( Address2 City State ) } =item verify_address( KEY, VALUE, ... ) The C method takes the following keys, which come directly from the USPS web service interface: FirmName The name of the company Address1 The suite or apartment Address2 The street address City The name of the city State The two letter state abbreviation Zip5 The 5 digit zip code Zip4 The 4 digit extension to the zip code It returns an anonymous hash with the same keys, but the values are the USPS's canonicalized address. If there is an error, the hash values will be the empty string, and the error flag is set. Check is with C: $verifier->is_error; See the C documentation in Business::US::USPS::WebTools for more details on error information. =cut sub verify_address { my( $self, %hash ) = @_; $self->_make_url( \%hash ); $self->_make_request; $self->_parse_response; } sub _api_name { "Verify" } sub _make_query_xml { my( $self, $hash ) = @_; my $user = $self->userid; my $pass = $self->password; my $xml = qq|| . qq|
|; foreach my $field ( $self->_fields ) { $xml .= "<$field>$$hash{$field}"; } $xml .= qq|
|; return $xml; } sub _parse_response { my( $self ) = @_; #require 'Hash::AsObject'; my %hash = (); foreach my $field ( $self->_fields ) { my( $value ) = $self->response =~ m|<$field>(.*?)|g; $hash{$field} = $value || ''; } bless \%hash, ref $self; # 'Hash::AsObject'; } =back =head1 TO DO =head1 SEE ALSO L The WebTools API is documented on the US Postal Service's website: http://www.usps.com/webtools/htm/Address-Information.htm =head1 SOURCE AVAILABILITY This source is part of a SourceForge project which always has the latest sources in CVS, as well as all of the previous releases. http://sourceforge.net/projects/brian-d-foy/ If, for some reason, I disappear from the world, one of the other members of the project can shepherd this module appropriately. =head1 AUTHOR brian d foy, C<< >> =head1 COPYRIGHT AND LICENSE Copyright (c) 2006-2007, brian d foy, All Rights Reserved. You may redistribute this under the same terms as Perl itself. =cut 1; Business-US-USPS-WebTools-1.11/lib/CityStateLookup.pm0000644000076500007650000000664710712776674022567 0ustar brianbrian00000000000000# $Id: CityStateLookup.pm 2360 2007-11-03 04:48:52Z comdog $ package Business::US::USPS::WebTools::CityStateLookup; use strict; no warnings 'uninitialized'; use base qw(Business::US::USPS::WebTools); use subs qw(); use vars qw($VERSION); $VERSION = '1.11'; =head1 NAME Business::US::USPS::WebTools::CityStateLookup - lookup a City and State by Zip Code =head1 SYNOPSIS use Business::US::USPS::WebTools::AddressStandardization; my $looker_upper = Business::US::USPS::WebTools::CityStateLookup->new( { UserID => $ENV{USPS_WEBTOOLS_USERID}, Password => $ENV{USPS_WEBTOOLS_PASSWORD}, Testing => 1, } ); my $hash = $looker_upper->lookup_city_state( ); if( $looker_upper->is_error ) { warn "Oh No! $looker_upper->{error}{description}\n"; } else { print join "\n", map { "$_: $hash->{$_}" } qw(FirmName Address1 Address2 City State Zip5 Zip4); } =head1 DESCRIPTION *** THIS IS ALPHA SOFTWARE *** This module implements the Address Standardization web service from the US Postal Service. It is a subclass of Business::US::USPS::WebTools. =cut =over 4 =cut sub _fields { qw( FirmName Address1 Address2 City State Zip5 Zip4 ) } sub _required { qw( Address2 City State ) } =item lookup_city_state( KEY, VALUE, ... ) The C method takes the following keys, which come directly from the USPS web service interface: FirmName The name of the company Address1 The suite or apartment Address2 The street address City The name of the city State The two letter state abbreviation Zip5 The 5 digit zip code Zip4 The 4 digit extension to the zip code It returns an anonymous hash with the same keys, but the values are the USPS's canonicalized address. If there is an error, the hash values will be the empty string, and the error flag is set. Check is with C: $verifier->is_error; See the C documentation in Business::US::USPS::WebTools for more details on error information. =cut sub lookup_city_state { my( $self, $zip_code ) = @_; $self->_make_url( { Zip5 => $zip_code } ); $self->_make_request; $self->_parse_response; } sub _api_name { "CityStateLookup" } sub _make_query_xml { my( $self, $hash ) = @_; my $user = $self->userid; my $pass = $self->password; my $xml = qq|| . qq|$$hash{Zip5}| . qq||; } sub _parse_response { my( $self ) = @_; #require 'Hash::AsObject'; my %hash = (); foreach my $field ( $self->_fields ) { my( $value ) = $self->response =~ m|<$field>(.*?)|g; $hash{$field} = $value || ''; } bless \%hash, ref $self; # 'Hash::AsObject'; } =back =head1 TO DO =head1 SEE ALSO L The WebTools API is documented on the US Postal Service's website: http://www.usps.com/webtools/htm/Address-Information.htm =head1 SOURCE AVAILABILITY This source is part of a SourceForge project which always has the latest sources in CVS, as well as all of the previous releases. http://sourceforge.net/projects/brian-d-foy/ If, for some reason, I disappear from the world, one of the other members of the project can shepherd this module appropriately. =head1 AUTHOR brian d foy, C<< >> =head1 COPYRIGHT AND LICENSE Copyright (c) 2006-2007, brian d foy, All Rights Reserved. You may redistribute this under the same terms as Perl itself. =cut 1; Business-US-USPS-WebTools-1.11/lib/WebTools.pm0000644000076500007650000001312510712776674021207 0ustar brianbrian00000000000000# $Id: WebTools.pm 2360 2007-11-03 04:48:52Z comdog $ package Business::US::USPS::WebTools; use strict; no warnings 'uninitialized'; use Carp qw(croak); use subs qw(); use vars qw($VERSION); $VERSION = '1.11'; =head1 NAME Business::US::USPS::WebTools - Use the US Postal Service Web Tools =head1 SYNOPSIS use Business::US::USPS::WebTools; # see subclasses for API details =head1 DESCRIPTION *** THIS IS ALPHA SOFTWARE *** This is the base class for the WebTools web service from the US Postal Service. The USPS offers several services, and this module handles the parts common to all of them: making the request, getting the response, parsing error reponses, and so on. The interesting stuff happens in one of the subclasses which implement a particular service. So far, the only subclass in this distribution is C. =over =cut my $LiveServer = "production.shippingapis.com"; my $TestServer = "testing.shippingapis.com"; =item new( ANONYMOUS_HASH ) Make the web service object. Pass is an anonymous hash with these keys: UserID the user id provided by the USPS Password the password provided by the USPS Testing true or false, to select the right server If you don't pass the UserID or Password entries, C looks in the environment variables USPS_WEBTOOLS_USERID and USPS_WEBTOOLS_PASSWORD. If C cannot find both the User ID and the Password, it croaks. If you pass a true value with the Testing key, the object will use the testing server host name and the testing URL path. If the Testing key is false or not present, the object uses the live server details. =cut sub new { my( $class, $args ) = @_; my $user_id = $args->{UserID} || $ENV{USPS_WEBTOOLS_USERID} || croak "No user ID for USPS WebTools!"; my $password = $args->{Password} || $ENV{USPS_WEBTOOLS_PASSWORD} || croak "No password for USPS WebTools!"; $args->{UserID} = $user_id; $args->{Password} = $password; $args->{testing} = $args->{Testing} || 0; $args->{live} = ! $args->{Testing}; bless $args, $class; } sub _testing { $_[0]->{testing} } sub _live { $_[0]->{live} } =item userid Returns the User ID for the web service. You need to get this from the US Postal Service. =item password Returns the Password for the web service. You need to get this from the US Postal Service. =item url Returns the URL for the request to the web service. So far, all requests are GET request with all of the data in the query string. =item response Returns the response from the web service. This is the slightly modified response. So far it only fixes up line endings and normalizes some error output for inconsistent responses from different physical servers. =cut sub userid { $_[0]->{UserID} } sub password { $_[0]->{Password} } sub url { $_[0]->{url} || $_[0]->_make_url } sub response { $_[0]->{response} } sub _api_host { my $self = shift; if( $self->_testing ) { $TestServer } elsif( $self->_live ) { $LiveServer } else { die "Am I testing or live?" } } sub _api_path { $_[0]->_live ? "/ShippingAPI.dll" : "/ShippingAPITest.dll" } sub _make_query_string { require URI; my( $self, $hash ) = @_; my $xml = $self->_make_query_xml( $hash ); my $uri = URI->new; $uri->query_form( API => $self->_api_name, XML => $xml, ); $uri->query; # this should work, but doesn't } sub _make_url { my( $self, $hash ) = @_; $self->{url} = qq|http://| . $self->_api_host . $self->_api_path . "?" . $self->_make_query_string( $hash ); } sub _make_request { my( $self, $url ) = @_; require LWP::Simple; $self->{error} = undef; $self->{response} = LWP::Simple::get( $self->url ); $self->{response} =~ s/\015\012/\n/g; $self->is_error; use Data::Dumper; # print STDERR "In _make_request:\n" . Dumper( $self ) . "\n"; $self->{response}; } =item is_error Returns true if the response to the last request was an error, and false otherwise. If the response was an error, this method sets various fields in the object: $self->{error}{number} $self->{error}{source} $self->{error}{description} $self->{error}{help_file} $self->{error}{help_context} =cut sub is_error { my $self = shift; return 0 unless $self->response =~ ""; $self->{error} = {}; # Apparently not all servers return this string in the # same way. Some have SOL and some have SoL $self->{response} =~ s/SOLServer/SOLServer/ig; ( $self->{error}{number} ) = $self->response =~ m|(-?\d+)|g; ( $self->{error}{source} ) = $self->response =~ m|(.*?)|g; ( $self->{error}{description} ) = $self->response =~ m|(.*?)|g; ( $self->{error}{help_file} ) = $self->response =~ m|(.*?)|ig; ( $self->{error}{help_context} ) = $self->response =~ m|(.*?)|ig; 1; } =back =head1 SEE ALSO The WebTools API is documented on the US Postal Service's website: http://www.usps.com/webtools/htm/Address-Information.htm =head1 SOURCE AVAILABILITY This source is part of a SourceForge project which always has the latest sources in CVS, as well as all of the previous releases. http://sourceforge.net/projects/brian-d-foy/ If, for some reason, I disappear from the world, one of the other members of the project can shepherd this module appropriately. =head1 AUTHOR brian d foy, C<< >> =head1 COPYRIGHT AND LICENSE Copyright (c) 2006-2007 brian d foy. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; Business-US-USPS-WebTools-1.11/lib/ZipCodeLookup.pm0000644000076500007650000000667310712776674022212 0ustar brianbrian00000000000000# $Id: ZipCodeLookup.pm 2360 2007-11-03 04:48:52Z comdog $ package Business::US::USPS::WebTools::ZipCodeLookup; use strict; no warnings 'uninitialized'; use base qw(Business::US::USPS::WebTools); use subs qw(); use vars qw($VERSION); $VERSION = '1.11'; =head1 NAME Business::US::USPS::WebTools::ZipCodeLookup - lookup a Zip Code using the USPS Web Tools =head1 SYNOPSIS use Business::US::USPS::WebTools::ZipCodeLookup; my $looker_upper = Business::US::USPS::WebTools::ZipCodeLookup->new( { UserID => $ENV{USPS_WEBTOOLS_USERID}, Password => $ENV{USPS_WEBTOOLS_PASSWORD}, Testing => 1, } ); my $hash = $looker_upper->lookup_zipcode( ); if( $looker_upper->is_error ) { warn "Oh No! $looker_upper->{error}{description}\n"; } else { print join "\n", map { "$_: $hash->{$_}" } qw(FirmName Address1 Address2 City State Zip5 Zip4); } =head1 DESCRIPTION *** THIS IS ALPHA SOFTWARE *** This module implements the Zip Code Lookup web service from the US Postal Service. It is a subclass of Business::US::USPS::WebTools. =cut =over 4 =cut sub _fields { qw( FirmName Address1 Address2 City State) } sub _required { qw( Address2 City State ) } =item lookup_zipcode( KEY, VALUE, ... ) The C method takes the following keys, which come directly from the USPS web service interface: Address2 The street address City The name of the city State The two letter state abbreviation Zip5 The 5 digit zip code Zip4 The 4 digit extension to the zip code It returns an anonymous hash with the same keys, but the values are the USPS's canonicalized address. If there is an error, the hash values will be the empty string, and the error flag is set. Check is with C: $verifier->is_error; See the C documentation in Business::US::USPS::WebTools for more details on error information. =cut sub lookup_zipcode { my( $self, %hash ) = @_; $self->_make_url( \%hash ); $self->_make_request; $self->_parse_response; } sub _api_name { "ZipCodeLookup" } sub _make_query_xml { my( $self, $hash ) = @_; my $user = $self->userid; my $pass = $self->password; my $xml = qq|| . qq|
|; foreach my $field ( $self->_fields ) { $xml .= "<$field>$$hash{$field}"; } $xml .= qq|
|; return $xml; } sub _parse_response { my( $self ) = @_; #require 'Hash::AsObject'; my %hash = (); foreach my $field ( $self->_fields, qw( Zip5 Zip4 ) ) { my( $value ) = $self->response =~ m|<$field>(.*?)|g; $hash{$field} = $value || ''; } bless \%hash, ref $self; # 'Hash::AsObject'; } =back =head1 TO DO =head1 SEE ALSO L The WebTools API is documented on the US Postal Service's website: http://www.usps.com/webtools/htm/Address-Information.htm =head1 SOURCE AVAILABILITY This source is part of a SourceForge project which always has the latest sources in CVS, as well as all of the previous releases. http://sourceforge.net/projects/brian-d-foy/ If, for some reason, I disappear from the world, one of the other members of the project can shepherd this module appropriately. =head1 AUTHOR brian d foy, C<< >> =head1 COPYRIGHT AND LICENSE Copyright (c) 2006-2007 brian d foy. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; Business-US-USPS-WebTools-1.11/LICENSE0000644000076500007650000000011510562747350017335 0ustar brianbrian00000000000000You can use Business::US::USPS::Webtools under the same terms as Perl itself.Business-US-USPS-WebTools-1.11/Makefile.PL0000644000076500007650000000350610712776674020321 0ustar brianbrian00000000000000# $Id: Makefile.PL 2360 2007-11-03 04:48:52Z comdog $ use ExtUtils::MakeMaker; require 5.006; eval "use Test::Manifest 1.14"; WriteMakefile( 'NAME' => 'Business::US::USPS::WebTools', 'VERSION_FROM' => 'lib/WebTools.pm', 'ABSTRACT' => 'Use the US Postal Service Web Tools', 'LICENSE' => 'perl', 'AUTHOR' => 'brian d foy ', 'PREREQ_PM' => { 'Test::More' => '0', 'Hash::AsObject' => '0', 'Test::Manifest' => 1.14, 'LWP::Simple' => '0', 'URI' => '0', }, 'PM' => { 'lib/WebTools.pm' => '$(INST_LIBDIR)/WebTools.pm', 'lib/AddressStandardization.pm' => '$(INST_LIBDIR)/WebTools/AddressStandardization.pm', 'lib/ZipCodeLookup.pm' => '$(INST_LIBDIR)/WebTools/ZipCodeLookup.pm', 'lib/CityStateLookup.pm' => '$(INST_LIBDIR)/WebTools/CityStateLookup.pm', }, 'MAN3PODS' => { 'lib/WebTools.pm' => '$(INST_MAN3DIR)/Business::US::USPS::WebTools.3', 'lib/AddressStandardization.pm' => '$(INST_LIBDIR)/Business::US::USPS::WebTools::AddressStandardization.3', 'lib/ZipCodeLookup.pm' => '$(INST_LIBDIR)/Business::US::USPS::WebTools::ZipCodeLookup.3', 'lib/CityStateLookup.pm' => '$(INST_LIBDIR)/Business::US::USPS::WebTools::CityStateLookup.3', }, clean => { FILES => q|Business-*| }, ); print <<"HERE" unless( $ENV{USPS_WEBTOOLS_USERID} and $ENV{USPS_WEBTOOLS_PASSWORD} ); ---------------------------------------------------------------------------- To use these modules, you need a User ID and Password from the US Postal Service. See the USPS website for details: http://www.usps.com/webtools/htm/Address-Information.htm Set the USPS_WEBTOOLS_USERID and USPS_WEBTOOLS_PASSWORD environment variables. ---------------------------------------------------------------------------- HERE Business-US-USPS-WebTools-1.11/MANIFEST0000644000076500007650000000071310712777041017462 0ustar brianbrian00000000000000Changes examples/address_standardization.pl examples/README examples/zip_code_lookup.pl lib/AddressStandardization.pm lib/CityStateLookup.pm lib/WebTools.pm lib/ZipCodeLookup.pm LICENSE Makefile.PL MANIFEST This list of files README t/address_verification.t t/city_state_lookup.t t/load.t t/pod.t t/pod_coverage.t t/prereq.t t/test_manifest t/test_or_live.t t/zip_code_lookup.t META.yml Module meta-data (added by MakeMaker) Business-US-USPS-WebTools-1.11/META.yml0000664000076500007650000000112310712777041017600 0ustar brianbrian00000000000000--- #YAML:1.0 name: Business-US-USPS-WebTools version: 1.11 abstract: Use the US Postal Service Web Tools license: perl generated_by: ExtUtils::MakeMaker version 6.36 distribution_type: module requires: Hash::AsObject: 0 LWP::Simple: 0 Test::Manifest: 1.14 Test::More: 0 URI: 0 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.3.html version: 1.3 author: - brian d foy Business-US-USPS-WebTools-1.11/README0000644000076500007650000000166310562747350017221 0ustar brianbrian00000000000000$Id: README 1903 2006-09-26 21:21:40Z comdog $ This module provides a Perl interface to the US Postal Service's Web Tools service. You need a UserID and Password to use these services. See the Web Tools site for details: http://www.usps.com/webtools/ You can set the USPS_WEBTOOLS_USERID and USPS_WEBTOOLS_PASSWORD environment variables and the module will pick them up automatically. I've included some example scripts in the examples/ directory. You can install this using in the usual Perl fashion perl Makefile.PL make make test make install The documentation is in the module file. Once you install the file, you can read it with perldoc. perldoc Business::US::USPS::WebTools If you want to read it before you install it, you can use perldoc directly on the module file. perldoc lib/WebTools.pm This module is also in CVS on SourceForge http://sourceforge.net/projects/brian-d-foy/ Enjoy, brian d foy, bdfoy@cpan.org Business-US-USPS-WebTools-1.11/t/0000755000076500007650000000000010712777041016573 5ustar brianbrian00000000000000Business-US-USPS-WebTools-1.11/t/address_verification.t0000644000076500007650000004504210562747350023157 0ustar brianbrian00000000000000#!/usr/bin/perl # $Id: address_verification.t 2122 2007-02-06 00:14:33Z comdog $ # See http://www.usps.com/webtools/htm/Address-Information.htm for # the test requirements. The headings ( "Good response #1", etc ) # correspond to the USPS test specification use Test::More; my $class = "Business::US::USPS::WebTools::AddressStandardization"; my $method = 'verify_address'; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # unless( $ENV{USPS_WEBTOOLS_USERID} and $ENV{USPS_WEBTOOLS_PASSWORD} ) { plan skip_all => "You must set the USPS_WEBTOOLS_USERID and USPS_WEBTOOLS_PASSWORD " . "environment variables to run these tests\n"; } else { plan tests => 111; } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # use_ok( $class ); my $verifier = $class->new( { UserID => $ENV{USPS_WEBTOOLS_USERID}, Password => $ENV{USPS_WEBTOOLS_PASSWORD}, Testing => 1, } ); isa_ok( $verifier, $class ); can_ok( $verifier, $method ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Good response #1 { my $url = $verifier->_make_url( { FirmName => '', Address1 => '', Address2 => '6406 Ivy Lane', City => 'Greenbelt', State => 'MD', Zip5 => '', Zip4 => '', } ); is( $url, qq|http://testing.shippingapis.com/ShippingAPITest.dll?API=Verify&XML=%3CAddressValidateRequest+USERID%3D%22$ENV{USPS_WEBTOOLS_USERID}%22+PASSWORD%3D%22$ENV{USPS_WEBTOOLS_PASSWORD}%22%3E%3CAddress+ID%3D%220%22%3E%3CFirmName%3E%3C%2FFirmName%3E%3CAddress1%3E%3C%2FAddress1%3E%3CAddress2%3E6406+Ivy+Lane%3C%2FAddress2%3E%3CCity%3EGreenbelt%3C%2FCity%3E%3CState%3EMD%3C%2FState%3E%3CZip5%3E%3C%2FZip5%3E%3CZip4%3E%3C%2FZip4%3E%3C%2FAddress%3E%3C%2FAddressValidateRequest%3E|, "URL for Ivy Lane is correct", ); my $response = $verifier->_make_request; ok( defined $response ); ok( ! $verifier->is_error, "Response is not an error" ); my $expected = <<"XML";
6406 IVY LNGREENBELTMD207701440
XML is( $response, $expected ); my $hash = $verifier->_parse_response; is( $hash->{FirmName}, '', 'FirmName matches for Ivy Lane' ); is( $hash->{Address1}, '', 'Address1 matches for Ivy Lane' ); is( $hash->{Address2}, '6406 IVY LN', 'Address2 matches for Ivy Lane' ); is( $hash->{City}, 'GREENBELT', 'City matches for Ivy Lane' ); is( $hash->{State}, 'MD', 'State matches for Ivy Lane' ); is( $hash->{Zip5}, '20770', 'Zip5 matches for Ivy Lane' ); is( $hash->{Zip4}, '1440', 'Zip4 matches for Ivy Lane' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Good response #2 { my $url = $verifier->_make_url( { FirmName => '', Address1 => '', Address2 => '8 Wildwood Drive', City => 'Old Lyme', State => 'CT', Zip5 => '06371', Zip4 => '', } ); is( $url, qq|http://testing.shippingapis.com/ShippingAPITest.dll?API=Verify&XML=%3CAddressValidateRequest+USERID%3D%22$ENV{USPS_WEBTOOLS_USERID}%22+PASSWORD%3D%22$ENV{USPS_WEBTOOLS_PASSWORD}%22%3E%3CAddress+ID%3D%220%22%3E%3CFirmName%3E%3C%2FFirmName%3E%3CAddress1%3E%3C%2FAddress1%3E%3CAddress2%3E8+Wildwood+Drive%3C%2FAddress2%3E%3CCity%3EOld+Lyme%3C%2FCity%3E%3CState%3ECT%3C%2FState%3E%3CZip5%3E06371%3C%2FZip5%3E%3CZip4%3E%3C%2FZip4%3E%3C%2FAddress%3E%3C%2FAddressValidateRequest%3E|, "URL for Wildwood Drive is correct", ); my $response = $verifier->_make_request; ok( defined $response ); ok( ! $verifier->is_error, "Response is not an error" ); my $expected = <<"XML";
8 WILDWOOD DROLD LYMECT063711844
XML is( $response, $expected ); my $hash = $verifier->_parse_response; is( $hash->{FirmName}, '', 'FirmName matches for Wildwood' ); is( $hash->{Address1}, '', 'Address1 matches for Wildwood' ); is( $hash->{Address2}, '8 WILDWOOD DR', 'Address2 matches for Wildwood' ); is( $hash->{City}, 'OLD LYME', 'City matches for Wildwood' ); is( $hash->{State}, 'CT', 'State matches for Wildwood' ); is( $hash->{Zip5}, '06371', 'Zip5 matches for Wildwood' ); is( $hash->{Zip4}, '1844', 'Zip4 matches for Wildwood' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Good response #3 { my $url = $verifier->_make_url( { FirmName => '', Address1 => '', Address2 => '4411 Romlon Street', City => 'Beltsville', State => 'MD', Zip5 => '', Zip4 => '', } ); is( $url, qq|http://testing.shippingapis.com/ShippingAPITest.dll?API=Verify&XML=%3CAddressValidateRequest+USERID%3D%22$ENV{USPS_WEBTOOLS_USERID}%22+PASSWORD%3D%22$ENV{USPS_WEBTOOLS_PASSWORD}%22%3E%3CAddress+ID%3D%220%22%3E%3CFirmName%3E%3C%2FFirmName%3E%3CAddress1%3E%3C%2FAddress1%3E%3CAddress2%3E4411+Romlon+Street%3C%2FAddress2%3E%3CCity%3EBeltsville%3C%2FCity%3E%3CState%3EMD%3C%2FState%3E%3CZip5%3E%3C%2FZip5%3E%3CZip4%3E%3C%2FZip4%3E%3C%2FAddress%3E%3C%2FAddressValidateRequest%3E|, "URL for Romlan Street is correct", ); my $response = $verifier->_make_request; ok( defined $response ); ok( ! $verifier->is_error, "Response is not an error" ); my $expected = <<"XML";
4411 ROMLON STBELTSVILLEMD207052425
XML is( $response, $expected ); my $hash = $verifier->_parse_response; is( $hash->{FirmName}, '', 'FirmName matches for Romlan' ); is( $hash->{Address1}, '', 'Address1 matches for Romlan' ); is( $hash->{Address2}, '4411 ROMLON ST', 'Address2 matches for Romlan' ); is( $hash->{City}, 'BELTSVILLE', 'City matches for Romlan' ); is( $hash->{State}, 'MD', 'State matches for Romlan' ); is( $hash->{Zip5}, '20705', 'Zip5 matches for Romlan' ); is( $hash->{Zip4}, '2425', 'Zip4 matches for Romlan' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Good response #4 { my $url = $verifier->_make_url( { FirmName => '', Address1 => '', Address2 => '3527 Sharonwood Road Apt. 3C', City => 'Laurel', State => 'MD', Zip5 => '', Zip4 => '', } ); is( $url, qq|http://testing.shippingapis.com/ShippingAPITest.dll?API=Verify&XML=%3CAddressValidateRequest+USERID%3D%22$ENV{USPS_WEBTOOLS_USERID}%22+PASSWORD%3D%22$ENV{USPS_WEBTOOLS_PASSWORD}%22%3E%3CAddress+ID%3D%220%22%3E%3CFirmName%3E%3C%2FFirmName%3E%3CAddress1%3E%3C%2FAddress1%3E%3CAddress2%3E3527+Sharonwood+Road+Apt.+3C%3C%2FAddress2%3E%3CCity%3ELaurel%3C%2FCity%3E%3CState%3EMD%3C%2FState%3E%3CZip5%3E%3C%2FZip5%3E%3CZip4%3E%3C%2FZip4%3E%3C%2FAddress%3E%3C%2FAddressValidateRequest%3E|, "URL for Sharonwood Road is correct", ); my $response = $verifier->_make_request; ok( defined $response ); ok( ! $verifier->is_error, "Response is not an error" ); my $expected = <<"XML";
3527 SHARONWOOD RD APT 3CLAURELMD207245920
XML is( $response, $expected ); my $hash = $verifier->_parse_response; is( $hash->{FirmName}, '', 'FirmName matches for Sharonwood' ); is( $hash->{Address1}, '', 'Address1 matches for Sharonwood' ); is( $hash->{Address2}, '3527 SHARONWOOD RD APT 3C', 'Address2 matches for Sharonwood' ); is( $hash->{City}, 'LAUREL', 'City matches for Sharonwood' ); is( $hash->{State}, 'MD', 'State matches for Sharonwood' ); is( $hash->{Zip5}, '20724', 'Zip5 matches for Sharonwood' ); is( $hash->{Zip4}, '5920', 'Zip4 matches for Sharonwood' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Error Requests # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Error response #1 { my $url = $verifier->_make_url( { FirmName => '', Address1 => '', Address2 => '3527 Sharonwood Road Apt. 3C', City => 'Wilmington', State => 'DE', Zip5 => '', Zip4 => '', } ); is( $url, qq|http://testing.shippingapis.com/ShippingAPITest.dll?API=Verify&XML=%3CAddressValidateRequest+USERID%3D%22$ENV{USPS_WEBTOOLS_USERID}%22+PASSWORD%3D%22$ENV{USPS_WEBTOOLS_PASSWORD}%22%3E%3CAddress+ID%3D%220%22%3E%3CFirmName%3E%3C%2FFirmName%3E%3CAddress1%3E%3C%2FAddress1%3E%3CAddress2%3E3527+Sharonwood+Road+Apt.+3C%3C%2FAddress2%3E%3CCity%3EWilmington%3C%2FCity%3E%3CState%3EDE%3C%2FState%3E%3CZip5%3E%3C%2FZip5%3E%3CZip4%3E%3C%2FZip4%3E%3C%2FAddress%3E%3C%2FAddressValidateRequest%3E|, "URL for Sharonwood Road Error is correct", ); my $response = $verifier->_make_request; ok( defined $response ); ok( $verifier->is_error, "Error request gets an error response" ); my $expected = <<"XML";
-2147219401SOLServerTest;SOLServerTest.CallAddressDllThat address could not be found.
XML is( $response, $expected ); is( $verifier->{error}{number}, -2147219401, 'Error number matches for Sharonwood error' ); is( $verifier->{error}{source}, 'SOLServerTest;SOLServerTest.CallAddressDll', 'Error source matches for Sharonwood error' ); is( $verifier->{error}{description}, 'That address could not be found.', 'Error description matches for Sharonwood error' ); is( $verifier->{error}{help_file}, '', 'Error help file matches for Sharonwood error' ); is( $verifier->{error}{help_context}, '', 'Error help context matches for Sharonwood error' ); my $hash = $verifier->_parse_response; is( $hash->{FirmName}, '', 'FirmName is empty for Sharonwood error' ); is( $hash->{Address1}, '', 'Address1 is empty for Sharonwood error' ); is( $hash->{Address2}, '', 'Address2 is empty for Sharonwood error' ); is( $hash->{City}, '', 'City is empty for Sharonwood error' ); is( $hash->{State}, '', 'State is empty for Sharonwood error' ); is( $hash->{Zip5}, '', 'Zip5 is empty for Sharonwood error' ); is( $hash->{Zip4}, '', 'Zip4 is empty for Sharonwood error' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Error response #2 { my $url = $verifier->_make_url( { FirmName => '', Address1 => '', Address2 => '1600 Pennsylvania Avenue', City => 'Washington', State => 'DC', Zip5 => '', Zip4 => '', } ); is( $url, qq|http://testing.shippingapis.com/ShippingAPITest.dll?API=Verify&XML=%3CAddressValidateRequest+USERID%3D%22$ENV{USPS_WEBTOOLS_USERID}%22+PASSWORD%3D%22$ENV{USPS_WEBTOOLS_PASSWORD}%22%3E%3CAddress+ID%3D%220%22%3E%3CFirmName%3E%3C%2FFirmName%3E%3CAddress1%3E%3C%2FAddress1%3E%3CAddress2%3E1600+Pennsylvania+Avenue%3C%2FAddress2%3E%3CCity%3EWashington%3C%2FCity%3E%3CState%3EDC%3C%2FState%3E%3CZip5%3E%3C%2FZip5%3E%3CZip4%3E%3C%2FZip4%3E%3C%2FAddress%3E%3C%2FAddressValidateRequest%3E|, "URL for Pennsylvania Avenue Error is correct", ); my $response = $verifier->_make_request; ok( defined $response ); ok( $verifier->is_error, "Error request gets an error response" ); my $expected = <<"XML";
-2147219403SOLServerTest;SOLServerTest.CallAddressDllMultiple responses found. No default address.
XML is( $response, $expected ); is( $verifier->{error}{number}, -2147219403, 'Error number matches for Pennsylvania Avenue error' ); is( $verifier->{error}{source}, 'SOLServerTest;SOLServerTest.CallAddressDll', 'Error source matches for Pennsylvania Avenue error' ); is( $verifier->{error}{description}, 'Multiple responses found. No default address.', 'Error description matches for Pennsylvania Avenue error' ); is( $verifier->{error}{help_file}, '', 'Error help file matches for Pennsylvania Avenue error' ); is( $verifier->{error}{help_context}, '', 'Error help context matches for Pennsylvania Avenue error' ); my $hash = $verifier->_parse_response; # print STDERR "In _make_request:\n" . Dumper( $verifier ) . "\n"; is( $hash->{FirmName}, '', 'FirmName is empty for Pennsylvania Avenue error' ); is( $hash->{Address1}, '', 'Address1 is empty for Pennsylvania Avenue error' ); is( $hash->{Address2}, '', 'Address2 is empty for Pennsylvania Avenue error' ); is( $hash->{City}, '', 'City is empty for Pennsylvania Avenue error' ); is( $hash->{State}, '', 'State is empty for Pennsylvania Avenue error' ); is( $hash->{Zip5}, '', 'Zip5 is empty for Pennsylvania Avenue error' ); is( $hash->{Zip4}, '', 'Zip4 is empty for Pennsylvania Avenue error' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Error response #3 { my $url = $verifier->_make_url( { FirmName => '', Address1 => '', Address2 => '123 Main Street', City => 'Washington', State => 'ZZ', Zip5 => '', Zip4 => '', } ); is( $url, qq|http://testing.shippingapis.com/ShippingAPITest.dll?API=Verify&XML=%3CAddressValidateRequest+USERID%3D%22$ENV{USPS_WEBTOOLS_USERID}%22+PASSWORD%3D%22$ENV{USPS_WEBTOOLS_PASSWORD}%22%3E%3CAddress+ID%3D%220%22%3E%3CFirmName%3E%3C%2FFirmName%3E%3CAddress1%3E%3C%2FAddress1%3E%3CAddress2%3E123+Main+Street%3C%2FAddress2%3E%3CCity%3EWashington%3C%2FCity%3E%3CState%3EZZ%3C%2FState%3E%3CZip5%3E%3C%2FZip5%3E%3CZip4%3E%3C%2FZip4%3E%3C%2FAddress%3E%3C%2FAddressValidateRequest%3E|, "URL for Main Street Error is correct", ); my $response = $verifier->_make_request; ok( defined $response ); ok( $verifier->is_error, "Error request gets an error response" ); my $expected = <<"XML";
-2147219402SOLServerTest;SOLServerTest.CallAddressDllThat State is not valid.
XML is( $response, $expected ); is( $verifier->{error}{number}, -2147219402, 'Error number matches for Main Street error' ); is( $verifier->{error}{source}, 'SOLServerTest;SOLServerTest.CallAddressDll', 'Error source matches for Main Street error' ); is( $verifier->{error}{description}, 'That State is not valid.', 'Error description matches for Main Street error' ); is( $verifier->{error}{help_file}, '', 'Error help file matches for Main Street error' ); is( $verifier->{error}{help_context}, '', 'Error help context matches for Main Street error' ); my $hash = $verifier->_parse_response; # print STDERR "In _make_request:\n" . Dumper( $verifier ) . "\n"; is( $hash->{FirmName}, '', 'FirmName is empty for Main Street error' ); is( $hash->{Address1}, '', 'Address1 is empty for Main Street error' ); is( $hash->{Address2}, '', 'Address2 is empty for Main Street error' ); is( $hash->{City}, '', 'City is empty for Main Street error' ); is( $hash->{State}, '', 'State is empty for Main Street error' ); is( $hash->{Zip5}, '', 'Zip5 is empty for Main Street error' ); is( $hash->{Zip4}, '', 'Zip4 is empty for Main Street error' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Error response #4 { my $url = $verifier->_make_url( { FirmName => '', Address1 => '', Address2 => '123 Main Street', City => 'Trenton', State => 'NJ', Zip5 => '', Zip4 => '', } ); is( $url, qq|http://testing.shippingapis.com/ShippingAPITest.dll?API=Verify&XML=%3CAddressValidateRequest+USERID%3D%22$ENV{USPS_WEBTOOLS_USERID}%22+PASSWORD%3D%22$ENV{USPS_WEBTOOLS_PASSWORD}%22%3E%3CAddress+ID%3D%220%22%3E%3CFirmName%3E%3C%2FFirmName%3E%3CAddress1%3E%3C%2FAddress1%3E%3CAddress2%3E123+Main+Street%3C%2FAddress2%3E%3CCity%3ETrenton%3C%2FCity%3E%3CState%3ENJ%3C%2FState%3E%3CZip5%3E%3C%2FZip5%3E%3CZip4%3E%3C%2FZip4%3E%3C%2FAddress%3E%3C%2FAddressValidateRequest%3E|, "URL for Trenton, NJ Error is correct", ); my $response = $verifier->_make_request; ok( defined $response ); ok( $verifier->is_error, "Error request gets an error response" ); my $expected = <<"XML";
-2147219400SOLServerTest;SOLServerTest.CallAddressDllThat is not a valid city.
XML is( $response, $expected ); is( $verifier->{error}{number}, -2147219400, 'Error number matches for Trenton, NJ error' ); is( $verifier->{error}{source}, 'SOLServerTest;SOLServerTest.CallAddressDll', 'Error source matches for Trenton, NJ error' ); is( $verifier->{error}{description}, 'That is not a valid city.', 'Error description matches for Trenton, NJ error' ); is( $verifier->{error}{help_file}, '', 'Error help file matches for Trenton, NJ error' ); is( $verifier->{error}{help_context}, '', 'Error help context matches for Trenton, NJ error' ); my $hash = $verifier->_parse_response; # print STDERR "In _make_request:\n" . Dumper( $verifier ) . "\n"; is( $hash->{FirmName}, '', 'FirmName is empty for Trenton, NJ error' ); is( $hash->{Address1}, '', 'Address1 is empty for Trenton, NJ error' ); is( $hash->{Address2}, '', 'Address2 is empty for Trenton, NJ error' ); is( $hash->{City}, '', 'City is empty for Trenton, NJ error' ); is( $hash->{State}, '', 'State is empty for Trenton, NJ error' ); is( $hash->{Zip5}, '', 'Zip5 is empty for Trenton, NJ error' ); is( $hash->{Zip4}, '', 'Zip4 is empty for Trenton, NJ error' ); }Business-US-USPS-WebTools-1.11/t/city_state_lookup.t0000644000076500007650000002051210562747350022524 0ustar brianbrian00000000000000#!/usr/bin/perl # $Id: city_state_lookup.t 2122 2007-02-06 00:14:33Z comdog $ # See http://www.usps.com/webtools/htm/Address-Information.htm for # the test requirements. The headings ( "Good response #1", etc ) # correspond to the USPS test specification use Test::More; my $class = "Business::US::USPS::WebTools::CityStateLookup"; my $method = 'lookup_city_state'; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # unless( $ENV{USPS_WEBTOOLS_USERID} and $ENV{USPS_WEBTOOLS_PASSWORD} ) { plan skip_all => "You must set the USPS_WEBTOOLS_USERID and USPS_WEBTOOLS_PASSWORD " . "environment variables to run these tests\n"; } else { plan tests => 50; } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # use_ok( $class ); my $verifier = $class->new( { UserID => $ENV{USPS_WEBTOOLS_USERID}, Password => $ENV{USPS_WEBTOOLS_PASSWORD}, Testing => 1, } ); isa_ok( $verifier, $class ); can_ok( $verifier, $method ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Good response #1 { my $url = $verifier->_make_url( { Zip5 => 90210, } ); is( $url, qq|http://testing.shippingapis.com/ShippingAPITest.dll?API=CityStateLookup&XML=%3CCityStateLookupRequest+USERID%3D%22$ENV{USPS_WEBTOOLS_USERID}%22+PASSWORD%3D%22$ENV{USPS_WEBTOOLS_PASSWORD}%22%3E%3CZipCode+ID%3D%220%22%3E%3CZip5%3E90210%3C%2FZip5%3E%3C%2FZipCode%3E%3C%2FCityStateLookupRequest%3E|, "URL for 90210 is correct", ); my $response = $verifier->_make_request; ok( defined $response ); ok( ! $verifier->is_error, "90210 response is not an error" ); my $expected = <<"XML"; 90210BEVERLY HILLSCA XML is( $response, $expected ); my $hash = $verifier->_parse_response; is( $hash->{City}, 'BEVERLY HILLS', 'City matches for 90210' ); is( $hash->{State}, 'CA', 'State matches for 90210' ); is( $hash->{Zip5}, '90210', 'Zip5 matches for 90210' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Good response #2 { my $url = $verifier->_make_url( { Zip5 => '20770', } ); is( $url, qq|http://testing.shippingapis.com/ShippingAPITest.dll?API=CityStateLookup&XML=%3CCityStateLookupRequest+USERID%3D%22$ENV{USPS_WEBTOOLS_USERID}%22+PASSWORD%3D%22$ENV{USPS_WEBTOOLS_PASSWORD}%22%3E%3CZipCode+ID%3D%220%22%3E%3CZip5%3E20770%3C%2FZip5%3E%3C%2FZipCode%3E%3C%2FCityStateLookupRequest%3E|, "URL for 20770 is correct", ); my $response = $verifier->_make_request; ok( defined $response ); ok( ! $verifier->is_error, "20770 response is not an error" ); my $expected = <<"XML"; 20770GREENBELTMD XML is( $response, $expected ); my $hash = $verifier->_parse_response; is( $hash->{City}, 'GREENBELT', 'City matches for 20770' ); is( $hash->{State}, 'MD', 'State matches for 20770' ); is( $hash->{Zip5}, '20770', 'Zip5 matches for 20770' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Good response #3 { my $url = $verifier->_make_url( { Zip5 => '21113', } ); is( $url, qq|http://testing.shippingapis.com/ShippingAPITest.dll?API=CityStateLookup&XML=%3CCityStateLookupRequest+USERID%3D%22$ENV{USPS_WEBTOOLS_USERID}%22+PASSWORD%3D%22$ENV{USPS_WEBTOOLS_PASSWORD}%22%3E%3CZipCode+ID%3D%220%22%3E%3CZip5%3E21113%3C%2FZip5%3E%3C%2FZipCode%3E%3C%2FCityStateLookupRequest%3E|, "URL for 21113 is correct", ); my $response = $verifier->_make_request; ok( defined $response ); ok( ! $verifier->is_error, "Response is not an error" ); my $expected = <<"XML"; 21113ODENTONMD XML is( $response, $expected ); my $hash = $verifier->_parse_response; is( $hash->{City}, 'ODENTON', 'City matches for 21113' ); is( $hash->{State}, 'MD', 'State matches for 21113' ); is( $hash->{Zip5}, '21113', 'Zip5 matches for 21113' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Good response #4 { my $url = $verifier->_make_url( { Zip5 => '21032', } ); is( $url, qq|http://testing.shippingapis.com/ShippingAPITest.dll?API=CityStateLookup&XML=%3CCityStateLookupRequest+USERID%3D%22$ENV{USPS_WEBTOOLS_USERID}%22+PASSWORD%3D%22$ENV{USPS_WEBTOOLS_PASSWORD}%22%3E%3CZipCode+ID%3D%220%22%3E%3CZip5%3E21032%3C%2FZip5%3E%3C%2FZipCode%3E%3C%2FCityStateLookupRequest%3E|, "URL for 21032 is correct", ); my $response = $verifier->_make_request; ok( defined $response ); ok( ! $verifier->is_error, "21032 response is not an error" ); my $expected = <<"XML"; 21032CROWNSVILLEMD XML is( $response, $expected ); my $hash = $verifier->_parse_response; is( $hash->{City}, 'CROWNSVILLE', 'City matches for 21032' ); is( $hash->{State}, 'MD', 'State matches for 21032' ); is( $hash->{Zip5}, '21032', 'Zip5 matches for 21032' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Good response #5 { my $url = $verifier->_make_url( { Zip5 => '21117', } ); is( $url, qq|http://testing.shippingapis.com/ShippingAPITest.dll?API=CityStateLookup&XML=%3CCityStateLookupRequest+USERID%3D%22$ENV{USPS_WEBTOOLS_USERID}%22+PASSWORD%3D%22$ENV{USPS_WEBTOOLS_PASSWORD}%22%3E%3CZipCode+ID%3D%220%22%3E%3CZip5%3E21117%3C%2FZip5%3E%3C%2FZipCode%3E%3C%2FCityStateLookupRequest%3E|, "URL for Sharonwood Road is correct", ); my $response = $verifier->_make_request; ok( defined $response ); ok( ! $verifier->is_error, "21117 response is not an error" ); my $expected = <<"XML"; 21117OWINGS MILLSMD XML is( $response, $expected ); my $hash = $verifier->_parse_response; is( $hash->{City}, 'OWINGS MILLS', 'City matches for 21117' ); is( $hash->{State}, 'MD', 'State matches for 21117' ); is( $hash->{Zip5}, '21117', 'Zip5 matches for 21117' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Error Requests # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Error response #1 { my $url = $verifier->_make_url( { Zip5 => '99999', } ); is( $url, qq|http://testing.shippingapis.com/ShippingAPITest.dll?API=CityStateLookup&XML=%3CCityStateLookupRequest+USERID%3D%22$ENV{USPS_WEBTOOLS_USERID}%22+PASSWORD%3D%22$ENV{USPS_WEBTOOLS_PASSWORD}%22%3E%3CZipCode+ID%3D%220%22%3E%3CZip5%3E99999%3C%2FZip5%3E%3C%2FZipCode%3E%3C%2FCityStateLookupRequest%3E|, "URL for Sharonwood Road Error is correct", ); my $response = $verifier->_make_request; ok( defined $response ); ok( $verifier->is_error, "Error request gets an error response" ); my $expected = <<"XML"; -2147219403SOLServerTest;SOLServerTest.CallZipCodeDllInvalid Zip Code. XML is( $response, $expected ); is( $verifier->{error}{number}, -2147219403, 'Error number matches for 99999 error' ); is( $verifier->{error}{source}, 'SOLServerTest;SOLServerTest.CallZipCodeDll', 'Error source matches for 99999 error' ); is( $verifier->{error}{description}, 'Invalid Zip Code.', 'Error description matches for 99999 error' ); is( $verifier->{error}{help_file}, '', 'Error help file matches for 99999 error' ); is( $verifier->{error}{help_context}, '', 'Error help context matches for 99999 error' ); my $hash = $verifier->_parse_response; is( $hash->{City}, '', 'City is empty for Sharonwood error' ); is( $hash->{State}, '', 'State is empty for Sharonwood error' ); is( $hash->{Zip5}, '', 'Zip5 is empty for Sharonwood error' ); } Business-US-USPS-WebTools-1.11/t/load.t0000644000076500007650000000063210562747350017703 0ustar brianbrian00000000000000# $Id: load.t 1902 2006-09-26 04:43:39Z comdog $ BEGIN { @classes = qw( Business::US::USPS::WebTools Business::US::USPS::WebTools::AddressStandardization Business::US::USPS::WebTools::ZipCodeLookup Business::US::USPS::WebTools::CityStateLookup ); } use Test::More tests => scalar @classes; foreach my $class ( @classes ) { print "bail out! $class did not compile\n" unless use_ok( $class ); } Business-US-USPS-WebTools-1.11/t/pod.t0000644000076500007650000000026110562747350017544 0ustar brianbrian00000000000000# $Id: pod.t 1895 2006-09-16 08:14:06Z comdog $ use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); Business-US-USPS-WebTools-1.11/t/pod_coverage.t0000644000076500007650000000035410562747350021422 0ustar brianbrian00000000000000#!/usr/bin/perl # $Id: pod_coverage.t 1895 2006-09-16 08:14:06Z comdog $ use Test::More; eval "use Test::Pod::Coverage 1.00"; plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@; all_pod_coverage_ok(); Business-US-USPS-WebTools-1.11/t/prereq.t0000644000076500007650000000036010562747350020260 0ustar brianbrian00000000000000#!/usr/bin/perl # $Id: prereq.t 1895 2006-09-16 08:14:06Z comdog $ use Test::More; eval "use Test::Prereq"; plan skip_all => "Test::Prereq required to test dependencies" if $@; prereq_ok(); Business-US-USPS-WebTools-1.11/t/test_manifest0000644000076500007650000000026010562747350021364 0ustar brianbrian00000000000000# $Id: test_manifest 1903 2006-09-26 21:21:40Z comdog $ #env.t load.t pod.t pod_coverage.t test_or_live.t #prereq.t address_verification.t zip_code_lookup.t city_state_lookup.tBusiness-US-USPS-WebTools-1.11/t/test_or_live.t0000644000076500007650000000273610562747350021471 0ustar brianbrian00000000000000# $Id: test_or_live.t 1903 2006-09-26 21:21:40Z comdog $ use Test::More 'no_plan'; my $class = "Business::US::USPS::WebTools"; use_ok( $class ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # { my $webtools = $class->new( { UserID => 'fake_user', Password => "this won't work", Testing => 1, } ); ok( $webtools->_testing, "I think I'm testing" ); is( ! $webtools->_live, 1, "I don't think I'm live!" ); is( $webtools->_api_host, "testing.shippingapis.com", "Testing host is right" ); is( $webtools->_api_path, "/ShippingAPITest.dll", "Testing path is right" ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # { my $webtools = $class->new( { UserID => 'fake_user', Password => "this won't work", Testing => 0, } ); ok( $webtools->_live, "I think I'm live" ); is( ! $webtools->_testing, 1, "I don't think I'm testing!" ); is( $webtools->_api_host, "production.shippingapis.com", "Live host is right" ); is( $webtools->_api_path, "/ShippingAPI.dll", "Testing path is right" ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Passing empty hash { my $webtools = $class->new( { UserID => 'fake_user', Password => "this won't work", } ); ok( $webtools->_live, "I think I'm live" ); is( ! $webtools->_testing, 1, "I don't think I'm testing!" ); is( $webtools->_api_host, "production.shippingapis.com", "Live host is right" ); is( $webtools->_api_path, "/ShippingAPI.dll", "Testing path is right" ); } Business-US-USPS-WebTools-1.11/t/zip_code_lookup.t0000644000076500007650000004373110562747350022160 0ustar brianbrian00000000000000#!/usr/bin/perl # $Id: zip_code_lookup.t 2122 2007-02-06 00:14:33Z comdog $ # See http://www.usps.com/webtools/htm/Address-Information.htm for # the test requirements. The headings ( "Good response #1", etc ) # correspond to the USPS test specification use Test::More; my $class = "Business::US::USPS::WebTools::ZipCodeLookup"; my $method = 'lookup_zipcode'; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # unless( $ENV{USPS_WEBTOOLS_USERID} and $ENV{USPS_WEBTOOLS_PASSWORD} ) { plan skip_all => "You must set the USPS_WEBTOOLS_USERID and USPS_WEBTOOLS_PASSWORD " . "environment variables to run these tests\n"; } else { plan tests => 109; } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # use_ok( $class ); my $verifier = $class->new( { UserID => $ENV{USPS_WEBTOOLS_USERID}, Password => $ENV{USPS_WEBTOOLS_PASSWORD}, Testing => 1, } ); isa_ok( $verifier, $class ); can_ok( $verifier, $method ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Good Request #1 { my $url = $verifier->_make_url( { FirmName => '', Address1 => '', Address2 => '6406 Ivy Lane', City => 'Greenbelt', State => 'MD', Zip5 => '', Zip4 => '', } ); is( $url, qq|http://testing.shippingapis.com/ShippingAPITest.dll?API=ZipCodeLookup&XML=%3CZipCodeLookupRequest+USERID%3D%22$ENV{USPS_WEBTOOLS_USERID}%22+PASSWORD%3D%22$ENV{USPS_WEBTOOLS_PASSWORD}%22%3E%3CAddress+ID%3D%220%22%3E%3CFirmName%3E%3C%2FFirmName%3E%3CAddress1%3E%3C%2FAddress1%3E%3CAddress2%3E6406+Ivy+Lane%3C%2FAddress2%3E%3CCity%3EGreenbelt%3C%2FCity%3E%3CState%3EMD%3C%2FState%3E%3C%2FAddress%3E%3C%2FZipCodeLookupRequest%3E|, "URL for Ivy Lane is correct", ); my $response = $verifier->_make_request; ok( defined $response ); ok( ! $verifier->is_error, "Response is not an error" ); my $expected = <<"XML";
6406 IVY LNGREENBELTMD207701440
XML is( $response, $expected ); my $hash = $verifier->_parse_response; is( $hash->{Address2}, '6406 IVY LN', 'Address2 matches for Ivy Lane' ); is( $hash->{City}, 'GREENBELT', 'City matches for Ivy Lane' ); is( $hash->{State}, 'MD', 'State matches for Ivy Lane' ); is( $hash->{Zip5}, '20770', 'Zip5 matches for Ivy Lane' ); is( $hash->{Zip4}, '1440', 'Zip4 matches for Ivy Lane' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Good request 2 { my $url = $verifier->_make_url( { FirmName => '', Address1 => '', Address2 => '8 Wildwood Drive', City => 'Old Lyme', State => 'CT', Zip5 => '06371', Zip4 => '', } ); is( $url, qq|http://testing.shippingapis.com/ShippingAPITest.dll?API=ZipCodeLookup&XML=%3CZipCodeLookupRequest+USERID%3D%22$ENV{USPS_WEBTOOLS_USERID}%22+PASSWORD%3D%22$ENV{USPS_WEBTOOLS_PASSWORD}%22%3E%3CAddress+ID%3D%220%22%3E%3CFirmName%3E%3C%2FFirmName%3E%3CAddress1%3E%3C%2FAddress1%3E%3CAddress2%3E8+Wildwood+Drive%3C%2FAddress2%3E%3CCity%3EOld+Lyme%3C%2FCity%3E%3CState%3ECT%3C%2FState%3E%3C%2FAddress%3E%3C%2FZipCodeLookupRequest%3E|, "URL for Wildwood Drive is correct", ); my $response = $verifier->_make_request; ok( defined $response ); ok( ! $verifier->is_error, "Response is not an error" ); my $expected = <<"XML";
8 WILDWOOD DROLD LYMECT063711844
XML is( $response, $expected ); my $hash = $verifier->_parse_response; is( $hash->{FirmName}, '', 'FirmName matches for Wildwood' ); is( $hash->{Address1}, '', 'Address1 matches for Wildwood' ); is( $hash->{Address2}, '8 WILDWOOD DR', 'Address2 matches for Wildwood' ); is( $hash->{City}, 'OLD LYME', 'City matches for Wildwood' ); is( $hash->{State}, 'CT', 'State matches for Wildwood' ); is( $hash->{Zip5}, '06371', 'Zip5 matches for Wildwood' ); is( $hash->{Zip4}, '1844', 'Zip4 matches for Wildwood' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Good request 3 { my $url = $verifier->_make_url( { FirmName => '', Address1 => '', Address2 => '4411 Romlon Street', City => 'Beltsville', State => 'MD', Zip5 => '', Zip4 => '', } ); is( $url, qq|http://testing.shippingapis.com/ShippingAPITest.dll?API=ZipCodeLookup&XML=%3CZipCodeLookupRequest+USERID%3D%22$ENV{USPS_WEBTOOLS_USERID}%22+PASSWORD%3D%22$ENV{USPS_WEBTOOLS_PASSWORD}%22%3E%3CAddress+ID%3D%220%22%3E%3CFirmName%3E%3C%2FFirmName%3E%3CAddress1%3E%3C%2FAddress1%3E%3CAddress2%3E4411+Romlon+Street%3C%2FAddress2%3E%3CCity%3EBeltsville%3C%2FCity%3E%3CState%3EMD%3C%2FState%3E%3C%2FAddress%3E%3C%2FZipCodeLookupRequest%3E|, "URL for Romlan Street is correct", ); my $response = $verifier->_make_request; ok( defined $response ); ok( ! $verifier->is_error, "Response is not an error" ); my $expected = <<"XML";
4411 ROMLON STBELTSVILLEMD207052425
XML is( $response, $expected ); my $hash = $verifier->_parse_response; is( $hash->{FirmName}, '', 'FirmName matches for Romlan' ); is( $hash->{Address1}, '', 'Address1 matches for Romlan' ); is( $hash->{Address2}, '4411 ROMLON ST', 'Address2 matches for Romlan' ); is( $hash->{City}, 'BELTSVILLE', 'City matches for Romlan' ); is( $hash->{State}, 'MD', 'State matches for Romlan' ); is( $hash->{Zip5}, '20705', 'Zip5 matches for Romlan' ); is( $hash->{Zip4}, '2425', 'Zip4 matches for Romlan' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Good request 4 { my $url = $verifier->_make_url( { FirmName => '', Address1 => '', Address2 => '3527 Sharonwood Road Apt. 3C', City => 'Laurel', State => 'MD', Zip5 => '', Zip4 => '', } ); is( $url, qq|http://testing.shippingapis.com/ShippingAPITest.dll?API=ZipCodeLookup&XML=%3CZipCodeLookupRequest+USERID%3D%22$ENV{USPS_WEBTOOLS_USERID}%22+PASSWORD%3D%22$ENV{USPS_WEBTOOLS_PASSWORD}%22%3E%3CAddress+ID%3D%220%22%3E%3CFirmName%3E%3C%2FFirmName%3E%3CAddress1%3E%3C%2FAddress1%3E%3CAddress2%3E3527+Sharonwood+Road+Apt.+3C%3C%2FAddress2%3E%3CCity%3ELaurel%3C%2FCity%3E%3CState%3EMD%3C%2FState%3E%3C%2FAddress%3E%3C%2FZipCodeLookupRequest%3E|, "URL for Sharonwood Road is correct", ); my $response = $verifier->_make_request; ok( defined $response ); ok( ! $verifier->is_error, "Response is not an error" ); my $expected = <<"XML";
3527 SHARONWOOD RD APT 3CLAURELMD207245920
XML is( $response, $expected ); my $hash = $verifier->_parse_response; is( $hash->{FirmName}, '', 'FirmName matches for Sharonwood' ); is( $hash->{Address1}, '', 'Address1 matches for Sharonwood' ); is( $hash->{Address2}, '3527 SHARONWOOD RD APT 3C', 'Address2 matches for Sharonwood' ); is( $hash->{City}, 'LAUREL', 'City matches for Sharonwood' ); is( $hash->{State}, 'MD', 'State matches for Sharonwood' ); is( $hash->{Zip5}, '20724', 'Zip5 matches for Sharonwood' ); is( $hash->{Zip4}, '5920', 'Zip4 matches for Sharonwood' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Error Requests # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Error response #1 { my $url = $verifier->_make_url( { FirmName => '', Address1 => '', Address2 => '3527 Sharonwood Road Apt. 3C', City => 'Wilmington', State => 'DE', Zip5 => '', Zip4 => '', } ); is( $url, qq|http://testing.shippingapis.com/ShippingAPITest.dll?API=ZipCodeLookup&XML=%3CZipCodeLookupRequest+USERID%3D%22$ENV{USPS_WEBTOOLS_USERID}%22+PASSWORD%3D%22$ENV{USPS_WEBTOOLS_PASSWORD}%22%3E%3CAddress+ID%3D%220%22%3E%3CFirmName%3E%3C%2FFirmName%3E%3CAddress1%3E%3C%2FAddress1%3E%3CAddress2%3E3527+Sharonwood+Road+Apt.+3C%3C%2FAddress2%3E%3CCity%3EWilmington%3C%2FCity%3E%3CState%3EDE%3C%2FState%3E%3C%2FAddress%3E%3C%2FZipCodeLookupRequest%3E|, "URL for Sharonwood Road Error is correct", ); my $response = $verifier->_make_request; ok( defined $response ); ok( $verifier->is_error, "Error request gets an error response" ); my $expected = <<"XML";
-2147219401SOLServerTest;SOLServerTest.CallAddressDllThat address could not be found.
XML is( $response, $expected ); is( $verifier->{error}{number}, -2147219401, 'Error number matches for Sharonwood error' ); is( $verifier->{error}{source}, 'SOLServerTest;SOLServerTest.CallAddressDll', 'Error source matches for Sharonwood error' ); is( $verifier->{error}{description}, 'That address could not be found.', 'Error description matches for Sharonwood error' ); is( $verifier->{error}{help_file}, '', 'Error help file matches for Sharonwood error' ); is( $verifier->{error}{help_context}, '', 'Error help context matches for Sharonwood error' ); my $hash = $verifier->_parse_response; is( $hash->{FirmName}, '', 'FirmName is empty for Sharonwood error' ); is( $hash->{Address1}, '', 'Address1 is empty for Sharonwood error' ); is( $hash->{Address2}, '', 'Address2 is empty for Sharonwood error' ); is( $hash->{City}, '', 'City is empty for Sharonwood error' ); is( $hash->{State}, '', 'State is empty for Sharonwood error' ); is( $hash->{Zip5}, '', 'Zip5 is empty for Sharonwood error' ); is( $hash->{Zip4}, '', 'Zip4 is empty for Sharonwood error' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # { my $url = $verifier->_make_url( { FirmName => '', Address1 => '', Address2 => '1600 Pennsylvania Avenue', City => 'Washington', State => 'DC', Zip5 => '', Zip4 => '', } ); is( $url, qq|http://testing.shippingapis.com/ShippingAPITest.dll?API=ZipCodeLookup&XML=%3CZipCodeLookupRequest+USERID%3D%22$ENV{USPS_WEBTOOLS_USERID}%22+PASSWORD%3D%22$ENV{USPS_WEBTOOLS_PASSWORD}%22%3E%3CAddress+ID%3D%220%22%3E%3CFirmName%3E%3C%2FFirmName%3E%3CAddress1%3E%3C%2FAddress1%3E%3CAddress2%3E1600+Pennsylvania+Avenue%3C%2FAddress2%3E%3CCity%3EWashington%3C%2FCity%3E%3CState%3EDC%3C%2FState%3E%3C%2FAddress%3E%3C%2FZipCodeLookupRequest%3E|, "URL for Pennsylvania Avenue Error is correct", ); my $response = $verifier->_make_request; ok( defined $response ); ok( $verifier->is_error, "Error request gets an error response" ); my $expected = <<"XML";
-2147219403SOLServerTest;SOLServerTest.CallAddressDllMultiple responses found. No default address.
XML is( $response, $expected ); is( $verifier->{error}{number}, -2147219403, 'Error number matches for Pennsylvania Avenue error' ); is( $verifier->{error}{source}, 'SOLServerTest;SOLServerTest.CallAddressDll', 'Error source matches for Pennsylvania Avenue error' ); is( $verifier->{error}{description}, 'Multiple responses found. No default address.', 'Error description matches for Pennsylvania Avenue error' ); is( $verifier->{error}{help_file}, '', 'Error help file matches for Pennsylvania Avenue error' ); is( $verifier->{error}{help_context}, '', 'Error help context matches for Pennsylvania Avenue error' ); my $hash = $verifier->_parse_response; # print STDERR "In _make_request:\n" . Dumper( $verifier ) . "\n"; is( $hash->{FirmName}, '', 'FirmName is empty for Pennsylvania Avenue error' ); is( $hash->{Address1}, '', 'Address1 is empty for Pennsylvania Avenue error' ); is( $hash->{Address2}, '', 'Address2 is empty for Pennsylvania Avenue error' ); is( $hash->{City}, '', 'City is empty for Pennsylvania Avenue error' ); is( $hash->{State}, '', 'State is empty for Pennsylvania Avenue error' ); is( $hash->{Zip5}, '', 'Zip5 is empty for Pennsylvania Avenue error' ); is( $hash->{Zip4}, '', 'Zip4 is empty for Pennsylvania Avenue error' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Error response #3 { my $url = $verifier->_make_url( { FirmName => '', Address1 => '', Address2 => '123 Main Street', City => 'Washington', State => 'ZZ', Zip5 => '', Zip4 => '', } ); is( $url, qq|http://testing.shippingapis.com/ShippingAPITest.dll?API=ZipCodeLookup&XML=%3CZipCodeLookupRequest+USERID%3D%22$ENV{USPS_WEBTOOLS_USERID}%22+PASSWORD%3D%22$ENV{USPS_WEBTOOLS_PASSWORD}%22%3E%3CAddress+ID%3D%220%22%3E%3CFirmName%3E%3C%2FFirmName%3E%3CAddress1%3E%3C%2FAddress1%3E%3CAddress2%3E123+Main+Street%3C%2FAddress2%3E%3CCity%3EWashington%3C%2FCity%3E%3CState%3EZZ%3C%2FState%3E%3C%2FAddress%3E%3C%2FZipCodeLookupRequest%3E|, "URL for Main Street Error is correct", ); my $response = $verifier->_make_request; ok( defined $response ); ok( $verifier->is_error, "Error request gets an error response" ); my $expected = <<"XML";
-2147219402SOLServerTest;SOLServerTest.CallAddressDllThat State is not valid.
XML is( $response, $expected ); is( $verifier->{error}{number}, -2147219402, 'Error number matches for Main Street error' ); is( $verifier->{error}{source}, 'SOLServerTest;SOLServerTest.CallAddressDll', 'Error source matches for Main Street error' ); is( $verifier->{error}{description}, 'That State is not valid.', 'Error description matches for Main Street error' ); is( $verifier->{error}{help_file}, '', 'Error help file matches for Main Street error' ); is( $verifier->{error}{help_context}, '', 'Error help context matches for Main Street error' ); my $hash = $verifier->_parse_response; # print STDERR "In _make_request:\n" . Dumper( $verifier ) . "\n"; is( $hash->{FirmName}, '', 'FirmName is empty for Main Street error' ); is( $hash->{Address1}, '', 'Address1 is empty for Main Street error' ); is( $hash->{Address2}, '', 'Address2 is empty for Main Street error' ); is( $hash->{City}, '', 'City is empty for Main Street error' ); is( $hash->{State}, '', 'State is empty for Main Street error' ); is( $hash->{Zip5}, '', 'Zip5 is empty for Main Street error' ); is( $hash->{Zip4}, '', 'Zip4 is empty for Main Street error' ); } # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Error response #4 { my $url = $verifier->_make_url( { FirmName => '', Address1 => '', Address2 => '123 Main Street', City => 'Trenton', State => 'NJ', Zip5 => '', Zip4 => '', } ); is( $url, qq|http://testing.shippingapis.com/ShippingAPITest.dll?API=ZipCodeLookup&XML=%3CZipCodeLookupRequest+USERID%3D%22$ENV{USPS_WEBTOOLS_USERID}%22+PASSWORD%3D%22$ENV{USPS_WEBTOOLS_PASSWORD}%22%3E%3CAddress+ID%3D%220%22%3E%3CFirmName%3E%3C%2FFirmName%3E%3CAddress1%3E%3C%2FAddress1%3E%3CAddress2%3E123+Main+Street%3C%2FAddress2%3E%3CCity%3ETrenton%3C%2FCity%3E%3CState%3ENJ%3C%2FState%3E%3C%2FAddress%3E%3C%2FZipCodeLookupRequest%3E|, "URL for Trenton, NJ Error is correct", ); my $response = $verifier->_make_request; ok( defined $response ); ok( $verifier->is_error, "Error request gets an error response" ); my $expected = <<"XML";
-2147219400SOLServerTest;SOLServerTest.CallAddressDllThat is not a valid city.
XML is( $response, $expected ); is( $verifier->{error}{number}, -2147219400, 'Error number matches for Trenton, NJ error' ); is( $verifier->{error}{source}, 'SOLServerTest;SOLServerTest.CallAddressDll', 'Error source matches for Trenton, NJ error' ); is( $verifier->{error}{description}, 'That is not a valid city.', 'Error description matches for Trenton, NJ error' ); is( $verifier->{error}{help_file}, '', 'Error help file matches for Trenton, NJ error' ); is( $verifier->{error}{help_context}, '', 'Error help context matches for Trenton, NJ error' ); my $hash = $verifier->_parse_response; # print STDERR "In _make_request:\n" . Dumper( $verifier ) . "\n"; is( $hash->{FirmName}, '', 'FirmName is empty for Trenton, NJ error' ); is( $hash->{Address1}, '', 'Address1 is empty for Trenton, NJ error' ); is( $hash->{Address2}, '', 'Address2 is empty for Trenton, NJ error' ); is( $hash->{City}, '', 'City is empty for Trenton, NJ error' ); is( $hash->{State}, '', 'State is empty for Trenton, NJ error' ); is( $hash->{Zip5}, '', 'Zip5 is empty for Trenton, NJ error' ); is( $hash->{Zip4}, '', 'Zip4 is empty for Trenton, NJ error' ); } __END__