diff --git a/src/AppBundle/Api/Client/Brickset/Brickset.php b/src/AppBundle/Api/Client/Brickset/Brickset.php index 4d98dca..45746ea 100644 --- a/src/AppBundle/Api/Client/Brickset/Brickset.php +++ b/src/AppBundle/Api/Client/Brickset/Brickset.php @@ -9,6 +9,10 @@ use AppBundle\Api\Client\Brickset\Entity\Set; use AppBundle\Api\Client\Brickset\Entity\Subtheme; use AppBundle\Api\Client\Brickset\Entity\Theme; use AppBundle\Api\Client\Brickset\Entity\Year; +use AppBundle\Api\Exception\ApiException; +use AppBundle\Api\Exception\AuthenticationFailedException; +use AppBundle\Api\Exception\CallFailedException; +use AppBundle\Api\Exception\EmptyResponseException; use Symfony\Component\Asset\Exception\LogicException; use Symfony\Component\Debug\Exception\ContextErrorException; @@ -42,6 +46,8 @@ class Brickset extends \SoapClient { $this->apiKey = $apikey; + $options['cache_wsdl'] = WSDL_CACHE_NONE; + foreach (self::$classmap as $key => $value) { if (!isset($options['classmap'][$key])) { $options['classmap'][$key] = $value; @@ -66,13 +72,12 @@ class Brickset extends \SoapClient $parameters['apiKey'] = $this->apiKey; try { + $this->checkApiKey(); return $this->__soapCall($method, [$parameters])->{$method.'Result'}; } catch (\SoapFault $e) { - //TODO - throw new LogicException($e->getCode().' - '.$e->getMessage()); + throw new CallFailedException(ApiException::BRICKSET); } catch (ContextErrorException $e) { - //TODO empty resposne - throw new LogicException($method.' - '.$e->getMessage()); + throw new EmptyResponseException(ApiException::BRICKSET); } } @@ -247,10 +252,14 @@ class Brickset extends \SoapClient /** * Check if an API key is valid. * - * @return bool + * @throws AuthenticationFailedException If api key is not valid */ - public function checkKey() + private function checkApiKey() { - return ($this->call('checkKey', [])) == 'OK' ? true : false; + $parameters['apiKey'] = $this->apiKey; + + if($this->__soapCall('checkKey', [$parameters])->checkKeyResult != 'OK') { + throw new AuthenticationFailedException(ApiException::BRICKSET); + } } } diff --git a/src/AppBundle/Api/Client/Rebrickable/Converter/PropertyNameConverter.php b/src/AppBundle/Api/Client/Rebrickable/Converter/PropertyNameConverter.php index 53eaec5..b5c47f8 100644 --- a/src/AppBundle/Api/Client/Rebrickable/Converter/PropertyNameConverter.php +++ b/src/AppBundle/Api/Client/Rebrickable/Converter/PropertyNameConverter.php @@ -14,7 +14,7 @@ class PropertyNameConverter implements NameConverterInterface public function denormalize($propertyName) { switch ($propertyName) { - case 'part_num': return 'id'; + case 'part_num': return 'number'; case 'part_cat_id': return 'categoryId'; case 'part_img_url': return 'imgUrl'; case 'part_url': return 'url'; diff --git a/src/AppBundle/Api/Client/Rebrickable/Rebrickable_v3.php b/src/AppBundle/Api/Client/Rebrickable/Rebrickable_v3.php index d3e5eaf..97fa006 100644 --- a/src/AppBundle/Api/Client/Rebrickable/Rebrickable_v3.php +++ b/src/AppBundle/Api/Client/Rebrickable/Rebrickable_v3.php @@ -2,6 +2,10 @@ namespace AppBundle\Api\Client\Rebrickable; +use AppBundle\Api\Exception\ApiException; +use AppBundle\Api\Exception\AuthenticationFailedException; +use AppBundle\Api\Exception\CallFailedException; +use AppBundle\Api\Exception\EmptyResponseException; use GuzzleHttp\Client; use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Exception\ConnectException; @@ -51,17 +55,15 @@ class Rebrickable_v3 return $content; } catch (ConnectException $e) { - //TODO - throw new LogicException($e); + throw new CallFailedException(ApiException::REBRICKABLE); } catch (ClientException $e) { - //TODO if ($e->getCode() == 404) { - throw new LogicException('Not Found'); + throw new EmptyResponseException(ApiException::REBRICKABLE); + } else if ($e->getCode() == 401) { + throw new AuthenticationFailedException(ApiException::REBRICKABLE); } - if ($e->getCode() == 500) { - throw new LogicException('Invalid token'); - } - throw new LogicException($e); + + throw new ApiException(ApiException::REBRICKABLE,$e,$e->getCode()); } } } diff --git a/src/AppBundle/Api/Exception/ApiException.php b/src/AppBundle/Api/Exception/ApiException.php new file mode 100644 index 0000000..92b3fe7 --- /dev/null +++ b/src/AppBundle/Api/Exception/ApiException.php @@ -0,0 +1,39 @@ +service = $service; + } + + /** + * @return string + */ + public function getService() + { + return $this->service; + } + + /** + * @param string $service + */ + public function setService($service) + { + $this->service = $service; + } +} diff --git a/src/AppBundle/Api/Exception/AuthenticationFailedException.php b/src/AppBundle/Api/Exception/AuthenticationFailedException.php new file mode 100644 index 0000000..3d5d481 --- /dev/null +++ b/src/AppBundle/Api/Exception/AuthenticationFailedException.php @@ -0,0 +1,14 @@ +