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 OpenILS::Utils::Editor;
9 use OpenSRF::Utils::SettingsClient;
13 # -----------------------------------------------------------------
14 # Reads zip code information from a file. File format is :
15 # ID|StateAbb|City|Zip|IsDefault|StateID|County|AreaCode
16 # Currently, StateAbb, City, Zip, County, AreaCode are used.
17 # IsDefault should be set to 1
18 # -----------------------------------------------------------------
21 my $conf = OpenSRF::Utils::SettingsClient->new;
22 my $zfile = $conf->config_value(
23 "apps", "open-ils.search", "app_settings", "zips_file");
24 return 1 unless $zfile and -f $zfile;
26 $logger->info("search loaded zips file $zfile");
33 my @items = split(/\|/, "$_");
40 areacode => $items[7],
44 next unless $items[4] eq '1';
45 $zips{$$items{zip}} = $items;
49 __PACKAGE__->register_method(
50 method => 'search_zip',
51 api_name => 'open-ils.search.zip',
53 Given a zip code, returns address info for the zip code
54 @param auth the login session key
55 @param zip The zip code to check
56 @return On success, returns an object of the form:
57 { state=>, city=>, zip=>, stateid=>, county=>, areacode=>}
58 returns event on error
62 #my( $self, $conn, $auth, $zip ) = @_;
63 #my $e = OpenILS::Utils::Editor->new(authtoken=>$auth);
64 #return $e->event unless $e->checkauth;
65 #return $e->event unless $e->allowed('VIEW_ZIP_DATA');
66 my( $self, $conn, $zip ) = @_;
67 $zip =~ s/(^\d{5}).*/$1/; # we don't care about the last 4 digits if they exist