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