From 0f7df821e321cb0670905beb23ce7a6bf1585270 Mon Sep 17 00:00:00 2001 From: alphayax Date: Wed, 3 Feb 2016 20:08:23 +0100 Subject: [PATCH] Change namespaces Update RestAuth --- freebox/api/v3/{dhcp => config}/DHCP.php | 17 ++--------- freebox/utils/RestAuth.php | 37 +++++++++++++++++++----- 2 files changed, 33 insertions(+), 21 deletions(-) rename freebox/api/v3/{dhcp => config}/DHCP.php (59%) diff --git a/freebox/api/v3/dhcp/DHCP.php b/freebox/api/v3/config/DHCP.php similarity index 59% rename from freebox/api/v3/dhcp/DHCP.php rename to freebox/api/v3/config/DHCP.php index 29ccf46..d807f5b 100644 --- a/freebox/api/v3/dhcp/DHCP.php +++ b/freebox/api/v3/config/DHCP.php @@ -1,5 +1,5 @@ getAuthService( self::API_DHCP_CONFIG); $rest->GET(); - $response = $rest->getCurlResponse(); - if( ! $response->success){ - throw new \Exception( __FUNCTION__ . ' Fail'); - } - - return $response; + return $rest->getCurlResponse(); } /** @@ -34,15 +29,9 @@ class DHCP extends Service { */ public function set_attribute_configuration( $new_config_x = []){ $rest = $this->getAuthService( self::API_DHCP_CONFIG); - $rest->setSessionToken( $this->application->getSessionToken()); $rest->PUT( $new_config_x); - $response = $rest->getCurlResponse(); - if( ! $response->success){ - throw new \Exception( __FUNCTION__ . ' Fail'); - } - - return $response; + return $rest->getCurlResponse(); } } diff --git a/freebox/utils/RestAuth.php b/freebox/utils/RestAuth.php index 8626d3c..280a1eb 100644 --- a/freebox/utils/RestAuth.php +++ b/freebox/utils/RestAuth.php @@ -1,5 +1,6 @@ */ -class RestAuth extends \alphayax\utils\Rest { +class RestAuth extends alphayax\utils\Rest { /** @var string */ protected $session_token = ''; /** - * + * @param null $curl_post_data */ - public function GET(){ + public function GET( $curl_post_data = null){ $this->add_XFbxAppAuth_Header(); - parent::GET(); + parent::GET( $curl_post_data); + $this->checkResponse(); } /** * @param $curl_post_data */ - public function POST( $curl_post_data){ + public function POST( $curl_post_data = null){ $this->add_XFbxAppAuth_Header(); parent::POST( $curl_post_data); + $this->checkResponse(); } /** * @param $curl_post_data */ - public function PUT( $curl_post_data){ + public function PUT( $curl_post_data = null){ $this->add_XFbxAppAuth_Header(); parent::PUT( $curl_post_data); + $this->checkResponse(); + } + + /** + * @param $curl_post_data + */ + public function DELETE( $curl_post_data = null){ + $this->add_XFbxAppAuth_Header(); + parent::DELETE( $curl_post_data); + $this->checkResponse(); } /** @@ -45,10 +58,20 @@ class RestAuth extends \alphayax\utils\Rest { )); } + /** + * @throws \Exception + */ + protected function checkResponse(){ + $response = $this->getCurlResponse(); + if( false === $response->success){ + throw new \Exception( $response->msg); + } + } + /** * @param $session_token */ - public function setSessionToken($session_token){ + public function setSessionToken( $session_token){ $this->session_token = $session_token; } }