Add Download Configuration API

This commit is contained in:
alphayax 2016-05-26 22:03:04 +02:00
parent de0de43157
commit 08bc5e89c9
5 changed files with 88 additions and 4 deletions

View File

@ -36,6 +36,7 @@ Jusqu'a présent, les fonctionalités suivantes ont été implémentées :
- Download (core)
- Download Stats
- Download Files
- Download Configuration
- Configuration
- Connection
- Connection (Core)
@ -133,7 +134,8 @@ 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
- `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
- `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...)
- `dl_rss` : Un script qui parse les flux RSS et qui rajoute en téléchagement les items correspondant a une expression réguliere

View File

@ -6,7 +6,7 @@
- Download Peers [UNSTABLE]
- Download Blacklist [UNSTABLE]
- Download Feeds
- Download Configuration
- ~~Download Configuration~~
- ~~File System Api~~
- ~~File System~~
- ~~File Sharing Link~~

View File

@ -0,0 +1,17 @@
<?php
/// Require Composer AutoLoader
require_once '../../vendor/autoload.php';
/// Define our application
$App = new \alphayax\freebox\utils\Application( 'com.alphayax.freebox.download', 'PHP API Example (Download)', '1.0.0');
$App->authorize();
$App->openSession();
/// Download configuration
$DownloadConfigService = new \alphayax\freebox\api\v3\services\download\Configuration( $App);
$DlConfig = $DownloadConfigService->getConfiguration();
print_r( $DlConfig);
$DlConfig = $DownloadConfigService->updateThrottlingMode( 'normal');
print_r( $DlConfig);

View File

@ -14,12 +14,12 @@ class DlThrottlingConfig extends Model {
/** @var DlRate : download rate for normal slow slot (in B/s) */
protected $slow;
/** @var string
/** @var string[168]
* The schedule array represent the list of week hours timeslot, starting on monday a midnight.
* Therefore the complete week is represented in a array of 168 elements (24 * 7)
* @see alphayax\freebox\api\v3\symbols\Download\Config\DlThrottlingConfig\Schedule
*/
protected $schedule;
protected $schedule = [];
/**
* @var string
@ -27,6 +27,16 @@ class DlThrottlingConfig extends Model {
*/
protected $mode;
/**
* DlThrottlingConfig constructor.
* @param array $properties_x
*/
public function __construct( array $properties_x){
parent::__construct( $properties_x);
$this->initProperty( '$normal' , DlRate::class);
$this->initProperty( 'slow' , DlRate::class);
}
/**
* @return DlRate
*/

View File

@ -0,0 +1,55 @@
<?php
namespace alphayax\freebox\api\v3\services\download;
use alphayax\freebox\api\v3\Service;
use alphayax\freebox\api\v3\models;
/**
* Class Configuration
* @package alphayax\freebox\api\v3\services\download
*/
class Configuration extends Service {
const API_DOWNLOAD_CONFIG = '/api/v3/downloads/config/';
const API_DOWNLOAD_THROTTLING = '/api/v3/downloads/throttling';
/**
* Get the current Download configuration
* @return models\Download\Config\DownloadConfig
*/
public function getConfiguration(){
$rest = $this->getAuthService( self::API_DOWNLOAD_CONFIG);
$rest->GET();
return new models\Download\Config\DownloadConfig( $rest->getCurlResponse()['result']);
}
/**
* Update the Download configuration
* @param models\Download\Config\DownloadConfig $downloadConfig
* @return models\Download\Config\DownloadConfig
*/
public function setConfiguration( models\Download\Config\DownloadConfig $downloadConfig){
$rest = $this->getAuthService( self::API_DOWNLOAD_CONFIG);
$rest->PUT( $downloadConfig->toArray());
return new models\Download\Config\DownloadConfig( $rest->getCurlResponse()['result']);
}
/**
* You can force the throttling mode using this method.
* You can use any of the throttling modes defined in DlThrottlingConfig.
* Setting to schedule will automatically set correct throttling mode.
* Other values will force the throttling mode until you set it back to schedule.
* @param string $throttlingMode
* @return array [is_scheduled, throttling]
*/
public function updateThrottlingMode( $throttlingMode = 'normal'){
$rest = $this->getAuthService( self::API_DOWNLOAD_THROTTLING);
$rest->PUT([
'throttling' => $throttlingMode,
]);
return $rest->getCurlResponse()['result'];
}
}