From dbfca3f6a418cfd93193c870c0173e879c12fe82 Mon Sep 17 00:00:00 2001 From: alphayax Date: Fri, 24 Jun 2016 16:34:06 +0200 Subject: [PATCH] Simplify Rest response check --- freebox/api/v3/services/ApiVersion.php | 3 ++- .../FileSystem/FileSystemOperation.php | 3 ++- .../v3/services/config/VPN/Server/User.php | 3 ++- freebox/utils/rest/Rest.php | 24 ++++++++++++++----- freebox/utils/rest/RestAuth.php | 4 ++-- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/freebox/api/v3/services/ApiVersion.php b/freebox/api/v3/services/ApiVersion.php index 1d66b0e..708a172 100644 --- a/freebox/api/v3/services/ApiVersion.php +++ b/freebox/api/v3/services/ApiVersion.php @@ -16,7 +16,8 @@ class ApiVersion extends Service { */ public function getApiVersion() { $rest = $this->getService( static::API_VERSION); - $rest->GET( null, false); + $rest->setIsResponseToCheck( false); + $rest->GET(); return $rest->getCurlResponse(); } diff --git a/freebox/api/v3/services/FileSystem/FileSystemOperation.php b/freebox/api/v3/services/FileSystem/FileSystemOperation.php index 73c2507..b73651d 100644 --- a/freebox/api/v3/services/FileSystem/FileSystemOperation.php +++ b/freebox/api/v3/services/FileSystem/FileSystemOperation.php @@ -270,7 +270,8 @@ public function rename( $sourceFilePath, $newFileName){ */ public function download( $sourceFilePath){ $rest = $this->getAuthService( self::API_DOWNLOAD . base64_encode( $sourceFilePath), false, false); - $rest->GET( null, false); + $rest->setIsResponseToCheck( false); + $rest->GET(); return $rest->getCurlResponse(); } diff --git a/freebox/api/v3/services/config/VPN/Server/User.php b/freebox/api/v3/services/config/VPN/Server/User.php index 42dd310..83f8927 100644 --- a/freebox/api/v3/services/config/VPN/Server/User.php +++ b/freebox/api/v3/services/config/VPN/Server/User.php @@ -89,7 +89,8 @@ public function update( models\VPN\Server\User $user){ public function getConfigurationFile( $serverName, $login){ $service = sprintf( self::API_VPN_USER_CONFIG, $serverName, $login); $rest = $this->getAuthService( $service, false, false); - $rest->GET( null, false); + $rest->setIsResponseToCheck( false); + $rest->GET(); return $rest->getCurlResponse(); } diff --git a/freebox/utils/rest/Rest.php b/freebox/utils/rest/Rest.php index 7686302..0e5e346 100644 --- a/freebox/utils/rest/Rest.php +++ b/freebox/utils/rest/Rest.php @@ -10,16 +10,16 @@ */ class Rest extends alphayax\utils\Rest { + /** @var bool */ + protected $isResponseToCheck = true; + /** * @param null $curlPostData - * @param bool $checkResponse - * @throws \Exception + * @throws \alphayax\freebox\Exception\FreeboxApiException */ - public function GET( $curlPostData = null, $checkResponse = true){ + public function GET( $curlPostData = null){ parent::GET( $curlPostData); - if( $checkResponse){ - $this->checkResponse(); - } + $this->checkResponse(); } /** @@ -54,6 +54,11 @@ protected function checkResponse(){ $url = $this->curlGetInfo['url']; // echo ">> $request ($url)" . PHP_EOL; + /// Don't need to go further if the response have not to be checked (binary content, non standard response, ...) + if( ! $this->isResponseToCheck){ + return; + } + if( false === $this->getSuccess()){ $response = $this->getCurlResponse(); @@ -106,4 +111,11 @@ public function getSuccess(){ return boolval( $this->getCurlResponse()['success']); } + /** + * @param boolean $isResponseToCheck + */ + public function setIsResponseToCheck( $isResponseToCheck = true){ + $this->isResponseToCheck = $isResponseToCheck; + } + } diff --git a/freebox/utils/rest/RestAuth.php b/freebox/utils/rest/RestAuth.php index 14566a4..e81cfd6 100644 --- a/freebox/utils/rest/RestAuth.php +++ b/freebox/utils/rest/RestAuth.php @@ -18,9 +18,9 @@ class RestAuth extends Rest { * @param bool $checkResponse * @throws \Exception */ - public function GET( $curlPostData = null, $checkResponse = true){ + public function GET( $curlPostData = null){ $this->add_XFbxAppAuth_Header(); - parent::GET( $curlPostData, $checkResponse); + parent::GET( $curlPostData); } /**