-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
71246bb
commit af174fe
Showing
28 changed files
with
246 additions
and
329 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of the TempNumberClient package. | ||
* | ||
* (c) Ahmed Ghanem <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace ahmedghanem00\TempNumberClient\Exception\API; | ||
|
||
use ahmedghanem00\TempNumberClient\Exception\ClientException; | ||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; | ||
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface; | ||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; | ||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; | ||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; | ||
use Symfony\Contracts\HttpClient\ResponseInterface; | ||
|
||
/** | ||
* | ||
*/ | ||
class APIException extends ClientException | ||
{ | ||
public const Description = "API Failed Action"; | ||
|
||
/** | ||
* @param ResponseInterface $response | ||
*/ | ||
public function __construct( | ||
private ResponseInterface $response | ||
) | ||
{ | ||
parent::__construct(static::Description); | ||
} | ||
|
||
/** | ||
* @param string $errorName | ||
* @param ResponseInterface $response | ||
* @return static | ||
*/ | ||
public static function newFromErrorName(string $errorName, ResponseInterface $response): self | ||
{ | ||
$exceptionClass = match (strtolower($errorName)) { | ||
'unauthorizedexception' => UnauthorizedServiceException::class, | ||
'invalidrequestparamsexception' => InvalidRequestParamsException::class, | ||
'paymentrequired' => PaymentRequiredException::class, | ||
'accountonholdexception' => AccountOnHoldException::class, | ||
'resourcenotfoundexception' => ResourceNotFoundException::class, | ||
'resourcebadstateexception' => ResourceBadStateException::class, | ||
'toomanyactivationspendingexception' => TooManyActivationsPendingException::class, | ||
'toomanyrequestsexception' => TooManyRequestsException::class, | ||
'expectedpriceerrorexception' => ExpectedPriceException::class, | ||
'goneexception' => GoneException::class, | ||
'lowsuccessrateexception' => LowSuccessRateException::class, | ||
'serviceunavailableexception' => ServiceUnavailableException::class, | ||
|
||
default => self::class | ||
}; | ||
|
||
return new $exceptionClass($response); | ||
} | ||
|
||
/** | ||
* @throws TransportExceptionInterface | ||
* @throws ServerExceptionInterface | ||
* @throws RedirectionExceptionInterface | ||
* @throws DecodingExceptionInterface | ||
* @throws ClientExceptionInterface | ||
*/ | ||
public function getResultData(): array | ||
{ | ||
return $this->getResponse()->toArray(false); | ||
} | ||
|
||
/** | ||
* @return ResponseInterface | ||
*/ | ||
public function getResponse(): ResponseInterface | ||
{ | ||
return $this->response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of the TempNumberClient package. | ||
* | ||
* (c) Ahmed Ghanem <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace ahmedghanem00\TempNumberClient\Exception\API; | ||
|
||
class AccountOnHoldException extends APIException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of the TempNumberClient package. | ||
* | ||
* (c) Ahmed Ghanem <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace ahmedghanem00\TempNumberClient\Exception\API; | ||
|
||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; | ||
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface; | ||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; | ||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; | ||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; | ||
|
||
class ExpectedPriceException extends APIException | ||
{ | ||
/** | ||
* @throws TransportExceptionInterface | ||
* @throws ServerExceptionInterface | ||
* @throws RedirectionExceptionInterface | ||
* @throws DecodingExceptionInterface | ||
* @throws ClientExceptionInterface | ||
*/ | ||
public function getNewPrice(): float | ||
{ | ||
return (float)$this->getResultData()['newPrice']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of the TempNumberClient package. | ||
* | ||
* (c) Ahmed Ghanem <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace ahmedghanem00\TempNumberClient\Exception\API; | ||
|
||
class GoneException extends APIException | ||
{ | ||
public const Description = "The target resource is no longer available"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of the TempNumberClient package. | ||
* | ||
* (c) Ahmed Ghanem <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace ahmedghanem00\TempNumberClient\Exception\API; | ||
|
||
class InvalidRequestParamsException extends APIException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of the TempNumberClient package. | ||
* | ||
* (c) Ahmed Ghanem <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace ahmedghanem00\TempNumberClient\Exception\API; | ||
|
||
/** | ||
* | ||
*/ | ||
class PaymentRequiredException extends APIException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of the TempNumberClient package. | ||
* | ||
* (c) Ahmed Ghanem <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace ahmedghanem00\TempNumberClient\Exception\API; | ||
|
||
/** | ||
* | ||
*/ | ||
class ResourceNotFoundException extends APIException | ||
{ | ||
} |
Oops, something went wrong.