Skip to content

Commit

Permalink
Merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Hall committed Mar 9, 2018
2 parents 67473e0 + 32ad7ef commit 922b4b4
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 92 deletions.
13 changes: 7 additions & 6 deletions Example.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

require_once 'vendor/autoload.php';
use \RapidWeb\Postcodes\Utils\Generator;
use \RapidWeb\Postcodes\Utils\Validator;
use \RapidWeb\Postcodes\Objects\IdealPostcodes;
use \RapidWeb\Postcodes\Objects\PostcodeAnywhere;
use RapidWeb\Postcodes\Objects\IdealPostcodes;
use RapidWeb\Postcodes\Objects\PostcodeAnywhere;
use RapidWeb\Postcodes\Utils\Generator;
use RapidWeb\Postcodes\Utils\Validator;

$postcode = Generator::generatePostcode();

Expand All @@ -15,8 +16,8 @@

$idealPostcodes = new IdealPostCodes('API_KEY');
$addresses = $idealPostcodes->getAddressesByPostcode('ST16 3DP');
var_dump($addresses);
var_dump($addresses);

$postcodeAnywhere = new PostcodeAnywhere('API_KEY');
$addresses = $postcodeAnywhere->getAddressesByPostcode('ST16 3DP');
var_dump($addresses);
var_dump($addresses);
3 changes: 2 additions & 1 deletion src/Exceptions/InvalidPostcodeException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace RapidWeb\Postcodes\Exceptions;

class InvalidPostcodeException extends \Exception
{
}
}
4 changes: 3 additions & 1 deletion src/Interfaces/PostcodeServiceInterface.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

namespace RapidWeb\Postcodes\Interfaces;

interface PostcodeServiceInterface
{
public function __construct($apiKey);

public function getAddressesByPostcode($postcode);
}
}
3 changes: 2 additions & 1 deletion src/Objects/Address.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace RapidWeb\Postcodes\Objects;

class Address
Expand All @@ -11,4 +12,4 @@ class Address
public $county = '';
public $country = 'United Kingdom';
public $postcode = '';
}
}
20 changes: 9 additions & 11 deletions src/Objects/IdealPostcodes.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace RapidWeb\Postcodes\Objects;

use Exception;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use RapidWeb\Postcodes\Interfaces\PostcodeServiceInterface;
use RapidWeb\Postcodes\Objects\Address;
use Exception;

class IdealPostCodes implements PostcodeServiceInterface
class IdealPostcodes implements PostcodeServiceInterface
{
private $apiKey = null;
private $client = null;
Expand All @@ -23,7 +23,6 @@ public function __construct($apiKey)
$headers = ['Authorization' => 'IDEALPOSTCODES api_key="'.$this->apiKey.'"'];

$this->client = new Client(['base_uri' => 'https://api.ideal-postcodes.co.uk/v1/', 'timeout' => 3.0, 'headers' => $headers]);

}

public function getAddressesByPostcode($postcode)
Expand All @@ -34,10 +33,10 @@ public function getAddressesByPostcode($postcode)

return $result;
}

private function parseResponse(Response $response)
{
if ($response->getStatusCode()!=200) {
if ($response->getStatusCode() != 200) {
throw new Exception('HTTP response code was not 200. Received HTTP reponse code: '.$response->getStatusCode().' ('.$response->getReasonPhrase().')');
}

Expand All @@ -51,7 +50,7 @@ private function parseResponse(Response $response)
throw new Exception('Response code not found or invalid.');
}

if ($object->code!=2000) {
if ($object->code != 2000) {
throw new Exception('Response code was not 2000. Response message: '.((isset($object->message) ? $object->message : '(none)')));
}

Expand All @@ -61,8 +60,8 @@ private function parseResponse(Response $response)

$addresses = [];

foreach($object->result as $idealPostcodesAddress) {
$address = new Address;
foreach ($object->result as $idealPostcodesAddress) {
$address = new Address();
$address->companyName = $idealPostcodesAddress->organisation_name;
$address->line1 = $idealPostcodesAddress->line_1;
$address->line2 = $idealPostcodesAddress->line_2;
Expand All @@ -75,6 +74,5 @@ private function parseResponse(Response $response)
}

return $addresses;

}
}
}
24 changes: 11 additions & 13 deletions src/Objects/PostcodeAnywhere.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace RapidWeb\Postcodes\Objects;

use RapidWeb\Postcodes\Interfaces\PostcodeServiceInterface;
use RapidWeb\Postcodes\Objects\Address;
use Exception;
use RapidWeb\Postcodes\Interfaces\PostcodeServiceInterface;
use SoapClient;

class PostcodeAnywhere implements PostcodeServiceInterface
Expand All @@ -22,7 +22,6 @@ public function __construct($apiKey)

$this->findSOAPClient = new SoapClient('https://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive/Find/v1.10/wsdlnew.ws');
$this->retrieveByIDSOAPClient = new \SoapClient('https://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive/RetrieveById/v1.30/wsdlnew.ws');

}

public function getAddressesByPostcode($postcode)
Expand All @@ -31,19 +30,19 @@ public function getAddressesByPostcode($postcode)

$addresses = [];

foreach($findResponseAddresses as $findResponseAddress) {
foreach ($findResponseAddresses as $findResponseAddress) {
$addresses[] = $this->getAddressById($findResponseAddress->Id);
}

return $addresses;
}

public function getFindResponseAddressesByPostcode($postcode)
public function getFindResponseAddressesByPostcode($postcode)
{
$findResponse = $this->findSOAPClient->PostcodeAnywhere_Interactive_Find_v1_10(
[
'Key' => $this->apiKey,
'SearchTerm' => $postcode
'Key' => $this->apiKey,
'SearchTerm' => $postcode,
]
);

Expand All @@ -56,14 +55,14 @@ public function getAddressById($id)
{
$retrieveByIDResponse = $this->retrieveByIDSOAPClient->PostcodeAnywhere_Interactive_RetrieveById_v1_30(
[
'Key' => $this->apiKey,
'Id' => $id
'Key' => $this->apiKey,
'Id' => $id,
]
);

$retrieveAddress = $retrieveByIDResponse->PostcodeAnywhere_Interactive_RetrieveById_v1_30_Result->PostcodeAnywhere_Interactive_RetrieveById_v1_30_Results;

$address = new Address;
$address = new Address();
$address->companyName = $retrieveAddress->Company;
$address->line1 = $retrieveAddress->Line1;
$address->line2 = $retrieveAddress->Line2;
Expand All @@ -75,5 +74,4 @@ public function getAddressById($id)

return $address;
}

}
}
6 changes: 3 additions & 3 deletions src/Utils/Generator.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

namespace RapidWeb\Postcodes\Utils;

use RapidWeb\Postcodes\Utils\Validator;
use Faker\Factory as FakerFactory;

abstract class Generator
Expand All @@ -12,11 +12,11 @@ public static function generatePostcode()

$validated = false;

while(!$validated) {
while (!$validated) {
$postcode = $faker->postcode;
$validated = Validator::validatePostcode($postcode);
}

return $postcode;
}
}
}
72 changes: 34 additions & 38 deletions src/Utils/Tokenizer.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
<?php
namespace RapidWeb\Postcodes\Utils;

use RapidWeb\Postcodes\Utils\Validator;
use Exception;
use RapidWeb\Postcodes\Exceptions\InvalidPostcodeException;

abstract class Tokenizer
{
public static function outward($postcode)
{
self::sanityCheck($postcode);

$postcodeStart = trim(substr($postcode, 0, -3));

return $postcodeStart;
}

public static function inward($postcode)
{
self::sanityCheck($postcode);

$postcodeEnd = trim(substr($postcode, -3,3));

return $postcodeEnd;
}

private static function sanityCheck($postcode)
{
$validated = Validator::validatePostcode($postcode);
if(!$validated)
{
throw new InvalidPostcodeException("Post code provided is not valid");
}

}

}
<?php

namespace RapidWeb\Postcodes\Utils;

use RapidWeb\Postcodes\Exceptions\InvalidPostcodeException;

abstract class Tokenizer
{
public static function outward($postcode)
{
self::sanityCheck($postcode);

$postcodeStart = trim(substr($postcode, 0, -3));

return $postcodeStart;
}

public static function inward($postcode)
{
self::sanityCheck($postcode);

$postcodeEnd = trim(substr($postcode, -3, 3));

return $postcodeEnd;
}

private static function sanityCheck($postcode)
{
$validated = Validator::validatePostcode($postcode);
if (!$validated) {
throw new InvalidPostcodeException('Post code provided is not valid');
}
}
}
3 changes: 2 additions & 1 deletion src/Utils/Validator.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace RapidWeb\Postcodes\Utils;

abstract class Validator
Expand All @@ -13,4 +14,4 @@ public static function validatePostcode($postcode)

return $result ? true : false;
}
}
}
Loading

0 comments on commit 922b4b4

Please sign in to comment.