allow omitting state/city or zip
authorMark Wells <mark@freeside.biz>
Wed, 4 Mar 2015 21:15:22 +0000 (13:15 -0800)
committerMark Wells <mark@freeside.biz>
Wed, 4 Mar 2015 21:15:22 +0000 (13:15 -0800)
Geocoding.pm

index 04605ad..b1f3ea7 100644 (file)
@@ -29,9 +29,9 @@ our $DEBUG = 0;
       # required fields
       street  => '123 Main Street',
       city    => 'San Francisco',   # city
       # required fields
       street  => '123 Main Street',
       city    => 'San Francisco',   # city
-      state   => 'CA',              # state/province
-      zip     => '93102',           # zip/postal code
+      state   => 'CA',              # state
       # optional fields
       # optional fields
+      zip     => '93102',           # zip code
       benchmark => 'Public_AR_ACS2013', # default is "Public_AR_Current"
       vintage   => 'Census2010_ACS2013', # default is "Current_Current"
 
       benchmark => 'Public_AR_ACS2013', # default is "Public_AR_Current"
       vintage   => 'Census2010_ACS2013', # default is "Current_Current"
 
@@ -89,12 +89,16 @@ sub query {
 
   my @row = ( 1 ); # first element = row identifier
   # at some point support multiple rows in a single query?
 
   my @row = ( 1 ); # first element = row identifier
   # at some point support multiple rows in a single query?
+  if (!$opt{street}) {
+    $result->error_message("Street address is required.");
+    return $result;
+  }
+  if (!$opt{zip} and (!$opt{city} or !$opt{state})) {
+    $result->error_message("Either city/state or zip code is required.");
+    return $result;
+  }
   foreach (qw(street city state zip)) {
   foreach (qw(street city state zip)) {
-    if (!length($opt{$_})) {
-      $result->error_message("$_ required");
-      return $result;
-    }
-    push @row, $opt{$_};
+    push @row, $opt{$_} || '';
   }
 
   $csv->combine(@row);
   }
 
   $csv->combine(@row);