]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Search/Zips.pm
more staged search configurability and acuracy
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Search / Zips.pm
1 package OpenILS::Application::Search::Zips;
2 use base qw/OpenILS::Application/;
3 use strict; use warnings;
4
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;
10
11 my %zips;
12
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 # -----------------------------------------------------------------
19
20 sub initialize {
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;
25
26         $logger->info("search loaded zips file $zfile");
27         open(F,$zfile);
28         my @data = <F>;
29         close(F);
30
31         for(@data) {
32                 chomp $_;
33                 my @items = split(/\|/, "$_");
34                 my $items = {
35                         state           => $items[1],
36                         city            => $items[2],
37                         zip             => $items[3],
38                         stateid => $items[5],
39                         county  => $items[6],
40                         areacode        => $items[7],
41                 };
42
43                 next unless $items[4] eq '1';
44                 $zips{$$items{zip}} = $items;
45         }
46 }
47
48 __PACKAGE__->register_method(
49         method => 'search_zip',
50         api_name        => 'open-ils.search.zip',
51         signature       => q/
52                 Given a zip code, returns address info for the zip code
53                 @param auth the login session key
54                 @param zip The zip code to check
55                 @return On success, returns an object of the form:
56                 { state=>, city=>, zip=>, stateid=>, county=>, areacode=>}
57                 returns event on error
58         /
59 );
60 sub search_zip {
61         #my( $self, $conn, $auth, $zip ) = @_;
62         #my $e = OpenILS::Utils::Editor->new(authtoken=>$auth);
63         #return $e->event unless $e->checkauth;
64         #return $e->event unless $e->allowed('VIEW_ZIP_DATA');
65         my( $self, $conn, $zip ) = @_;
66         $zip =~ s/(^\d{5}).*/$1/; # we don't care about the last 4 digits if they exist 
67         return $zips{$zip};
68 }
69
70 1;