Skip to content

Commit

Permalink
Added Secondary and Secondary Count endpoints for the US Address Enri…
Browse files Browse the repository at this point in the history
…chment API
  • Loading branch information
smartyeric committed Aug 2, 2024
1 parent eae24e3 commit 84ff5b4
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 15 deletions.
12 changes: 12 additions & 0 deletions src/US_Enrichment/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ public function sendGeoReferenceLookup($smartyKey){
return $lookup->getResponse();
}

public function sendSecondaryLookup($smartyKey){
$lookup = new Lookup($smartyKey, "secondary", null);
$this->sendLookup($lookup);
return $lookup->getResponse();
}

public function sendSecondaryCountLookup($smartyKey){
$lookup = new Lookup($smartyKey, "secondary", "count");
$this->sendLookup($lookup);
return $lookup->getResponse();
}

public function sendGenericLookup($smartyKey, $dataSetName, $dataSubsetName){
$lookup = new Lookup($smartyKey, $dataSetName, $dataSubsetName);
$this->sendLookup($lookup);
Expand Down
21 changes: 10 additions & 11 deletions src/US_Enrichment/GeoReferenceAttributes.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
namespace SmartyStreets\PhpSdk\US_Enrichment;

use PSpell\Dictionary;
use SmartyStreets\PhpSdk\ArrayUtil;

require_once(dirname(dirname(__FILE__)) . '/US_Enrichment/GeoReference/CensusBlockEntry.php');
Expand Down Expand Up @@ -38,23 +37,23 @@ public function __construct($obj = null) {
$this->createPlace(ArrayUtil::setField($obj, "place"));
}

private function createCensusBlock($censusBlockArray){
$this->censusBlock = new CensusBlockEntry($censusBlockArray);
private function createCensusBlock($censusBlock){
$this->censusBlock = new CensusBlockEntry($censusBlock);
}

private function createCensusCountyDivision($censusCountyDivisionArray){
$this->censusCountyDivision = new CensusCountyDivisionEntry($censusCountyDivisionArray);
private function createCensusCountyDivision($censusCountyDivision){
$this->censusCountyDivision = new CensusCountyDivisionEntry($censusCountyDivision);
}

private function createCensusTract($censusTractArray){
$this->censusTract = new CensusTractEntry($censusTractArray);
private function createCensusTract($censusTract){
$this->censusTract = new CensusTractEntry($censusTract);
}

private function createCoreBasedStatArea($coreBasedStatAreaArray){
$this->coreBasedStatArea = new CoreBasedStatAreaEntry($coreBasedStatAreaArray);
private function createCoreBasedStatArea($coreBasedStatArea){
$this->coreBasedStatArea = new CoreBasedStatAreaEntry($coreBasedStatArea);
}

private function createPlace($placeArray){
$this->place = new PlaceEntry($placeArray);
private function createPlace($place){
$this->place = new PlaceEntry($place);
}
}
39 changes: 35 additions & 4 deletions src/US_Enrichment/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
require_once('FinancialAttributes.php');
require_once('PrincipalAttributes.php');
require_once('GeoReferenceAttributes.php');
require_once('SecondaryAttributes.php');
require_once('SecondaryCountAttributes.php');
use SmartyStreets\PhpSdk\ArrayUtil;


Expand All @@ -16,17 +18,35 @@ class Result {
public $smartyKey,
$dataSetName,
$dataSubsetName,
$attributes;
$attributes,
$rootAddress,
$aliases,
$secondaries,
$count;

//endregion

public function __construct($obj = null) {
if ($obj == null)
return;
$this->smartyKey = ArrayUtil::setField($obj, 'smarty_key');
$this->dataSetName = ArrayUtil::setField($obj, 'data_set_name');
$this->dataSubsetName = ArrayUtil::setField($obj, 'data_subset_name');
$this->attributes = $this->createAttributes($this->dataSetName, $this->dataSubsetName, ArrayUtil::setField($obj, 'attributes'));
if (array_key_exists('data_set_name', $obj)) {
$this->dataSetName = ArrayUtil::setField($obj, 'data_set_name');
$this->dataSubsetName = ArrayUtil::setField($obj, 'data_subset_name');
$this->attributes = $this->createAttributes($this->dataSetName, $this->dataSubsetName, ArrayUtil::setField($obj, 'attributes'));
}
else {
if (array_key_exists('secondaries', $obj)) {
$this->dataSetName = 'secondary';
$this->dataSubsetName = null;
$this->createSecondaryData($obj, $this->dataSubsetName);
}
else if (array_key_exists('count', $obj)) {
$this->dataSetName = 'secondary';
$this->dataSubsetName = 'count';
$this->createSecondaryData($obj, $this->dataSubsetName);
}
}
}

private function createAttributes($dataSetName, $dataSubsetName, $attributesObj){
Expand All @@ -42,4 +62,15 @@ private function createAttributes($dataSetName, $dataSubsetName, $attributesObj)
return new GeoReferenceAttributes($attributesObj);
}
}

private function createSecondaryData($responseObj, $dataSubsetName) {
if ($dataSubsetName = 'count'){
$attributes = new SecondaryCountAttributes($responseObj);
$this->count = $attributes->count;
}
$attributes = new SecondaryAttributes($responseObj);
$this->rootAddress = $attributes->rootAddress;
$this->aliases[] = $attributes->aliases;
$this->secondaries[] = $attributes->secondaries;
}
}
36 changes: 36 additions & 0 deletions src/US_Enrichment/Secondary/AliasesEntry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace SmartyStreets\PhpSdk\US_Enrichment\Secondary;
use SmartyStreets\PhpSdk\ArrayUtil;

class AliasesEntry {
//region [ Fields ]

public $smartyKey,
$primaryNumber,
$streetPredirection,
$streetName,
$streetSuffix,
$streetPostdirection,
$cityName,
$stateAbbreviation,
$zipcode,
$plus4Code;

//endregion

public function __construct($obj = null){
if ($obj == null)
return;
$this->smartyKey = ArrayUtil::setField($obj, "smarty_key");
$this->primaryNumber = ArrayUtil::setField($obj, "primary_number");
$this->streetPredirection = ArrayUtil::setField($obj, "street_predirection");
$this->streetName = ArrayUtil::setField($obj, "street_name");
$this->streetSuffix = ArrayUtil::setField($obj, "street_suffix");
$this->streetPostdirection = ArrayUtil::setField($obj, "street_postdirection");
$this->cityName = ArrayUtil::setField($obj, "city_name");
$this->stateAbbreviation = ArrayUtil::setField($obj, "state_abbreviation");
$this->zipcode = ArrayUtil::setField($obj, "zipcode");
$this->plus4Code = ArrayUtil::setField($obj, "plus4_code");
}
}
38 changes: 38 additions & 0 deletions src/US_Enrichment/Secondary/RootAddressEntry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace SmartyStreets\PhpSdk\US_Enrichment\Secondary;
use SmartyStreets\PhpSdk\ArrayUtil;

class RootAddressEntry {
//region [ Fields ]

public $secondaryCount,
$smartyKey,
$primaryNumber,
$streetPredirection,
$streetName,
$streetSuffix,
$streetPostdirection,
$cityName,
$stateAbbreviation,
$zipcode,
$plus4Code;

//endregion

public function __construct($obj = null){
if ($obj == null)
return;
$this->secondaryCount = ArrayUtil::setField($obj, "secondary_count");
$this->smartyKey = ArrayUtil::setField($obj, "smarty_key");
$this->primaryNumber = ArrayUtil::setField($obj, "primary_number");
$this->streetPredirection = ArrayUtil::setField($obj, "street_predirection");
$this->streetName = ArrayUtil::setField($obj, "street_name");
$this->streetSuffix = ArrayUtil::setField($obj, "street_suffix");
$this->streetPostdirection = ArrayUtil::setField($obj, "street_postdirection");
$this->cityName = ArrayUtil::setField($obj, "city_name");
$this->stateAbbreviation = ArrayUtil::setField($obj, "state_abbreviation");
$this->zipcode = ArrayUtil::setField($obj, "zipcode");
$this->plus4Code = ArrayUtil::setField($obj, "plus4_code");
}
}
24 changes: 24 additions & 0 deletions src/US_Enrichment/Secondary/SecondariesEntry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace SmartyStreets\PhpSdk\US_Enrichment\Secondary;
use SmartyStreets\PhpSdk\ArrayUtil;

class SecondariesEntry {
//region [ Fields ]

public $smartyKey,
$secondaryDesignator,
$secondaryNumber,
$plus4Code;

//endregion

public function __construct($obj = null){
if ($obj == null)
return;
$this->smartyKey = ArrayUtil::setField($obj, "smarty_key");
$this->secondaryDesignator = ArrayUtil::setField($obj, "secondary_designator");
$this->secondaryNumber = ArrayUtil::setField($obj, "secondary_number");
$this->plus4Code = ArrayUtil::setField($obj, "plus4_code");
}
}
47 changes: 47 additions & 0 deletions src/US_Enrichment/SecondaryAttributes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
namespace SmartyStreets\PhpSdk\US_Enrichment;

use SmartyStreets\PhpSdk\ArrayUtil;

require_once(dirname(dirname(__FILE__)) . '/US_Enrichment/Secondary/RootAddressEntry.php');
require_once(dirname(dirname(__FILE__)) . '/US_Enrichment/Secondary/AliasesEntry.php');
require_once(dirname(dirname(__FILE__)) . '/US_Enrichment/Secondary/SecondariesEntry.php');

use SmartyStreets\PhpSdk\US_Enrichment\Secondary\RootAddressEntry;
use SmartyStreets\PhpSdk\US_Enrichment\Secondary\AliasesEntry;
use SmartyStreets\PhpSdk\US_Enrichment\Secondary\SecondariesEntry;

class SecondaryAttributes {

//region [ Fields ]

public $rootAddress,
$aliases,
$secondaries;

//endregion

public function __construct($obj = null) {
if ($obj == null)
return;
$this->createRootAddress(ArrayUtil::setField($obj, "root_address"));
$this->createAliases(ArrayUtil::setField($obj, "aliases"));
$this->createSecondaries(ArrayUtil::setField($obj, "secondaries"));
}

private function createRootAddress($rootAddress){
$this->rootAddress = new RootAddressEntry($rootAddress);
}

private function createAliases($aliasesArray){
foreach($aliasesArray as $value){
$this->aliases = new AliasesEntry($value);
}
}

private function createSecondaries($secondariesArray){
foreach($secondariesArray as $value){
$this->secondaries = new SecondariesEntry($value);
}
}
}
19 changes: 19 additions & 0 deletions src/US_Enrichment/SecondaryCountAttributes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
namespace SmartyStreets\PhpSdk\US_Enrichment;

use SmartyStreets\PhpSdk\ArrayUtil;

class SecondaryCountAttributes {

//region [ Fields ]

public $count;

//endregion

public function __construct($obj = null) {
if ($obj == null)
return;
$this->count = ArrayUtil::setField($obj, "count");
}
}

0 comments on commit 84ff5b4

Please sign in to comment.