diff --git a/README.md b/README.md index b941a57..a47baa0 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ # Freebox v6 PHP API v3 -![license](https://img.shields.io/packagist/l/alphayax/freebox_api_php.svg) -![unstable](https://poser.pugx.org/alphayax/freebox_api_php/v/unstable) ![stable](https://poser.pugx.org/alphayax/freebox_api_php/v/stable) +![unstable](https://poser.pugx.org/alphayax/freebox_api_php/v/unstable) ![pakagist](https://img.shields.io/packagist/v/alphayax/freebox_api_php.svg) + ![codacy](https://api.codacy.com/project/badge/Grade/f3569cf671f04b8ab6d699be3fd011e5) +![license](https://img.shields.io/packagist/l/alphayax/freebox_api_php.svg) + Implementation PHP de l'API de la freebox (dans sa version 3). diff --git a/composer.json b/composer.json index e3906b5..2dc7865 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "require" : { "php": ">=5.5.0", - "alphayax/php_utils" : "^0.1.1", + "alphayax/php_utils" : "^1.0.0", "monolog/monolog": "^1.9.1" }, "autoload": { diff --git a/exemple/download/dl_rss/config/one_piece.json b/exemple/download/dl_rss/config/one_piece.json index 47529eb..d94e961 100644 --- a/exemple/download/dl_rss/config/one_piece.json +++ b/exemple/download/dl_rss/config/one_piece.json @@ -1,5 +1,5 @@ { "rss": "https:\/\/www.nyaa.se\/?page=rss&user=175467", "pattern": "\/One_Piece.*HD.*mp4\/", - "last_date": 1463909172 + "last_date": 1464513148 } \ No newline at end of file diff --git a/exemple/download/dl_rss/dl_rss.php b/exemple/download/dl_rss/dl_rss.php index 06e3313..a7ab4cd 100644 --- a/exemple/download/dl_rss/dl_rss.php +++ b/exemple/download/dl_rss/dl_rss.php @@ -5,7 +5,7 @@ use alphayax\utils\cli\IO; require_once '../../../vendor/autoload.php'; /// Define our application -$App = new \alphayax\freebox\utils\Application( 'com.alphayax.freebox.example', 'Freebox PHP API Example', '0.0.2'); +$App = new \alphayax\freebox\utils\Application( 'com.alphayax.freebox.dl_rss', 'Alphayax RSS Downloader', '1.0.0'); $App->authorize(); $App->openSession(); diff --git a/freebox/api/v3/Service.php b/freebox/api/v3/Service.php index 1dcd2fb..9f588ae 100644 --- a/freebox/api/v3/Service.php +++ b/freebox/api/v3/Service.php @@ -33,10 +33,10 @@ abstract class Service { * @param string $service * @param bool $isJson * @param bool $returnAsArray - * @return \alphayax\freebox\utils\RestAuth + * @return \alphayax\freebox\utils\rest\RestAuth */ protected function getAuthService( $service, $isJson = true, $returnAsArray = true){ - $rest = new \alphayax\freebox\utils\RestAuth( static::API_HOST . $service, $isJson, $returnAsArray); + $rest = new \alphayax\freebox\utils\rest\RestAuth( static::API_HOST . $service, $isJson, $returnAsArray); $rest->setSessionToken( $this->application->getSessionToken()); return $rest; } diff --git a/freebox/api/v3/services/login/Authorize.php b/freebox/api/v3/services/login/Authorize.php index ca0d0f5..bfe2302 100644 --- a/freebox/api/v3/services/login/Authorize.php +++ b/freebox/api/v3/services/login/Authorize.php @@ -78,6 +78,10 @@ class Authorize extends Service { ]); $response = $rest->getCurlResponse(); + if( ! $response['success']){ + $this->application->getLogger()->addCritical( 'Freebox Error : '. $response['error_code'] .' - '. $response['msg']); + throw new \Exception( $response['msg'], $response['error_code']); + } $this->application->getLogger()->addInfo( 'Authorization send to Freebox. Waiting for response...'); diff --git a/freebox/utils/RestAuth.php b/freebox/utils/rest/Rest.php similarity index 74% rename from freebox/utils/RestAuth.php rename to freebox/utils/rest/Rest.php index af90dfc..6bb978d 100644 --- a/freebox/utils/RestAuth.php +++ b/freebox/utils/rest/Rest.php @@ -1,5 +1,5 @@ */ -class RestAuth extends alphayax\utils\Rest { - - /** @var string */ - protected $session_token = ''; +class Rest extends alphayax\utils\Rest { /** * @param null $curl_post_data @@ -19,7 +16,6 @@ class RestAuth extends alphayax\utils\Rest { * @throws \Exception */ public function GET( $curl_post_data = null, $checkResponse = true){ - $this->add_XFbxAppAuth_Header(); parent::GET( $curl_post_data); if( $checkResponse){ $this->checkResponse(); @@ -30,7 +26,6 @@ class RestAuth extends alphayax\utils\Rest { * @param $curl_post_data */ public function POST( $curl_post_data = null){ - $this->add_XFbxAppAuth_Header(); parent::POST( $curl_post_data); $this->checkResponse(); } @@ -39,7 +34,6 @@ class RestAuth extends alphayax\utils\Rest { * @param $curl_post_data */ public function PUT( $curl_post_data = null){ - $this->add_XFbxAppAuth_Header(); parent::PUT( $curl_post_data); $this->checkResponse(); } @@ -48,36 +42,20 @@ class RestAuth extends alphayax\utils\Rest { * @param $curl_post_data */ public function DELETE( $curl_post_data = null){ - $this->add_XFbxAppAuth_Header(); parent::DELETE( $curl_post_data); $this->checkResponse(); } - /** - * Add the session token in the X-Fbx-App-Auth Header - */ - protected function add_XFbxAppAuth_Header(){ - $this->http_headers[ 'X-Fbx-App-Auth'] = $this->session_token; - } - - /** * @throws \Exception */ protected function checkResponse(){ - $response = $this->getCurlResponse(); - if( false === $response['success']){ + if( false === $this->getSuccess()){ + $response = $this->getCurlResponse(); throw new \Exception( $response['msg'] . ' ('. $response['error_code'] . ')'); } } - /** - * @param $session_token - */ - public function setSessionToken( $session_token){ - $this->session_token = $session_token; - } - /** * @param string $className * @return array diff --git a/freebox/utils/rest/RestAuth.php b/freebox/utils/rest/RestAuth.php new file mode 100644 index 0000000..b927a56 --- /dev/null +++ b/freebox/utils/rest/RestAuth.php @@ -0,0 +1,64 @@ + + */ +class RestAuth extends Rest { + + /** @var string */ + protected $session_token = ''; + + /** + * @param null $curl_post_data + * @param bool $checkResponse + * @throws \Exception + */ + public function GET( $curl_post_data = null, $checkResponse = true){ + $this->add_XFbxAppAuth_Header(); + parent::GET( $curl_post_data, $checkResponse); + } + + /** + * @param $curl_post_data + */ + public function POST( $curl_post_data = null){ + $this->add_XFbxAppAuth_Header(); + parent::POST( $curl_post_data); + } + + /** + * @param $curl_post_data + */ + public function PUT( $curl_post_data = null){ + $this->add_XFbxAppAuth_Header(); + parent::PUT( $curl_post_data); + } + + /** + * @param $curl_post_data + */ + public function DELETE( $curl_post_data = null){ + $this->add_XFbxAppAuth_Header(); + parent::DELETE( $curl_post_data); + } + + /** + * Add the session token in the X-Fbx-App-Auth Header + */ + protected function add_XFbxAppAuth_Header(){ + $this->addHeader( 'X-Fbx-App-Auth', $this->session_token); + } + + /** + * @param $session_token + */ + public function setSessionToken( $session_token){ + $this->session_token = $session_token; + } + +}