[freeside-commits] branch master updated. 33f5c81279e1de9afd97adb1872c1b11caf7f6f9

Mark Wells mark at 420.am
Wed Mar 4 13:29:17 PST 2015


The branch, master has been updated
       via  33f5c81279e1de9afd97adb1872c1b11caf7f6f9 (commit)
      from  fec65a77360f792a868e51c68c41885b59e62608 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 33f5c81279e1de9afd97adb1872c1b11caf7f6f9
Author: Mark Wells <mark at freeside.biz>
Date:   Wed Mar 4 13:29:07 2015 -0800

    add support for U.S. Census geocoding, #32250

diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 479e9ab..d5e8960 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -4440,6 +4440,7 @@ and customer address. Include units.',
     'section'     => 'invoicing',
     'description' => 'Instead of showing payments (and credits) applied to the invoice, show those received since the previous invoice date.',
     'type'        => 'checkbox',
+                       'uscensus' => 'U.S. Census Bureau',
   },
 
   {
diff --git a/FS/FS/Misc/Geo.pm b/FS/FS/Misc/Geo.pm
index dbc383a..1e17b5f 100644
--- a/FS/FS/Misc/Geo.pm
+++ b/FS/FS/Misc/Geo.pm
@@ -236,6 +236,8 @@ sub wa_sales {
   die "WA tax district lookup error: $error";
 }
 
+###### USPS Standardization ######
+
 sub standardize_usps {
   my $class = shift;
 
@@ -292,6 +294,55 @@ sub standardize_usps {
     addr_clean=> 'Y' }
 }
 
+###### U.S. Census Bureau ######
+
+sub standardize_uscensus {
+  my $self = shift;
+  my $location = shift;
+
+  eval "use Geo::USCensus::Geocoding";
+  die $@ if $@;
+
+  if ( $location->{country} ne 'US' ) {
+    # soft failure
+    warn "standardize_uscensus not for use in country ".$location->{country}."\n";
+    $location->{addr_clean} = '';
+    return $location;
+  }
+
+  my $request = {
+    street  => $location->{address1},
+    city    => $location->{city},
+    state   => $location->{state},
+    zip     => $location->{zip},
+    debug   => ($DEBUG || 0),
+  };
+
+  my $result = Geo::USCensus::Geocoding->query($request);
+  if ( $result->is_match ) {
+    # unfortunately we get the address back as a single line
+    if ($result->address =~ /^(.*), (.*), ([A-Z]{2}), (\d{5}.*)$/) {
+      return +{
+        address1    => $1,
+        city        => $2,
+        state       => $3,
+        zip         => $4,
+        address2    => uc($location->{address2}),
+        latitude    => $result->latitude,
+        longitude   => $result->longitude,
+        censustract => $result->censustract,
+      };
+    } else {
+      die "can't parse address '".$result->address."'";
+    }
+  } else {
+    warn Dumper($result) if $DEBUG;
+    die $result->error_message;
+  }
+}
+
+####### EZLOCATE (obsolete) #######
+
 sub _tomtom_query { # helper method for the below
   my %args = @_;
   my $result = Geo::TomTom::Geocoding->query(%args);

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Conf.pm     |    1 +
 FS/FS/Misc/Geo.pm |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)




More information about the freeside-commits mailing list