Add Wifi config API
Add jsonSerializable on models Add travis
This commit is contained in:
parent
6fb1b7cced
commit
717624fbb9
|
@ -0,0 +1,20 @@
|
|||
language: php
|
||||
|
||||
php:
|
||||
- '5.6'
|
||||
- '7.0'
|
||||
|
||||
#install:
|
||||
# - curl -s http://getcomposer.org/installer | php
|
||||
# - php composer.phar install --dev --no-interaction
|
||||
# - composer dump-autoload
|
||||
#
|
||||
#script:
|
||||
# - mkdir -p build/cov
|
||||
# - mkdir -p build/logs
|
||||
# - php vendor/bin/phpunit -c phpunit.dist.xml
|
||||
#
|
||||
#after_success:
|
||||
# - travis_retry php vendor/bin/coveralls -v
|
||||
# - travis_retry php vendor/bin/codacycoverage clover build/logs/clover.xml
|
||||
#
|
|
@ -77,6 +77,8 @@ Jusqu'a présent, les fonctionalités suivantes ont été implémentées :
|
|||
- VPN
|
||||
- Client
|
||||
- Server
|
||||
- WiFi
|
||||
- Config (core)
|
||||
|
||||
|
||||
## Utilisation
|
||||
|
@ -153,6 +155,7 @@ Les exemples sont disponibles dans le repertoire `exemple`. Ils sont classés pa
|
|||
- `System` : Affichage de la configuration système de la freebox
|
||||
- `UPnP` : Affichage des configuration UPnP
|
||||
- `VPN` : Affiche la configuration des serveurs VPN, liste les utilisateurs...
|
||||
- `WiFi` : Affiche la configuration globale du wifi
|
||||
- `download`
|
||||
- `Download` : Listage des téléchargement en cours, liste des fichiers d'un téléchargement et mise a jour de la priorité de téléchargement
|
||||
- `DlConfig` : Affichage des configurations de téléchargement (bt, nntp...)
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
/// Require Composer AutoLoader
|
||||
require_once '../../vendor/autoload.php';
|
||||
|
||||
/// Define our application
|
||||
$App = new \alphayax\freebox\utils\Application( 'com.alphayax.freebox.config', 'PHP API Example (Config)', '1.0.0');
|
||||
$App->authorize();
|
||||
$App->openSession();
|
||||
|
||||
$WiFiConfigService = new \alphayax\freebox\api\v3\services\config\WiFi\Config( $App);
|
||||
$a = $WiFiConfigService->getConfiguration();
|
||||
print_r( $a);
|
|
@ -5,7 +5,7 @@ namespace alphayax\freebox\api\v3;
|
|||
* Class Model
|
||||
* @package alphayax\freebox\api\v3
|
||||
*/
|
||||
abstract class Model {
|
||||
abstract class Model implements \JsonSerializable {
|
||||
|
||||
/**
|
||||
* Model constructor.
|
||||
|
@ -64,4 +64,15 @@ abstract class Model {
|
|||
return $ModelArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify data which should be serialized to JSON
|
||||
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
|
||||
* @return mixed data which can be serialized by <b>json_encode</b>,
|
||||
* which is a value of any type other than a resource.
|
||||
* @since 5.4.0
|
||||
*/
|
||||
function jsonSerialize() {
|
||||
return $this->toArray();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
namespace alphayax\freebox\api\v3\models\WiFi;
|
||||
use alphayax\freebox\api\v3\Model;
|
||||
|
||||
/**
|
||||
* Class GlobalConfig
|
||||
* @package alphayax\freebox\api\v3\models\WiFi
|
||||
*/
|
||||
class GlobalConfig extends Model {
|
||||
|
||||
/** @var bool : is wifi enabled */
|
||||
protected $enabled;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @see alphayax\freebox\api\v3\symbols\WiFi\GlobalConfig\MacFilterState
|
||||
*/
|
||||
protected $mac_filter_state;
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function isEnabled() {
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $enabled
|
||||
*/
|
||||
public function setEnabled( $enabled) {
|
||||
$this->enabled = $enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @see alphayax\freebox\api\v3\symbols\WiFi\GlobalConfig\MacFilterState
|
||||
*/
|
||||
public function getMacFilterState() {
|
||||
return $this->mac_filter_state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mac_filter_state
|
||||
* @see alphayax\freebox\api\v3\symbols\WiFi\GlobalConfig\MacFilterState
|
||||
*/
|
||||
public function setMacFilterState( $mac_filter_state) {
|
||||
$this->mac_filter_state = $mac_filter_state;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
namespace alphayax\freebox\api\v3\services\config\WiFi;
|
||||
use alphayax\freebox\api\v3\models;
|
||||
use alphayax\freebox\api\v3\Service;
|
||||
|
||||
/**
|
||||
* Class Config
|
||||
* @package alphayax\freebox\api\v3\services\config\WiFi
|
||||
*/
|
||||
class Config extends Service {
|
||||
|
||||
const API_WIFI_CONFIG = '/api/v3/wifi/config/';
|
||||
const API_WIFI_CONFIG_RESET = '/api/v3/wifi/config/reset/';
|
||||
|
||||
/**
|
||||
* @return models\WiFi\GlobalConfig
|
||||
*/
|
||||
public function getConfiguration(){
|
||||
$rest = $this->getAuthService( self::API_WIFI_CONFIG);
|
||||
$rest->GET();
|
||||
|
||||
return $rest->getResult( models\WiFi\GlobalConfig::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param models\WiFi\GlobalConfig $globalConfig
|
||||
* @return models\WiFi\GlobalConfig
|
||||
*/
|
||||
public function setConfiguration( models\WiFi\GlobalConfig $globalConfig){
|
||||
$rest = $this->getAuthService( self::API_WIFI_CONFIG);
|
||||
$rest->PUT( $globalConfig);
|
||||
|
||||
return $rest->getResult( models\WiFi\GlobalConfig::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset Wifi to default configuration
|
||||
* @return bool
|
||||
*/
|
||||
public function resetConfiguration(){
|
||||
$rest = $this->getAuthService( self::API_WIFI_CONFIG_RESET);
|
||||
$rest->POST();
|
||||
|
||||
return $rest->getSuccess();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
namespace alphayax\freebox\api\v3\symbols\WiFi\GlobalConfig;
|
||||
|
||||
/**
|
||||
* Symbol MacFilterState
|
||||
* @package alphayax\freebox\api\v3\symbols\WiFi\GlobalConfig
|
||||
* @see alphayax\freebox\api\v3\models\WiFi\GlobalConfig
|
||||
*/
|
||||
interface MacFilterState {
|
||||
|
||||
/** mac filter is disabled */
|
||||
const DISABLED = 'disabled';
|
||||
|
||||
/** mac filter is enabled, using a whitelist */
|
||||
const WHITELIST = 'whitelist';
|
||||
|
||||
/** mac filter is enabled, using a blacklist */
|
||||
const BLACKLIST = 'blacklist';
|
||||
}
|
|
@ -75,7 +75,7 @@ class Rest extends alphayax\utils\Rest {
|
|||
|
||||
/**
|
||||
* @param string $className
|
||||
* @return array
|
||||
* @return array|alphayax\freebox\api\v3\Model
|
||||
*/
|
||||
public function getResult( $className = ''){
|
||||
$Model = @$this->getCurlResponse()['result'];
|
||||
|
|
|
@ -61,4 +61,28 @@ class RestAuth extends Rest {
|
|||
$this->session_token = $session_token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function checkResponse(){
|
||||
$response = $this->getCurlResponse();
|
||||
|
||||
echo ">> ". explode( "\r\n", $this->_curl_getinfo['request_header'])[0] . PHP_EOL;
|
||||
|
||||
if( false === $this->getSuccess()){
|
||||
$request = explode( PHP_EOL, @$this->_curl_getinfo['request_header'])[0];
|
||||
switch( $response['error_code']){
|
||||
case 'invalid_request' :
|
||||
$a = new alphayax\freebox\Exception\InvalidRequestException();
|
||||
$a->setHttpRequestHeader( $this->_curl_getinfo['request_header']);
|
||||
$a->setHttpUrl( $this->_curl_getinfo['url']);
|
||||
echo PHP_EOL . '---' . PHP_EOL;
|
||||
echo $this->_curl_getinfo['request_header'];
|
||||
echo PHP_EOL . '---' . PHP_EOL;
|
||||
throw $a;
|
||||
}
|
||||
throw new \Exception( $request .' - '. $response['msg'] . ' ('. $response['error_code'] . ')');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue