From 1694ce8ad465bec9201b0a158b05ef2c8d875af5 Mon Sep 17 00:00:00 2001 From: Jordan Hall Date: Thu, 22 Jun 2017 13:41:32 +0100 Subject: [PATCH] Initial work of Postcode Anywhere integration --- Example.php | 9 +---- README.md | 20 +++++----- pa-test.php | 8 ++++ src/Factories/IdealPostcodesFactory.php | 26 ------------- src/Interfaces/PostcodeServiceInterface.php | 8 ++++ src/Objects/IdealPostcodes.php | 3 +- src/Objects/PostcodeAnywhere.php | 41 +++++++++++++++++++++ 7 files changed, 70 insertions(+), 45 deletions(-) create mode 100644 pa-test.php delete mode 100644 src/Factories/IdealPostcodesFactory.php create mode 100644 src/Interfaces/PostcodeServiceInterface.php create mode 100644 src/Objects/PostcodeAnywhere.php diff --git a/Example.php b/Example.php index 0ee7d47..69fcefd 100644 --- a/Example.php +++ b/Example.php @@ -2,7 +2,7 @@ require_once 'vendor/autoload.php'; use \RapidWeb\Postcodes\Utils\Generator; use \RapidWeb\Postcodes\Utils\Validator; -use \RapidWeb\Postcodes\Factories\IdealPostcodesFactory; +use \RapidWeb\Postcodes\Objects\IdealPostCodes; $postcode = Generator::generatePostcode(); @@ -12,12 +12,7 @@ if ($validated) { - // You should specify IDEAL_POSTCODES_API_KEY in your .env file, - // or pass it via the getByAPIKey method. - - $idealPostcodes = IdealPostcodesFactory::getByEnvironment(); - - $addresses = $idealPostcodes->getAddressesByPostcode('ST163DP'); + $addresses = new IdealPostCodes('API_KEY'); var_dump($addresses); diff --git a/README.md b/README.md index bb7c69f..428fed8 100644 --- a/README.md +++ b/README.md @@ -22,24 +22,22 @@ To install, just run the following composer command. Using some of the data retrieval features provided by this library requires an Ideal Postcodes API key. Sign up at https://ideal-postcodes.co.uk if you need to use these features. -If you are using a `.env` file or another way of manage environment variables in your -project, set the following variable to specify the Ideal Postcode. - -``` -IDEAL_POSTCODES_API_KEY=abcdef -``` - You can then use the following code to get an `IdealPostcodes` object. ```php -$idealPostcodes = \RapidWeb\Postcodes\Factories\IdealPostcodesFactory::getByEnvironment(); +$idealPostcodes = new \RapidWeb\Postcodes\Objects\IdealPostcodes('API_KEY'); ``` -If you are not using environment variables in your project, simple pass through the API -key as follows. + +### Postcode Anywhere (PCA Predict) + +Using some of the data retrieval features provided by this library requires an Postcode Anywhere (PCA Predict) +API key. Sign up at https://www.pcapredict.com/ if you need to use these features. + +You can then use the following code to get an `PostcodeAnywhere` object. ```php -$idealPostcodes = \RapidWeb\Postcodes\Factories\IdealPostcodesFactory::getByAPIKey('abdef'); +$postcodeAnywhere = new \RapidWeb\Postcodes\Objects\PostcodeAnywhere('API_KEY'); ``` ## Usage diff --git a/pa-test.php b/pa-test.php new file mode 100644 index 0000000..4783c8a --- /dev/null +++ b/pa-test.php @@ -0,0 +1,8 @@ +getAddressesByPostcode('st163jr'); \ No newline at end of file diff --git a/src/Factories/IdealPostcodesFactory.php b/src/Factories/IdealPostcodesFactory.php deleted file mode 100644 index 3667f39..0000000 --- a/src/Factories/IdealPostcodesFactory.php +++ /dev/null @@ -1,26 +0,0 @@ -apiKey = $apiKey; + + $this->findSOAPClient = new SoapClient('https://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive/Find/v1.10/wsdlnew.ws'); + + } + + public function getAddressesByPostcode($postcode) + { + $findResponse = $this->findSOAPClient->PostcodeAnywhere_Interactive_Find_v1_10( + [ + 'Key' => $this->apiKey, + 'SearchTerm' => $postcode + ] + ); + + $findResponseAddresses = $findResponse->PostcodeAnywhere_Interactive_Find_v1_10_Result->PostcodeAnywhere_Interactive_Find_v1_10_Results; + + return $result; + } + +} \ No newline at end of file