From b52c971deb82bb4c6a6ef7c0376d1242e6033fed Mon Sep 17 00:00:00 2001 From: DivineOmega Date: Mon, 28 Aug 2017 17:17:16 +0100 Subject: [PATCH] Added additional methods to PostcodeAnywhere to allow for creation of slim implementations --- src/Objects/PostcodeAnywhere.php | 50 ++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/src/Objects/PostcodeAnywhere.php b/src/Objects/PostcodeAnywhere.php index ba6f69f..0c107fc 100644 --- a/src/Objects/PostcodeAnywhere.php +++ b/src/Objects/PostcodeAnywhere.php @@ -28,6 +28,19 @@ public function __construct($apiKey) } public function getAddressesByPostcode($postcode) + { + $findResponseAddresses = $this->getFindResponseAddressesByPostcode($postcode); + + $addresses = []; + + foreach($findResponseAddresses as $findResponseAddress) { + $addresses[] = $this->getAddressById($findResponseAddress->Id);; + } + + return $addresses; + } + + public function getFindResponseAddressesByPostcode($postcode) { $findResponse = $this->findSOAPClient->PostcodeAnywhere_Interactive_Find_v1_10( [ @@ -38,32 +51,31 @@ public function getAddressesByPostcode($postcode) $findResponseAddresses = $findResponse->PostcodeAnywhere_Interactive_Find_v1_10_Result->PostcodeAnywhere_Interactive_Find_v1_10_Results; - $addresses = []; - - foreach($findResponseAddresses as $findResponseAddress) { + return $findResponseAddresses; + } - $retrieveByIDResponse = $this->retrieveByIDSOAPClient->PostcodeAnywhere_Interactive_RetrieveById_v1_30( + public function getAddressById($id) + { + $retrieveByIDResponse = $this->retrieveByIDSOAPClient->PostcodeAnywhere_Interactive_RetrieveById_v1_30( [ 'Key' => $this->apiKey, - 'Id' => $findResponseAddress->Id + 'Id' => $id ] ); - $retrieveAddress = $retrieveByIDResponse->PostcodeAnywhere_Interactive_RetrieveById_v1_30_Result->PostcodeAnywhere_Interactive_RetrieveById_v1_30_Results; - - $address = new Address; - $address->companyName = $retrieveAddress->Company; - $address->line1 = $retrieveAddress->Line1; - $address->line2 = $retrieveAddress->Line2; - $address->line3 = $retrieveAddress->Line3; - $address->townCity = $retrieveAddress->PostTown; - $address->county = $retrieveAddress->County; - $address->postcode = $retrieveAddress->Postcode; - $address->country = $retrieveAddress->CountryName; - $addresses[] = $address; - } + $retrieveAddress = $retrieveByIDResponse->PostcodeAnywhere_Interactive_RetrieveById_v1_30_Result->PostcodeAnywhere_Interactive_RetrieveById_v1_30_Results; - return $addresses; + $address = new Address; + $address->companyName = $retrieveAddress->Company; + $address->line1 = $retrieveAddress->Line1; + $address->line2 = $retrieveAddress->Line2; + $address->line3 = $retrieveAddress->Line3; + $address->townCity = $retrieveAddress->PostTown; + $address->county = $retrieveAddress->County; + $address->postcode = $retrieveAddress->Postcode; + $address->country = $retrieveAddress->CountryName; + + return $address; } } \ No newline at end of file