From 088a428aaa15a2cb8057e6748fb840a33eb070fa Mon Sep 17 00:00:00 2001 From: Eric Devenport Date: Tue, 10 Dec 2024 16:31:28 -0700 Subject: [PATCH 1/5] Added custom parameter option for all APIs Added county_source parameter for the US Street Address API --- examples/InternationalAutocompleteExample.php | 3 ++ examples/InternationalExample.php | 3 ++ examples/USAutocompleteProExample.php | 3 ++ examples/USEnrichmentExample.php | 3 ++ examples/USExtractExample.php | 3 ++ examples/USReverseGeoExample.php | 3 ++ ...StreetLookupsWithMatchStrategyExamples.php | 3 ++ examples/UsStreetMultipleAddressesExample.php | 3 ++ examples/UsStreetSingleAddressExample.php | 4 ++ examples/UsZIPCodeMultipleLookupsExample.php | 3 ++ examples/UsZIPCodeSingleLookupExample.php | 3 ++ src/International_Autocomplete/Client.php | 4 ++ src/International_Autocomplete/Lookup.php | 12 ++++- src/International_Street/Client.php | 4 ++ src/International_Street/Lookup.php | 12 ++++- src/US_Autocomplete_Pro/Client.php | 4 ++ src/US_Autocomplete_Pro/Lookup.php | 13 ++++- src/US_Enrichment/Client.php | 5 ++ src/US_Enrichment/Lookup.php | 12 ++++- src/US_Extract/Client.php | 4 ++ src/US_Extract/Lookup.php | 12 ++++- src/US_Reverse_Geo/Client.php | 4 ++ src/US_Reverse_Geo/Lookup.php | 18 +++++-- src/US_Street/Lookup.php | 47 ++++++++++++++++++- src/US_ZIPCode/Lookup.php | 17 ++++++- 25 files changed, 190 insertions(+), 12 deletions(-) diff --git a/examples/InternationalAutocompleteExample.php b/examples/InternationalAutocompleteExample.php index 5adf023..be205c5 100644 --- a/examples/InternationalAutocompleteExample.php +++ b/examples/InternationalAutocompleteExample.php @@ -36,6 +36,9 @@ public function run() { $lookup->setCountry("FRA"); $lookup->setLocality("Paris"); + // Uncomment the below line to add a custom parameter to the API call + // $lookup->addCustomParameter("parameter", "value"); + try { $client->sendLookup($lookup); // The candidates are also stored in the lookup's 'result' field. foreach ($lookup->getResult() as $candidate) { diff --git a/examples/InternationalExample.php b/examples/InternationalExample.php index 495631d..a88162d 100644 --- a/examples/InternationalExample.php +++ b/examples/InternationalExample.php @@ -43,6 +43,9 @@ public function run() { $lookup->setCountry("Brazil"); $lookup->setPostalCode("02516-050"); + // Uncomment the below line to add a custom parameter to the API call + // $lookup->addCustomParameter("parameter", "value"); + try { $client->sendLookup($lookup); // The candidates are also stored in the lookup's 'result' field. $this->displayResults($lookup); diff --git a/examples/USAutocompleteProExample.php b/examples/USAutocompleteProExample.php index a660ffd..3330345 100644 --- a/examples/USAutocompleteProExample.php +++ b/examples/USAutocompleteProExample.php @@ -51,6 +51,9 @@ public function run() $lookup->setMaxResults(5); $lookup->setSource("all"); + // Uncomment the below line to add a custom parameter to the API call + // $lookup->addCustomParameter("parameter", "value"); + $client->sendLookup($lookup); $this->displayResultsFilter($lookup); } diff --git a/examples/USEnrichmentExample.php b/examples/USEnrichmentExample.php index 29d107a..0998137 100644 --- a/examples/USEnrichmentExample.php +++ b/examples/USEnrichmentExample.php @@ -41,6 +41,9 @@ public function run() $lookup->setCity("Somerville"); $lookup->setState("NJ"); $lookup->setZipcode("08876"); + + // Uncomment the below line to add a custom parameter to the API call + // $lookup->addCustomParameter("parameter", "value"); // You can also send an address in freeform by uncommenting the line below // $lookup->setFreeform("56 Union Ave Somerville NJ 08876"); diff --git a/examples/USExtractExample.php b/examples/USExtractExample.php index 2daaf8f..6b2e61d 100644 --- a/examples/USExtractExample.php +++ b/examples/USExtractExample.php @@ -35,6 +35,9 @@ public function run() { $lookup->isAggressive(); $lookup->setAddressesHaveLineBreaks(false); $lookup->setAddressesPerLine(2); + + // Uncomment the below line to add a custom parameter to the API call + // $lookup->addCustomParameter("parameter", "value"); try { $client->sendLookup($lookup); $this->displayResults($lookup); diff --git a/examples/USReverseGeoExample.php b/examples/USReverseGeoExample.php index c0774c1..3aa73e7 100644 --- a/examples/USReverseGeoExample.php +++ b/examples/USReverseGeoExample.php @@ -34,6 +34,9 @@ public function run() $lookup = new Lookup(40.111111, -111.111111); + // Uncomment the below line to add a custom parameter to the API call + // $lookup->addCustomParameter("parameter", "value"); + try { $client->sendLookup($lookup); $this->displayResults($lookup); diff --git a/examples/USStreetLookupsWithMatchStrategyExamples.php b/examples/USStreetLookupsWithMatchStrategyExamples.php index 0857b40..2fce0f3 100644 --- a/examples/USStreetLookupsWithMatchStrategyExamples.php +++ b/examples/USStreetLookupsWithMatchStrategyExamples.php @@ -31,6 +31,9 @@ public function run() { $addressWithStrictStrategy->setState("utah"); $addressWithStrictStrategy->setMatchStrategy(Lookup::STRICT); + // Uncomment the below line to add a custom parameter to the API call + // $addressWithStrictStrategy->addCustomParameter("parameter", "value"); + $addressWithInvalidStrategy = new Lookup(); $addressWithInvalidStrategy->setStreet("693 W 1150 S"); $addressWithInvalidStrategy->setCity("provo"); diff --git a/examples/UsStreetMultipleAddressesExample.php b/examples/UsStreetMultipleAddressesExample.php index 519c3fd..43d52ad 100644 --- a/examples/UsStreetMultipleAddressesExample.php +++ b/examples/UsStreetMultipleAddressesExample.php @@ -48,6 +48,9 @@ public function run() // this will always return at least one result even if the address is invalid. // Refer to the documentation for additional MatchStrategy options. + // Uncomment the below line to add a custom parameter to the API call + // $address0->addCustomParameter("parameter","value"); + $address1 = new Lookup("1 Rosedale, Baltimore, Maryland"); // Freeform addresses work too. $address1->setMaxCandidates(1); // Allows up to ten possible matches to be returned (default is 1). diff --git a/examples/UsStreetSingleAddressExample.php b/examples/UsStreetSingleAddressExample.php index 2450ad4..9b4c5d6 100644 --- a/examples/UsStreetSingleAddressExample.php +++ b/examples/UsStreetSingleAddressExample.php @@ -44,10 +44,14 @@ public function run() { $lookup->setState("CA"); $lookup->setZipcode("21229"); $lookup->setMaxCandidates(3); + $lookup->setCountySource(lookup::GEOGRAPHIC); $lookup->setMatchStrategy(Lookup::INVALID); // "invalid" is the most permissive match, // this will always return at least one result even if the address is invalid. // Refer to the documentation for additional MatchStrategy options. + // Uncomment the below line to add a custom parameter to the API call + // $lookup->addCustomParameter("parameter","value"); + try { $client->sendLookup($lookup); $this->displayResults($lookup); diff --git a/examples/UsZIPCodeMultipleLookupsExample.php b/examples/UsZIPCodeMultipleLookupsExample.php index 2149b0d..48f1487 100644 --- a/examples/UsZIPCodeMultipleLookupsExample.php +++ b/examples/UsZIPCodeMultipleLookupsExample.php @@ -35,6 +35,9 @@ public function run() { $lookup0 = new Lookup(); $lookup0->setZIPCode("12345"); // A Lookup may have a ZIP Code, city and state, or city, state, and ZIP Code + // Uncomment the below line to add a custom parameter to the API call + // $lookup0->addCustomParameter("parameter","value"); + $lookup1 = new Lookup(); $lookup1->setInputId("01189998819991197253"); // Optional ID from your system $lookup1->setCity("Phoenix"); diff --git a/examples/UsZIPCodeSingleLookupExample.php b/examples/UsZIPCodeSingleLookupExample.php index 863755c..c0446ef 100644 --- a/examples/UsZIPCodeSingleLookupExample.php +++ b/examples/UsZIPCodeSingleLookupExample.php @@ -34,6 +34,9 @@ public function run() { $lookup->setCity("Mountain View"); $lookup->setState("California"); + // Uncomment the below line to add a custom parameter to the API call + // $lookup->addCustomParameter("parameter", "value"); + try { $client->sendLookup($lookup); $this->displayResults($lookup); diff --git a/src/International_Autocomplete/Client.php b/src/International_Autocomplete/Client.php index 8e3a7c0..cf066df 100644 --- a/src/International_Autocomplete/Client.php +++ b/src/International_Autocomplete/Client.php @@ -53,6 +53,10 @@ private function buildRequest(Lookup $lookup) { $request->setParameter("include_only_locality", $lookup->getLocality()); $request->setParameter("include_only_postal_code", $lookup->getPostalCode()); + foreach ($lookup->getCustomParamArray() as $key => $value) { + $request->setParameter($key, $value); + } + return $request; } } \ No newline at end of file diff --git a/src/International_Autocomplete/Lookup.php b/src/International_Autocomplete/Lookup.php index a6206dd..27378e9 100644 --- a/src/International_Autocomplete/Lookup.php +++ b/src/International_Autocomplete/Lookup.php @@ -18,7 +18,8 @@ class Lookup { $address_id, $maxResults, $locality, - $postalCode; + $postalCode, + $customParamArray; //endregion /** @@ -29,6 +30,7 @@ public function __construct($search = null) { $this->result = array(); $this->search = $search; $this->maxResults = Lookup::MAX_RESULTS_DEFAULT; + $this->customParamArray = array(); } //region [ Getters ] @@ -65,6 +67,10 @@ public function getPostalCode() { return $this->postalCode; } + public function getCustomParamArray() { + return $this->customParamArray; + } + //endregion //region [ Setter ] @@ -100,4 +106,8 @@ public function setPostalCode($postalCode) { } //endregion + + public function addCustomParameter($parameter, $value) { + $this->customParamArray[$parameter] = $value; + } } \ No newline at end of file diff --git a/src/International_Street/Client.php b/src/International_Street/Client.php index 7eabc08..2200cdb 100644 --- a/src/International_Street/Client.php +++ b/src/International_Street/Client.php @@ -58,6 +58,10 @@ private function buildRequest(Lookup $lookup) { $request->setParameter("administrative_area", $lookup->getAdministrativeArea()); $request->setParameter("postal_code", $lookup->getPostalCode()); + foreach ($lookup->getCustomParamArray() as $key => $value) { + $request->setParameter($key, $value); + } + return $request; } diff --git a/src/International_Street/Lookup.php b/src/International_Street/Lookup.php index 15e5f8e..c4958cb 100644 --- a/src/International_Street/Lookup.php +++ b/src/International_Street/Lookup.php @@ -24,7 +24,8 @@ class Lookup { $organization, $locality, $administrativeArea, - $postalCode; + $postalCode, + $customParamArray; //endregion @@ -32,6 +33,7 @@ class Lookup { public function __construct() { $this->result = array(); + $this->customParamArray = array(); } public function setFreeformInput($freeform, $country) { @@ -144,6 +146,10 @@ public function getPostalCode() { return $this->postalCode; } + public function getCustomParamArray() { + return $this->customParamArray; + } + //endregion //region [ Setters ] @@ -218,4 +224,8 @@ public function setPostalCode($postalCode) { } //endregion + + public function addCustomParameter($parameter, $value) { + $this->customParamArray[$parameter] = $value; + } } \ No newline at end of file diff --git a/src/US_Autocomplete_Pro/Client.php b/src/US_Autocomplete_Pro/Client.php index bf8c1e3..c7e0ef4 100644 --- a/src/US_Autocomplete_Pro/Client.php +++ b/src/US_Autocomplete_Pro/Client.php @@ -57,6 +57,10 @@ private function buildRequest(Lookup $lookup) { $request->setParameter("selected", $lookup->getSelected()); $request->setParameter("source", $lookup->getSource()); + foreach ($lookup->getCustomParamArray() as $key => $value) { + $request->setParameter($key, $value); + } + return $request; } diff --git a/src/US_Autocomplete_Pro/Lookup.php b/src/US_Autocomplete_Pro/Lookup.php index 753e065..a08c844 100644 --- a/src/US_Autocomplete_Pro/Lookup.php +++ b/src/US_Autocomplete_Pro/Lookup.php @@ -27,7 +27,8 @@ class Lookup { $preferRatio, $preferGeolocation, $selected, - $source; + $source, + $customParamArray; //endregion @@ -47,6 +48,7 @@ public function __construct($search = null) { $this->preferZIPCodes = array(); $this->preferRatio = Lookup::PREFER_RATIO_DEFAULT; $this->preferGeolocation = new GeolocateType(GEOLOCATE_TYPE_CITY); + $this->customParamArray = array(); } public function addCityFilter($city) { @@ -79,6 +81,10 @@ public function addPreferZIPCode($zipcode) { $this->preferZIPCodes[] = $zipcode; } + public function addCustomParameter($parameter, $value) { + $this->customParamArray[$parameter] = $value; + } + //region [ Getters ] public function getResult() { @@ -141,6 +147,10 @@ public function getSource() { return $this->source; } + public function getCustomParamArray() { + return $this->customParamArray; + } + function getMaxResultsStringIfSet() { if ($this->maxResults == Lookup::MAX_RESULTS_DEFAULT) return null; @@ -152,6 +162,7 @@ function getPreferRatioStringIfSet() { return null; return strval($this->preferRatio); } + //endregion //region [ Setter ] diff --git a/src/US_Enrichment/Client.php b/src/US_Enrichment/Client.php index 63734a9..ae7f8e8 100644 --- a/src/US_Enrichment/Client.php +++ b/src/US_Enrichment/Client.php @@ -156,6 +156,11 @@ private function buildRequest(Lookup $lookup) { $request->setParameter("state", $lookup->getState()); $request->setParameter("zipcode", $lookup->getZipcode()); } + + foreach ($lookup->getCustomParamArray() as $key => $value) { + $request->setParameter($key, $value); + } + return $request; } diff --git a/src/US_Enrichment/Lookup.php b/src/US_Enrichment/Lookup.php index e744c47..8752482 100644 --- a/src/US_Enrichment/Lookup.php +++ b/src/US_Enrichment/Lookup.php @@ -14,7 +14,8 @@ class Lookup { $zipcode, $dataSetName, $dataSubsetName, - $response; + $response, + $customParamArray; //endregion @@ -29,6 +30,7 @@ public function __construct($smartyKey = null, $dataSetName = null, $dataSubsetN $this->state = $state; $this->zipcode = $zipcode; $this->response = null; + $this->customParamArray = array(); } public function getSmartyKey(){ @@ -67,6 +69,10 @@ public function getResponse() { return $this->response; } + public function getCustomParamArray() { + return $this->customParamArray; + } + public function setSmartyKey($smartyKey) { $this->smartyKey = $smartyKey; } @@ -102,4 +108,8 @@ public function setZipcode($zipcode){ public function setResponse($response){ $this->response = $response; } + + public function addCustomParameter($parameter, $value) { + $this->customParamArray[$parameter] = $value; + } } \ No newline at end of file diff --git a/src/US_Extract/Client.php b/src/US_Extract/Client.php index 299d90f..832b011 100644 --- a/src/US_Extract/Client.php +++ b/src/US_Extract/Client.php @@ -54,6 +54,10 @@ private function buildRequest(Lookup $lookup) { $request->setParameter('match', $match); } + foreach ($lookup->getCustomParamArray() as $key => $value) { + $request->setParameter($key, $value); + } + return $request; } } \ No newline at end of file diff --git a/src/US_Extract/Lookup.php b/src/US_Extract/Lookup.php index fa856c2..f64d1fa 100644 --- a/src/US_Extract/Lookup.php +++ b/src/US_Extract/Lookup.php @@ -21,7 +21,8 @@ class Lookup { $addressesHaveLineBreaks, $addressPerLine, $matchStrategy, - $text; + $text, + $customParamArray; /** * @param $text string The text that is to have addresses extracted out of it for verification @@ -33,6 +34,7 @@ public function __construct($text = null) { $this->addressPerLine = 0; $this->matchStrategy = ""; $this->text = $text; + $this->customParamArray = array(); } //region [ Getters ] @@ -65,6 +67,10 @@ public function getText() { return $this->text; } + public function getCustomParamArray() { + return $this->customParamArray; + } + //endregion //region [ Setters ] @@ -98,4 +104,8 @@ public function setText($text) { } //endregion + + public function addCustomParameter($parameter, $value) { + $this->customParamArray[$parameter] = $value; + } } \ No newline at end of file diff --git a/src/US_Reverse_Geo/Client.php b/src/US_Reverse_Geo/Client.php index 843a435..b084b69 100644 --- a/src/US_Reverse_Geo/Client.php +++ b/src/US_Reverse_Geo/Client.php @@ -42,6 +42,10 @@ private function buildRequest(Lookup $lookup) { $request->setParameter("longitude", $lookup->getLongitude()); $request->setParameter("source", $lookup->getSource()); + foreach ($lookup->getCustomParamArray() as $key => $value) { + $request->setParameter($key, $value); + } + return $request; } } \ No newline at end of file diff --git a/src/US_Reverse_Geo/Lookup.php b/src/US_Reverse_Geo/Lookup.php index d6439a9..469dce9 100644 --- a/src/US_Reverse_Geo/Lookup.php +++ b/src/US_Reverse_Geo/Lookup.php @@ -11,7 +11,8 @@ class Lookup { private $response, $latitude, $longitude, - $source; + $source, + $customParamArray; //endregion @@ -21,6 +22,7 @@ public function __construct($latitude, $longitude) { $this->response = null; $this->latitude = round($latitude, 8); $this->longitude = round($longitude, 8); + $this->customParamArray = array(); } //endregion @@ -43,17 +45,27 @@ public function getSource() { return $this->source; } - public function setSource($source) { - $this->source = $source; + public function getCustomParamArray() { + return $this->customParamArray; } + + //endregion //region [ Setters ] + public function setSource($source) { + $this->source = $source; + } + public function setResponse($response) { $this->response = $response; } //endregion + + public function addCustomParameter($parameter, $value) { + $this->customParamArray[$parameter] = $value; + } } \ No newline at end of file diff --git a/src/US_Street/Lookup.php b/src/US_Street/Lookup.php index efb05e7..7506562 100644 --- a/src/US_Street/Lookup.php +++ b/src/US_Street/Lookup.php @@ -16,6 +16,9 @@ class Lookup implements \JsonSerializable { const FORMAT_DEFAULT = "default"; const PROJECT_USA = "project-usa"; + const GEOGRAPHIC = "geographic"; + const POSTAL = "postal"; + private $input_id, $street, $street2, @@ -29,6 +32,9 @@ class Lookup implements \JsonSerializable { $matchStrategy, $maxCandidates, $outputFormat, + $countySource, + $customParamArray, + $jsonArray, $result; //endregion @@ -37,7 +43,7 @@ class Lookup implements \JsonSerializable { * This constructor accepts a freeform address. That means the whole address is in one string. */ public function __construct($street = null, $street2 = null, $secondary = null, $city = null, $state = null, $zipcode = null, - $lastline = null, $addressee = null, $urbanization = null, $matchStrategy = null, $maxCandidates = 1, $input_id = null, $outputFormat = null) { + $lastline = null, $addressee = null, $urbanization = null, $matchStrategy = null, $maxCandidates = 1, $input_id = null, $outputFormat = null, $countySource = null) { $this->input_id = $input_id; $this->street = $street; $this->street2 = $street2; @@ -51,12 +57,32 @@ public function __construct($street = null, $street2 = null, $secondary = null, $this->matchStrategy = $matchStrategy; $this->maxCandidates = $maxCandidates; $this->outputFormat = $outputFormat; + $this->countySource = $countySource; + $this->customParamArray = array(); + $this->jsonArray = array( + 'input_id' => $this->input_id, + 'street' => $this->street, + 'street2' => $this->street2, + 'secondary' => $this->secondary, + 'city' => $this->city, + 'state' => $this->state, + 'zipcode' => $this->zipcode, + 'lastline' => $this->lastline, + 'addressee' => $this->addressee, + 'urbanization' => $this->urbanization, + 'match' => $this->matchStrategy, + 'format' => $this->outputFormat, + 'county_source' => $this->countySource, + 'candidates' => $this->maxCandidates + ); $this->result = array(); } + + #[\ReturnTypeWillChange] function jsonSerialize() { - return array( + $this->jsonArray = array( 'input_id' => $this->input_id, 'street' => $this->street, 'street2' => $this->street2, @@ -69,8 +95,13 @@ function jsonSerialize() { 'urbanization' => $this->urbanization, 'match' => $this->matchStrategy, 'format' => $this->outputFormat, + 'county_source' => $this->countySource, 'candidates' => $this->maxCandidates ); + foreach ($this->customParamArray as $key => $value) { + $this->jsonArray[$key] = $value; + } + return $this->jsonArray; } //region [ Getters ] @@ -127,6 +158,10 @@ public function getOutputFormat() { return $this->outputFormat; } + public function getCountySource() { + return $this->countySource; + } + public function getResult() { return $this->result; } @@ -210,9 +245,17 @@ public function setOutputFormat($outputFormat) { $this->outputFormat = $outputFormat; } + public function setCountySource($countySource) { + $this->countySource = $countySource; + } + public function setResult($result) { $this->result[] = $result; } //endregion + + public function addCustomParameter($parameter, $value) { + $this->customParamArray[$parameter] = $value; + } } \ No newline at end of file diff --git a/src/US_ZIPCode/Lookup.php b/src/US_ZIPCode/Lookup.php index 7b936f3..3eb39ce 100644 --- a/src/US_ZIPCode/Lookup.php +++ b/src/US_ZIPCode/Lookup.php @@ -16,7 +16,9 @@ class Lookup implements \JsonSerializable { $inputId, $city, $state, - $zipcode; + $zipcode, + $customParamArray, + $jsonArray; //endregion @@ -27,17 +29,23 @@ public function __construct($city = null, $state = null, $zipcode = null) { $this->city = $city; $this->state = $state; $this->zipcode = $zipcode; + $this->customParamArray = array(); + $this->jsonArray = array(); } #[\ReturnTypeWillChange] public function jsonSerialize() { - return array( + $this->jsonArray = array( 'input_id' => $this->inputId, 'city' => $this->city, 'state' => $this->state, 'zipcode' => $this->zipcode ); + foreach ($this->customParamArray as $key => $value) { + $this->jsonArray[$key] = $value; + } + return $this->jsonArray; } //endregion @@ -88,5 +96,10 @@ public function setInputId($inputId) { $this->inputId = $inputId; return $this; } + //endregion + + public function addCustomParameter($parameter, $value) { + $this->customParamArray[$parameter] = $value; + } } \ No newline at end of file From 8e657724ad12d4cf1e7cc4e462697c4e0cc4c4eb Mon Sep 17 00:00:00 2001 From: Eric Devenport Date: Thu, 12 Dec 2024 09:30:09 -0700 Subject: [PATCH 2/5] Added tests for Custom Parameter feature Added Client Test for US Autocomplete Pro --- src/US_Street/Lookup.php | 4 ++ src/US_ZIPCode/Lookup.php | 4 ++ .../International_Autocomplete/ClientTest.php | 20 +++++++ tests/International_Street/ClientTest.php | 28 ++++++++++ tests/US_Autocomplete_Pro/ClientTest.php | 53 +++++++++++++++++++ tests/US_Enrichment/ClientTest.php | 19 +++++++ tests/US_Extract/ClientTest.php | 20 +++++++ tests/US_Reverse_Geo/ClientTest.php | 14 +++++ tests/US_Street/ClientTest.php | 32 ++++++++++- tests/US_ZIPCode/ClientTest.php | 22 ++++++++ tests/US_ZIPCode/LookupTest.php | 7 +++ 11 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 tests/US_Autocomplete_Pro/ClientTest.php diff --git a/src/US_Street/Lookup.php b/src/US_Street/Lookup.php index 7506562..b824002 100644 --- a/src/US_Street/Lookup.php +++ b/src/US_Street/Lookup.php @@ -166,6 +166,10 @@ public function getResult() { return $this->result; } + public function getCustomParamArray() { + return $this->customParamArray; + } + //endregion //region [ Setters ] diff --git a/src/US_ZIPCode/Lookup.php b/src/US_ZIPCode/Lookup.php index 3eb39ce..607b129 100644 --- a/src/US_ZIPCode/Lookup.php +++ b/src/US_ZIPCode/Lookup.php @@ -72,6 +72,10 @@ public function getZIPCode() { return $this->zipcode; } + public function getCustomParamArray() { + return $this->customParamArray; + } + //endregion //region [ Setters ] diff --git a/tests/International_Autocomplete/ClientTest.php b/tests/International_Autocomplete/ClientTest.php index 72be84b..2bd639a 100644 --- a/tests/International_Autocomplete/ClientTest.php +++ b/tests/International_Autocomplete/ClientTest.php @@ -48,6 +48,26 @@ public function testSendingSingleFullyPopulatedLookup() { $this->assertEquals($expectedUrl, $capturingSender->getRequest()->getUrl()); } + public function testSendingCustomParameterLookup() { + $capturingSender = new RequestCapturingSender(); + $sender = new URLPrefixSender("http://localhost", $capturingSender); + $expectedUrl = "http://localhost/coolID?country=0&search=1&max_results=2&include_only_locality=4&include_only_postal_code=5¶meter=value"; + $serializer = new MockSerializer(null); + $client = new Client($sender, $serializer); + $lookup = new Lookup(); + $lookup->setCountry("0"); + $lookup->setSearch("1"); + $lookup->setMaxResults(2); + $lookup->setLocality("4"); + $lookup->setPostalCode("5"); + $lookup->setAddressID("coolID"); + $lookup->addCustomParameter("parameter", "value"); + + $client->sendLookup($lookup); + + $this->assertEquals($expectedUrl, $capturingSender->getRequest()->getUrl()); + } + public function testEmptyLookupRejected() { $this->assertLookupRejected(new Lookup()); } diff --git a/tests/International_Street/ClientTest.php b/tests/International_Street/ClientTest.php index 7cdb02f..1f94333 100644 --- a/tests/International_Street/ClientTest.php +++ b/tests/International_Street/ClientTest.php @@ -70,6 +70,34 @@ public function testSendingSingleFullyPopulatedLookup() { $this->assertEquals($expectedUrl, $capturingSender->getRequest()->getUrl()); } + public function testSendingCustomParameterLookup() { + $capturingSender = new RequestCapturingSender(); + $sender = new URLPrefixSender("http://localhost/", $capturingSender); + $expectedUrl = "http://localhost/?input_id=1234&country=0&geocode=true&language=native&freeform=1" . + "&address1=2&address2=3&address3=4&address4=5&organization=6&locality=7&administrative_area=8&postal_code=9¶meter=value"; + $serializer = new MockSerializer(null); + $client = new Client($sender, $serializer); + $lookup = new Lookup(); + $lookup->setInputId("1234"); + $lookup->setCountry("0"); + $lookup->setGeocode(true); + $lookup->setLanguage(new LanguageMode(LANGUAGE_MODE_NATIVE)); + $lookup->setFreeform("1"); + $lookup->setAddress1("2"); + $lookup->setAddress2("3"); + $lookup->setAddress3("4"); + $lookup->setAddress4("5"); + $lookup->setOrganization("6"); + $lookup->setLocality("7"); + $lookup->setAdministrativeArea("8"); + $lookup->setPostalCode("9"); + $lookup->addCustomParameter("parameter", "value"); + + $client->sendLookup($lookup); + + $this->assertEquals($expectedUrl, $capturingSender->getRequest()->getUrl()); + } + public function testEmptyLookupRejected() { $this->assertLookupRejected(new Lookup()); } diff --git a/tests/US_Autocomplete_Pro/ClientTest.php b/tests/US_Autocomplete_Pro/ClientTest.php new file mode 100644 index 0000000..8a78fc1 --- /dev/null +++ b/tests/US_Autocomplete_Pro/ClientTest.php @@ -0,0 +1,53 @@ +addPreferCity("testCity"); + + $client->sendLookup($lookup); + + $this->assertEquals('http://localhost/?search=testSearch&prefer_cities=testCity&prefer_geolocation=city', $capturingSender->getRequest()->getUrl()); + } + + public function testSendingCustomParameterLookup() { + $capturingSender = new RequestCapturingSender(); + $sender = new URLPrefixSender("http://localhost/", $capturingSender); + $serializer = new MockSerializer(null); + $client = new Client($sender, $serializer); + + $lookup = new Lookup("testSearch"); + $lookup->addPreferCity("testCity"); + $lookup->addCustomParameter("parameter", "value"); + + $client->sendLookup($lookup); + + $this->assertEquals('http://localhost/?search=testSearch&prefer_cities=testCity&prefer_geolocation=city¶meter=value', $capturingSender->getRequest()->getUrl()); + } +} \ No newline at end of file diff --git a/tests/US_Enrichment/ClientTest.php b/tests/US_Enrichment/ClientTest.php index e8dcd19..dd015e6 100644 --- a/tests/US_Enrichment/ClientTest.php +++ b/tests/US_Enrichment/ClientTest.php @@ -30,6 +30,7 @@ public function testSendingLookup() { $this->assertEquals("http://localhost/123/property/principal?", $capturingSender->getRequest()->getUrl()); } + public function testSendingAddressComponentLookup() { $capturingSender = new RequestCapturingSender(); $sender = new URLPrefixSender("http://localhost/", $capturingSender); @@ -45,6 +46,24 @@ public function testSendingAddressComponentLookup() { $this->assertEquals("http://localhost/search/property/principal?street=123+Test+Street&city=Test+City&state=Test+State&zipcode=Test+Zipcode", $capturingSender->getRequest()->getUrl()); } + + public function testSendingCustomParameterLookup() { + $capturingSender = new RequestCapturingSender(); + $sender = new URLPrefixSender("http://localhost/", $capturingSender); + $serializer = new MockSerializer(null); + $client = new Client($sender, $serializer); + $lookup = new Lookup(); + $lookup->setStreet("123 Test Street"); + $lookup->setCity("Test City"); + $lookup->setState("Test State"); + $lookup->setZipcode("Test Zipcode"); + $lookup->addCustomParameter("parameter", "custom"); + $lookup->addCustomParameter("second", "parameter"); + + $client->sendPropertyPrincipalLookup($lookup); + + $this->assertEquals("http://localhost/search/property/principal?street=123+Test+Street&city=Test+City&state=Test+State&zipcode=Test+Zipcode¶meter=custom&second=parameter", $capturingSender->getRequest()->getUrl()); + } public function testSendingFreeformLookup() { $capturingSender = new RequestCapturingSender(); diff --git a/tests/US_Extract/ClientTest.php b/tests/US_Extract/ClientTest.php index 4cb7781..deb5f97 100644 --- a/tests/US_Extract/ClientTest.php +++ b/tests/US_Extract/ClientTest.php @@ -58,6 +58,26 @@ public function testSendingFullyPopulatedLookup() { $this->assertEquals($expectedUrl, $capturingSender->getRequest()->getUrl()); } + public function testSendingCustomParameterLookup() { + $capturingSender = new RequestCapturingSender(); + $sender = new URLPrefixSender('http://localhost/', $capturingSender); + $serializer = new MockSerializer(null); + $client = new Client($sender, $serializer); + $expectedUrl = "http://localhost/?html=true&aggressive=true&addr_line_breaks=false&addr_per_line=2&match=enhanced¶meter=custom&second=parameter"; + $lookup = new Lookup('1'); + $lookup->specifyHtmlInput(true); + $lookup->setAggressive(true); + $lookup->setAddressesHaveLineBreaks(false); + $lookup->setAddressesPerLine(2); + $lookup->setMatchStrategy(Lookup::ENHANCED); + $lookup->addCustomParameter("parameter", "custom"); + $lookup->addCustomParameter("second", "parameter"); + + $client->sendLookup($lookup); + + $this->assertEquals($expectedUrl, $capturingSender->getRequest()->getUrl()); + } + public function testRejectNullLookup() { $classType = \SmartyStreets\PhpSdk\Exceptions\SmartyException::class; diff --git a/tests/US_Reverse_Geo/ClientTest.php b/tests/US_Reverse_Geo/ClientTest.php index 79f7697..b096ceb 100644 --- a/tests/US_Reverse_Geo/ClientTest.php +++ b/tests/US_Reverse_Geo/ClientTest.php @@ -35,4 +35,18 @@ public function testSendingLookup() { $this->assertEquals("http://localhost/?latitude=44.88888889&longitude=-111.11111111", $capturingSender->getRequest()->getUrl()); } + + public function testSendingCustomParameterLookup() { + $capturingSender = new RequestCapturingSender(); + $sender = new URLPrefixSender("http://localhost/", $capturingSender); + $serializer = new MockSerializer(null); + $client = new Client($sender, $serializer); + $lookup = new Lookup(44.888888888, -111.111111111); + $lookup->addCustomParameter("parameter", "custom"); + $lookup->addCustomParameter("second", "parameter"); + + $client->sendLookup($lookup); + + $this->assertEquals("http://localhost/?latitude=44.88888889&longitude=-111.11111111¶meter=custom&second=parameter", $capturingSender->getRequest()->getUrl()); + } } diff --git a/tests/US_Street/ClientTest.php b/tests/US_Street/ClientTest.php index 9717624..f868a3f 100644 --- a/tests/US_Street/ClientTest.php +++ b/tests/US_Street/ClientTest.php @@ -67,7 +67,37 @@ public function testSendingSingleFullyPopulatedLookup() { $this->assertEquals($expectedURL, $capturingSender->getRequest()->getURL()); $this->assertEquals("GET", $capturingSender->getRequest()->getMethod()); -} + } + + public function testSendingCustomParameterLookup() { + $capturingSender = new RequestCapturingSender(); + $sender = new URLPrefixSender("http://localhost/", $capturingSender); + $serializer = new NativeSerializer(); + $expectedURL = ("http://localhost/?input_id=1&street=2&street2=3&secondary=4&city=5&" . + "state=6&zipcode=7&lastline=8&addressee=9&" . + "urbanization=10&match=enhanced&candidates=5¶meter=custom&second=parameter"); + + $client = new Client($sender, $serializer); + $lookup = new Lookup(); + $lookup->setInputId(1); + $lookup->setStreet("2"); + $lookup->setStreet2("3"); + $lookup->setSecondary("4"); + $lookup->setCity("5"); + $lookup->setState("6"); + $lookup->setZipCode("7"); + $lookup->setLastline("8"); + $lookup->setAddressee("9"); + $lookup->setUrbanization("10"); + $lookup->setMatchStrategy(Lookup::ENHANCED); + $lookup->addCustomParameter("parameter", "custom"); + $lookup->addCustomParameter("second", "parameter"); + + $client->sendLookup($lookup); + + $this->assertEquals($expectedURL, $capturingSender->getRequest()->getURL()); + $this->assertEquals("GET", $capturingSender->getRequest()->getMethod()); + } public function testSendingSingleFullyPopulatedLookupWithFormatField() { $capturingSender = new RequestCapturingSender(); diff --git a/tests/US_ZIPCode/ClientTest.php b/tests/US_ZIPCode/ClientTest.php index ff1135e..eda8cdc 100644 --- a/tests/US_ZIPCode/ClientTest.php +++ b/tests/US_ZIPCode/ClientTest.php @@ -57,6 +57,28 @@ public function testSendingSingleFullyPopulatedLookup() { $this->assertEquals("GET", $capturingSender->getRequest()->getMethod()); } + public function testSendingCustomParameterLookup() { + $capturingSender = new RequestCapturingSender(); + $sender = new URLPrefixSender("http://localhost/", $capturingSender); + $serializer = new MockSerializer(""); + $expectedURL = ("http://localhost/?input_id=1&city=2&state=3&zipcode=4¶meter=custom&second=parameter"); + + $client = new Client($sender, $serializer); + $lookup = new Lookup(); + $lookup->setInputId("1"); + $lookup->setCity("2"); + $lookup->setState("3"); + $lookup->setZipCode("4"); + $lookup->addCustomParameter("parameter", "custom"); + $lookup->addCustomParameter("second", "parameter"); + + + $client->sendLookup($lookup); + + $this->assertEquals($expectedURL, $capturingSender->getRequest()->getURL()); + $this->assertEquals("GET", $capturingSender->getRequest()->getMethod()); + } + public function testSuccessfullySendsBatchOfLookups() { $expectedPayload = "Hello, World!"; $sender = new RequestCapturingSender(); diff --git a/tests/US_ZIPCode/LookupTest.php b/tests/US_ZIPCode/LookupTest.php index 8ff15c5..ef65489 100644 --- a/tests/US_ZIPCode/LookupTest.php +++ b/tests/US_ZIPCode/LookupTest.php @@ -35,4 +35,11 @@ function testLookupConstructorSetsCityStateAndZipcode() { $this->assertEquals("state", $lookup->getState()); $this->assertEquals("12345", $lookup->getZIPCode()); } + + function testCustomParameterAddition() { + $lookup = new Lookup("city", "state", "12345"); + $lookup->addCustomParameter("parameter", "value"); + + $this->assertEquals($lookup->getCustomParamArray()["parameter"], "value"); + } } \ No newline at end of file From ed0aacf44e4eea0c56f9c398e2c1206bcf6cd822 Mon Sep 17 00:00:00 2001 From: Eric Devenport Date: Thu, 12 Dec 2024 11:37:54 -0700 Subject: [PATCH 3/5] Changed internal jsonArray to be a temporary variable --- src/US_Street/Lookup.php | 23 +++-------------------- src/US_ZIPCode/Lookup.php | 10 ++++------ 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/US_Street/Lookup.php b/src/US_Street/Lookup.php index b824002..0cdba24 100644 --- a/src/US_Street/Lookup.php +++ b/src/US_Street/Lookup.php @@ -34,7 +34,6 @@ class Lookup implements \JsonSerializable { $outputFormat, $countySource, $customParamArray, - $jsonArray, $result; //endregion @@ -59,22 +58,6 @@ public function __construct($street = null, $street2 = null, $secondary = null, $this->outputFormat = $outputFormat; $this->countySource = $countySource; $this->customParamArray = array(); - $this->jsonArray = array( - 'input_id' => $this->input_id, - 'street' => $this->street, - 'street2' => $this->street2, - 'secondary' => $this->secondary, - 'city' => $this->city, - 'state' => $this->state, - 'zipcode' => $this->zipcode, - 'lastline' => $this->lastline, - 'addressee' => $this->addressee, - 'urbanization' => $this->urbanization, - 'match' => $this->matchStrategy, - 'format' => $this->outputFormat, - 'county_source' => $this->countySource, - 'candidates' => $this->maxCandidates - ); $this->result = array(); } @@ -82,7 +65,7 @@ public function __construct($street = null, $street2 = null, $secondary = null, #[\ReturnTypeWillChange] function jsonSerialize() { - $this->jsonArray = array( + $jsonArray = array( 'input_id' => $this->input_id, 'street' => $this->street, 'street2' => $this->street2, @@ -99,9 +82,9 @@ function jsonSerialize() { 'candidates' => $this->maxCandidates ); foreach ($this->customParamArray as $key => $value) { - $this->jsonArray[$key] = $value; + $jsonArray[$key] = $value; } - return $this->jsonArray; + return $jsonArray; } //region [ Getters ] diff --git a/src/US_ZIPCode/Lookup.php b/src/US_ZIPCode/Lookup.php index 607b129..c0964de 100644 --- a/src/US_ZIPCode/Lookup.php +++ b/src/US_ZIPCode/Lookup.php @@ -17,8 +17,7 @@ class Lookup implements \JsonSerializable { $city, $state, $zipcode, - $customParamArray, - $jsonArray; + $customParamArray; //endregion @@ -30,22 +29,21 @@ public function __construct($city = null, $state = null, $zipcode = null) { $this->state = $state; $this->zipcode = $zipcode; $this->customParamArray = array(); - $this->jsonArray = array(); } #[\ReturnTypeWillChange] public function jsonSerialize() { - $this->jsonArray = array( + $jsonArray = array( 'input_id' => $this->inputId, 'city' => $this->city, 'state' => $this->state, 'zipcode' => $this->zipcode ); foreach ($this->customParamArray as $key => $value) { - $this->jsonArray[$key] = $value; + $jsonArray[$key] = $value; } - return $this->jsonArray; + return $jsonArray; } //endregion From 6923e76c62470c64a01c21d0084a34844e95475a Mon Sep 17 00:00:00 2001 From: Eric Devenport Date: Mon, 16 Dec 2024 16:38:08 -0700 Subject: [PATCH 4/5] Added include and exclude parameters for the US Address Enrichment API --- examples/USEnrichmentExample.php | 13 +++++++++++++ src/US_Enrichment/Client.php | 10 ++++++++++ src/US_Enrichment/Lookup.php | 30 +++++++++++++++++++++++++++++- 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/examples/USEnrichmentExample.php b/examples/USEnrichmentExample.php index 0998137..a82886a 100644 --- a/examples/USEnrichmentExample.php +++ b/examples/USEnrichmentExample.php @@ -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"); diff --git a/src/US_Enrichment/Client.php b/src/US_Enrichment/Client.php index ae7f8e8..d3d54b1 100644 --- a/src/US_Enrichment/Client.php +++ b/src/US_Enrichment/Client.php @@ -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); } @@ -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); + } } \ No newline at end of file diff --git a/src/US_Enrichment/Lookup.php b/src/US_Enrichment/Lookup.php index 8752482..b7b80de 100644 --- a/src/US_Enrichment/Lookup.php +++ b/src/US_Enrichment/Lookup.php @@ -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; @@ -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(); } @@ -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; @@ -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; } From 21f9963c6b324108132f374893f0416fba0db3e2 Mon Sep 17 00:00:00 2001 From: Eric Devenport Date: Mon, 16 Dec 2024 17:06:06 -0700 Subject: [PATCH 5/5] Modified tests to include the include and exclude parameters --- tests/US_Enrichment/ClientTest.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/US_Enrichment/ClientTest.php b/tests/US_Enrichment/ClientTest.php index dd015e6..22ddc1e 100644 --- a/tests/US_Enrichment/ClientTest.php +++ b/tests/US_Enrichment/ClientTest.php @@ -41,10 +41,14 @@ public function testSendingAddressComponentLookup() { $lookup->setCity("Test City"); $lookup->setState("Test State"); $lookup->setZipcode("Test Zipcode"); + $lookup->addIncludeAttribute("Test Include 1"); + $lookup->addIncludeAttribute("Test Include 2"); + $lookup->addExcludeAttribute("Test Exclude 1"); + $lookup->addExcludeAttribute("Test Exclude 2"); $client->sendPropertyPrincipalLookup($lookup); - $this->assertEquals("http://localhost/search/property/principal?street=123+Test+Street&city=Test+City&state=Test+State&zipcode=Test+Zipcode", $capturingSender->getRequest()->getUrl()); + $this->assertEquals("http://localhost/search/property/principal?street=123+Test+Street&city=Test+City&state=Test+State&zipcode=Test+Zipcode&include=Test+Include+1%2CTest+Include+2&exclude=Test+Exclude+1%2CTest+Exclude+2", $capturingSender->getRequest()->getUrl()); } public function testSendingCustomParameterLookup() { @@ -59,10 +63,14 @@ public function testSendingCustomParameterLookup() { $lookup->setZipcode("Test Zipcode"); $lookup->addCustomParameter("parameter", "custom"); $lookup->addCustomParameter("second", "parameter"); + $includeArray = array("Test Include 1","Test Include 2"); + $excludeArray = array("Test Exclude 1","Test Exclude 2"); + $lookup->setIncludeArray($includeArray); + $lookup->setExcludeArray($excludeArray); $client->sendPropertyPrincipalLookup($lookup); - $this->assertEquals("http://localhost/search/property/principal?street=123+Test+Street&city=Test+City&state=Test+State&zipcode=Test+Zipcode¶meter=custom&second=parameter", $capturingSender->getRequest()->getUrl()); + $this->assertEquals("http://localhost/search/property/principal?street=123+Test+Street&city=Test+City&state=Test+State&zipcode=Test+Zipcode&include=Test+Include+1%2CTest+Include+2&exclude=Test+Exclude+1%2CTest+Exclude+2¶meter=custom&second=parameter", $capturingSender->getRequest()->getUrl()); } public function testSendingFreeformLookup() {