Skip to content

Commit

Permalink
Simplify Rest response check
Browse files Browse the repository at this point in the history
  • Loading branch information
alphayax committed Jun 24, 2016
1 parent 6b9f372 commit dbfca3f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
3 changes: 2 additions & 1 deletion freebox/api/v3/services/ApiVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
3 changes: 2 additions & 1 deletion freebox/api/v3/services/FileSystem/FileSystemOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
3 changes: 2 additions & 1 deletion freebox/api/v3/services/config/VPN/Server/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
24 changes: 18 additions & 6 deletions freebox/utils/rest/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -106,4 +111,11 @@ public function getSuccess(){
return boolval( $this->getCurlResponse()['success']);
}

/**
* @param boolean $isResponseToCheck
*/
public function setIsResponseToCheck( $isResponseToCheck = true){
$this->isResponseToCheck = $isResponseToCheck;
}

}
4 changes: 2 additions & 2 deletions freebox/utils/rest/RestAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit dbfca3f

Please sign in to comment.