Add remote access
This commit is contained in:
parent
d545be09a1
commit
16b83e2dc0
18
README.md
18
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');
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
/// Require Composer AutoLoader
|
||||
require_once '../vendor/autoload.php';
|
||||
|
||||
/// Define our application
|
||||
$App = new \alphayax\freebox\utils\Application( 'com.alphayax.freebox.version', 'Freebox PHP API Example (Version)', '1.0.0');
|
||||
$App->setFreeboxApiHost( 'https://xxx.freeboxos.fr:17105');
|
||||
|
||||
$VersionService = new \alphayax\freebox\api\v3\services\ApiVersion( $App);
|
||||
$version = $VersionService->getApiVersion();
|
||||
print_r( $version);
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue