diff --git a/src/Client/Client.php b/src/Client/Client.php index 9086cb4..c8a2dc9 100644 --- a/src/Client/Client.php +++ b/src/Client/Client.php @@ -9,7 +9,6 @@ use Setono\GLS\Webservice\Response\Response; use SoapClient; use SoapFault; -use RuntimeException; final class Client implements ClientInterface { @@ -23,9 +22,27 @@ public function __construct(SoapClient $soapClient) $this->soapClient = $soapClient; } - public function getAllParcelShops(string $countryIso): array + public function getAllParcelShops(string $countryCode): array { - throw new RuntimeException('Method not implemented. Please do so in a pull request on GitHub ;)'); + $response = $this->sendRequest('GetAllParcelShops', [ + 'countryIso3166A2' => $countryCode, + ]); + + $parcelShops = []; + + if (200 !== $response->getStatusCode()) { + return $parcelShops; + } + + if (null === $response->getResult()) { + return $parcelShops; + } + + foreach ($response->getResult()->GetAllParcelShopsResult->PakkeshopData as $parcelShop) { + $parcelShops[] = ParcelShop::createFromStdClass($parcelShop); + } + + return $parcelShops; } public function getOneParcelShop(string $parcelShopNumber): ParcelShop @@ -42,22 +59,62 @@ public function getOneParcelShop(string $parcelShopNumber): ParcelShop return ParcelShop::createFromStdClass($response->getResult()->GetOneParcelShopResult); } - public function getParcelShopDropPoint(string $street, string $zipCode, string $countryIso, int $amount): array + public function getParcelShopDropPoint(string $street, string $zipCode, string $countryCode, int $amount): array { - throw new RuntimeException('Method not implemented. Please do so in a pull request on GitHub ;)'); + $response = $this->sendRequest('GetParcelShopDropPoint', [ + 'street' => $street, + 'zipcode' => $zipCode, + 'countryIso3166A2' => $countryCode, + 'Amount' => $amount, + ]); + + $parcelShops = []; + + if (200 !== $response->getStatusCode()) { + return $parcelShops; + } + + if (null === $response->getResult()) { + return $parcelShops; + } + + foreach ($response->getResult()->GetParcelShopDropPointResult->parcelshops->PakkeshopData as $parcelShop) { + $parcelShops[] = ParcelShop::createFromStdClass($parcelShop); + } + + return $parcelShops; } - public function getParcelShopsInZipCode(string $zipCode, string $countryIso): array + public function getParcelShopsInZipCode(string $zipCode, string $countryCode): array { - throw new RuntimeException('Method not implemented. Please do so in a pull request on GitHub ;)'); + $response = $this->sendRequest('GetParcelShopsInZipCode', [ + 'zipcode' => $zipCode, + 'countryIso3166A2' => $countryCode, + ]); + + $parcelShops = []; + + if (200 !== $response->getStatusCode()) { + return $parcelShops; + } + + if (null === $response->getResult()) { + return $parcelShops; + } + + foreach ($response->getResult()->GetParcelShopsInZipcodeResult->PakkeshopData as $parcelShop) { + $parcelShops[] = ParcelShop::createFromStdClass($parcelShop); + } + + return $parcelShops; } - public function searchNearestParcelShops(string $street, string $zipCode, string $countryIso, int $amount = 10): array + public function searchNearestParcelShops(string $street, string $zipCode, string $countryCode, int $amount = 10): array { $response = $this->sendRequest('SearchNearestParcelShops', [ 'street' => $street, 'zipcode' => $zipCode, - 'countryIso3166A2' => $countryIso, + 'countryIso3166A2' => $countryCode, 'Amount' => $amount, ]); diff --git a/src/Client/ClientInterface.php b/src/Client/ClientInterface.php index 3302b67..504c5b6 100644 --- a/src/Client/ClientInterface.php +++ b/src/Client/ClientInterface.php @@ -15,11 +15,11 @@ interface ClientInterface /** * Returns all ParcelShops in a given country. * - * @param string $countryIso The alpha 2 country code (https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes) + * @param string $countryCode The alpha 2 country code (https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes) * * @return ParcelShop[] */ - public function getAllParcelShops(string $countryIso): array; + public function getAllParcelShops(string $countryCode): array; /** * Get one ParcelShop. @@ -37,22 +37,22 @@ public function getOneParcelShop(string $parcelShopNumber): ParcelShop; * * @param string $street * @param string $zipCode - * @param string $countryIso The alpha 2 country code (https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes) + * @param string $countryCode The alpha 2 country code (https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes) * @param int $amount * * @return ParcelShop[] */ - public function getParcelShopDropPoint(string $street, string $zipCode, string $countryIso, int $amount): array; + public function getParcelShopDropPoint(string $street, string $zipCode, string $countryCode, int $amount): array; /** * Returns all ParcelShops in a zip code - or the 3 nearest in other zip codes. * * @param string $zipCode - * @param string $countryIso The alpha 2 country code (https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes) + * @param string $countryCode The alpha 2 country code (https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes) * * @return ParcelShop[] */ - public function getParcelShopsInZipCode(string $zipCode, string $countryIso): array; + public function getParcelShopsInZipCode(string $zipCode, string $countryCode): array; /** * Search for nearest ParcelShops to an address. @@ -62,10 +62,10 @@ public function getParcelShopsInZipCode(string $zipCode, string $countryIso): ar * * @param string $street * @param string $zipCode - * @param string $countryIso + * @param string $countryCode * @param int $amount * * @return ParcelShop[] */ - public function searchNearestParcelShops(string $street, string $zipCode, string $countryIso, int $amount): array; + public function searchNearestParcelShops(string $street, string $zipCode, string $countryCode, int $amount): array; }