1 package OpenILS::Application::Search::Zips;
2 use base qw/OpenILS::Application/;
3 use strict; use warnings;
5 use OpenSRF::EX qw(:try);
6 use OpenSRF::Utils::Logger qw/$logger/;
7 use OpenILS::Application::AppUtils;
8 use OpenSRF::Utils::SettingsClient;
14 # -----------------------------------------------------------------
15 # Reads zip code information from a file. File format is :
16 # ID|StateAbb|City|Zip|IsDefault|StateID|County|AreaCode
17 # Currently, StateAbb, City, Zip, County, AreaCode are used.
18 # IsDefault should be set to 1
19 # -----------------------------------------------------------------
22 my $conf = OpenSRF::Utils::SettingsClient->new;
23 my $zfile = $conf->config_value(
24 "apps", "open-ils.search", "app_settings", "zips_file");
25 return 1 unless $zfile and -f $zfile;
27 $logger->info("search loaded zips file $zfile");
34 my @items = split(/\|/, "$_");
41 areacode => $items[7],
45 next unless $items[4] eq '1';
46 $zips{$$items{zip}} = $items;
50 __PACKAGE__->register_method(
51 method => 'search_zip',
52 api_name => 'open-ils.search.zip',
54 Given a zip code, returns address info for the zip code
55 @param auth the login session key
56 @param zip The zip code to check
57 @return On success, returns an object of the form:
58 { state=>, city=>, zip=>, stateid=>, county=>, areacode=>}
59 returns event on error
63 my( $self, $conn, $zip ) = @_;
64 $zip =~ s/(^\d{5}).*/$1/; # we don't care about the last 4 digits if they exist