]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Zips.pm
LP#1187035 Remove OpenILS::Utils::Editor part 2.
[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 OpenSRF::Utils::SettingsClient;
9
10 use open ':utf8';
11
12 my %zips;
13
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 # -----------------------------------------------------------------
20
21 sub initialize {
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;
26
27     $logger->info("search loaded zips file $zfile");
28     open(F,$zfile);
29     my @data = <F>;
30     close(F);
31
32     for(@data) {
33         chomp $_;
34         my @items = split(/\|/, "$_");
35         my $items = {
36             state       => $items[1],
37             city        => $items[2],
38             zip     => $items[3],
39             stateid => $items[5],
40             county  => $items[6],
41             areacode    => $items[7],
42             alert   => $items[8]
43         };
44
45         next unless $items[4] eq '1';
46         $zips{$$items{zip}} = $items;
47     }
48 }
49
50 __PACKAGE__->register_method(
51     method => 'search_zip',
52     api_name    => 'open-ils.search.zip',
53     signature   => q/
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
60     /
61 );
62 sub search_zip {
63     my( $self, $conn, $zip ) = @_;
64     $zip =~ s/(^\d{5}).*/$1/; # we don't care about the last 4 digits if they exist 
65     return $zips{$zip};
66 }
67
68 1;