Skip to content

Commit

Permalink
Added additional methods to PostcodeAnywhere to allow for creation of…
Browse files Browse the repository at this point in the history
… slim implementations
  • Loading branch information
DivineOmega committed Aug 28, 2017
1 parent 1613d4e commit b52c971
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions src/Objects/PostcodeAnywhere.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
Expand All @@ -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;
}

}

0 comments on commit b52c971

Please sign in to comment.