diff --git a/README.md b/README.md index abe1f6f..d6ac46c 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,21 @@ Un document complet repertorie l'ensemble des services implémentées : [service ### Application -La premiere étape est de créer une application. -La seconde est de demander l'autorisation de connexion a la freebox (cf: cadrant led du Freebox Server) -La derniere est de récuperer une session pour utiliser les divers services de l'API +Pour acceder aux services proposés par l'API de la freebox, vous deverez +autoriser votre application. Cette procedure impose que vous soyez connecté +au réseau local de votre Freebox lors de "l'association" et que vous ayez la +Freebox a portée de main. L'application sauvegarde automatiquement le token +retourné par la frebox et cette procedure ne sera plus a reproduire. + +Notez que pour modifier les droits d'accès aux differents services, vous deverez +passer par l'interface web locale : [http://mafreebox.freebox.fr/login.php]. + +> Parametres de la freebox > Divers > Gestion des accès > Applications + + +1. Créer un objet application. +2. Demander l'autorisation de connexion a la freebox (cf: cadrant led du Freebox Server) +3. Récuperer une session pour utiliser les divers services de l'API ```php $App = new \alphayax\freebox\utils\Application( 'com.alphayax.freebox.example', 'Freebox PHP API Exemple', '0.0.1'); diff --git a/exemple/remote.php b/exemple/remote.php new file mode 100644 index 0000000..523e786 --- /dev/null +++ b/exemple/remote.php @@ -0,0 +1,12 @@ +setFreeboxApiHost( 'https://xxx.freeboxos.fr:17105'); + +$VersionService = new \alphayax\freebox\api\v3\services\ApiVersion( $App); +$version = $VersionService->getApiVersion(); +print_r( $version); diff --git a/freebox/api/v3/Service.php b/freebox/api/v3/Service.php index 66242e3..9440450 100644 --- a/freebox/api/v3/Service.php +++ b/freebox/api/v3/Service.php @@ -10,9 +10,6 @@ abstract class Service { /** @var \alphayax\freebox\utils\Application */ protected $application; - /// Freebox API host URI - const API_HOST = 'http://mafreebox.freebox.fr'; - /** * Service constructor. * @param \alphayax\freebox\utils\Application $application @@ -26,7 +23,7 @@ abstract class Service { * @return \alphayax\freebox\utils\rest\Rest */ protected function getService( $service){ - return new utils\rest\Rest( static::API_HOST . $service); + return new utils\rest\Rest( $this->application->getFreeboxApiHost() . $service); } /** @@ -36,7 +33,7 @@ abstract class Service { * @return utils\rest\RestAuth */ protected function getAuthService( $service, $isJson = true, $returnAsArray = true){ - $rest = new utils\rest\RestAuth( static::API_HOST . $service, $isJson, $returnAsArray); + $rest = new utils\rest\RestAuth( $this->application->getFreeboxApiHost() . $service, $isJson, $returnAsArray); $rest->setSessionToken( $this->application->getSessionToken()); return $rest; } diff --git a/freebox/utils/Application.php b/freebox/utils/Application.php index bbb40bd..c25caa7 100644 --- a/freebox/utils/Application.php +++ b/freebox/utils/Application.php @@ -10,6 +10,9 @@ use Monolog\Logger; */ class Application { + /// Freebox API host URI + const API_HOST_LOCAL = 'http://mafreebox.freebox.fr'; + /** @var string */ private $id = ''; @@ -25,6 +28,9 @@ class Application { /** @var string */ private $session_token = ''; + /** @var string : The freebox API Host (default is "mafreebox.freebox.fr" */ + private $freeboxApiHost = self::API_HOST_LOCAL; + /** @var Logger */ protected $logger; @@ -43,6 +49,22 @@ class Application { $this->logger->pushHandler( new ErrorLogHandler()); } + /** + * Return the Freebox API Host + * @return string + */ + public function getFreeboxApiHost() { + return $this->freeboxApiHost; + } + + /** + * Set the freebox api host + * @param string $freeboxApiHost + */ + public function setFreeboxApiHost( $freeboxApiHost) { + $this->freeboxApiHost = $freeboxApiHost; + } + /** * Ask authorization to the freebox and save the app token */