[freeside-commits] branch FREESIDE_3_BRANCH updated. ab8c55215658db8a41f00c5b36fad95c4bceb6a1

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


The branch, FREESIDE_3_BRANCH has been updated
       via  ab8c55215658db8a41f00c5b36fad95c4bceb6a1 (commit)
      from  a8aa6fdd7c54ecf1be881ba0b37e1927bf1eb4ae (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 ab8c55215658db8a41f00c5b36fad95c4bceb6a1
Author: Mark Wells <mark at freeside.biz>
Date:   Wed Mar 4 13:26:41 2015 -0800

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

diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index d7b0bb9..3b9a291 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -4440,6 +4440,7 @@ and customer address. Include units.',
     'type'        => 'select',
     'select_hash' => [ '' => '', 
                        'usps'     => 'U.S. Postal Service',
+                       'uscensus' => 'U.S. Census Bureau',
                        'ezlocate' => 'EZLocate',
                        'tomtom'   => 'TomTom',
                        'melissa'  => 'Melissa WebSmart',
diff --git a/FS/FS/Misc/Geo.pm b/FS/FS/Misc/Geo.pm
index e7b1fa8..009621b 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) #######
+
 my %ezlocate_error = ( # USA_Geo_002 documentation
   10  => 'State not found',
   11  => 'City not found',

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

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