Skip to content

Commit

Permalink
Added include and exclude parameters for the US Address Enrichment API
Browse files Browse the repository at this point in the history
  • Loading branch information
smartyeric committed Dec 16, 2024
1 parent ed0aacf commit 6923e76
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
13 changes: 13 additions & 0 deletions examples/USEnrichmentExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ public function run()
$lookup->setState("NJ");
$lookup->setZipcode("08876");

// Use the setIncludeArray function to set the include or exclude parameter using an existing array:
// $tempArray = array("assessed_improvement_percent", "assessed_improvement_value");
// $lookup->setIncludeArray($tempArray);
// OR
// $lookup->setExcludeArray($tempArray);

// Or use the addIncludeAttributes function to set the attributes you would like to include or exclude one by one:
// $lookup->addIncludeAttribute("assessed_improvement_percent");
// $lookup->addIncludeAttribute("assessed_improvement_value");
// OR
// $lookup->addExcludeAttribute("assessed_improvement_percent");
// $lookup->addExcludeAttribute("assessed_improvement_value");

// Uncomment the below line to add a custom parameter to the API call
// $lookup->addCustomParameter("parameter", "value");

Expand Down
10 changes: 10 additions & 0 deletions src/US_Enrichment/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ private function buildRequest(Lookup $lookup) {
$request->setParameter("zipcode", $lookup->getZipcode());
}

$request->setParameter("include", $this->buildFilterString($lookup->getIncludeArray()));
$request->setParameter("exclude", $this->buildFilterString($lookup->getExcludeArray()));

foreach ($lookup->getCustomParamArray() as $key => $value) {
$request->setParameter($key, $value);
}
Expand All @@ -178,4 +181,11 @@ private function getUrlPrefix($lookup){
return $lookup->getSmartyKey() . "/" . $lookup->getDataSetName() . "/" . $lookup->getDataSubsetName();
}
}

private function buildFilterString($list) {
if (empty($list))
return null;

return join(',', $list);
}
}
30 changes: 29 additions & 1 deletion src/US_Enrichment/Lookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ class Lookup {
$zipcode,
$dataSetName,
$dataSubsetName,
$include,
$exclude,
$response,
$customParamArray;

//endregion

public function __construct($smartyKey = null, $dataSetName = null, $dataSubsetName = null, $freeform = null, $street = null, $city = null, $state = null,
$zipcode = null) {
$zipcode = null, $include = null, $exclude = null) {
$this->smartyKey = $smartyKey;
$this->dataSetName = $dataSetName;
$this->dataSubsetName = $dataSubsetName;
Expand All @@ -29,6 +31,8 @@ public function __construct($smartyKey = null, $dataSetName = null, $dataSubsetN
$this->city = $city;
$this->state = $state;
$this->zipcode = $zipcode;
$this->include = array();
$this->exclude = array();
$this->response = null;
$this->customParamArray = array();
}
Expand Down Expand Up @@ -64,6 +68,14 @@ public function getDataSetName(){
public function getDataSubsetName(){
return $this->dataSubsetName;
}

public function getIncludeArray() {
return $this->include;
}

public function getExcludeArray() {
return $this->exclude;
}

public function getResponse() {
return $this->response;
Expand Down Expand Up @@ -105,10 +117,26 @@ public function setZipcode($zipcode){
$this->zipcode = $zipcode;
}

public function setIncludeArray($include) {
$this->include = $include;
}

public function setExcludeArray($exclude) {
$this->exclude = $exclude;
}

public function setResponse($response){
$this->response = $response;
}

public function addIncludeAttribute($attribute) {
array_push($this->include, $attribute);
}

public function addExcludeAttribute($attribute) {
array_push($this->exclude, $attribute);
}

public function addCustomParameter($parameter, $value) {
$this->customParamArray[$parameter] = $value;
}
Expand Down

0 comments on commit 6923e76

Please sign in to comment.