diff options
author | Mark Wells <mark@freeside.biz> | 2013-12-19 12:16:56 -0800 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2013-12-19 12:16:56 -0800 |
commit | 73c19b415a4e227b968b8e6150de4d9dfae73385 (patch) | |
tree | 7d1c71f2f9f0a2e8fbd7b14f755d06afb19b2d76 /FS/FS/Misc/Geo.pm | |
parent | cae0ba8600fcaf18e5bc347b09520d2ac4c86ae5 (diff) |
Melissa Data address standardization, #25557
Diffstat (limited to 'FS/FS/Misc/Geo.pm')
-rw-r--r-- | FS/FS/Misc/Geo.pm | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/FS/FS/Misc/Geo.pm b/FS/FS/Misc/Geo.pm index 9f6b89bf2..1af499152 100644 --- a/FS/FS/Misc/Geo.pm +++ b/FS/FS/Misc/Geo.pm @@ -652,6 +652,57 @@ sub subloc_address2 { ($subloc, $addr2); } +sub standardize_melissa { + my $class = shift; + my $location = shift; + + local $@; + eval "use Geo::Melissa::WebSmart"; + die $@ if $@; + + my $id = $conf->config('melissa-userid') + or die "no melissa-userid configured\n"; + my $geocode = $conf->exists('melissa-enable_geocoding') ? 1 : 0; + + my $request = { + id => $id, + a1 => $location->{address1}, + a2 => $location->{address2}, + city => $location->{city}, + state => $location->{state}, + ctry => $location->{country}, + zip => $location->{zip}, + geocode => $geocode, + }; + my $result = Geo::Melissa::WebSmart->query($request); + if ( $result->code =~ /AS01/ ) { # always present on success + my $addr = $result->address; + warn Dumper $addr if $DEBUG > 1; + my $out = { + address1 => $addr->{Address1}, + address2 => $addr->{Address2}, + city => $addr->{City}->{Name}, + state => $addr->{State}->{Abbreviation}, + country => $addr->{Country}->{Abbreviation}, + zip => $addr->{Zip}, + latitude => $addr->{Latitude}, + longitude => $addr->{Longitude}, + addr_clean => 'Y', + }; + if ( $addr->{Census}->{Tract} ) { + my $censustract = $addr->{County}->{Fips} . $addr->{Census}->{Tract}; + # insert decimal point two digits from the end + $censustract =~ s/(\d\d)$/\.$1/; + $out->{censustract} = $censustract; + $out->{censusyear} = $conf->config('census_year'); + } + # we could do a lot more nuanced reporting of the warning/status codes, + # but the UI doesn't support that yet. + return $out; + } else { + die $result->status_message; + } +} =back |