]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Zips.pm
Post-2.5-m1 whitespace fixup
[working/Evergreen.git] / Open-ILS / src / perlmods / lib / 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             alert   => $items[8]
42         };
43
44         next unless $items[4] eq '1';
45         $zips{$$items{zip}} = $items;
46     }
47 }
48
49 __PACKAGE__->register_method(
50     method => 'search_zip',
51     api_name    => 'open-ils.search.zip',
52     signature   => q/
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
59     /
60 );
61 sub search_zip {
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 
68     return $zips{$zip};
69 }
70
71 1;