Add Download BT BlackList API

This commit is contained in:
alphayax 2016-05-27 20:09:17 +02:00
parent 5c7dae69f4
commit c78c3b9049
5 changed files with 90 additions and 3 deletions

View File

@ -40,6 +40,7 @@ Jusqu'a présent, les fonctionalités suivantes ont été implémentées :
- Bittorent
- Trackers
- Peers
- BlackList
- Configuration
- Connection
- Connection (Core)

View File

@ -4,7 +4,7 @@
- ~~Download Files~~
- ~~Download Trackers [UNSTABLE]~~
- ~~Download Peers [UNSTABLE]~~
- Download Blacklist [UNSTABLE]
- ~~Download Blacklist [UNSTABLE]~~
- Download Feeds
- ~~Download Configuration~~
- ~~File System Api~~

View File

@ -12,7 +12,7 @@ $App->openSession();
$DownloadService = new \alphayax\freebox\api\v3\services\download\Download( $App);
$Downloads = $DownloadService->getAll();
print_r( $Downloads);
/*
/// Trackers
$TrackerService = new \alphayax\freebox\api\v3\services\download\Tracker( $App);
$Trackers = $TrackerService->getAll( $Downloads[1]->getId());
@ -22,5 +22,8 @@ print_r( $Trackers);
$PeerService = new \alphayax\freebox\api\v3\services\download\Peer( $App);
$Peers = $PeerService->getAll( $Downloads[0]->getId());
print_r( $Peers);
*/
$BLService = new \alphayax\freebox\api\v3\services\download\BlackList( $App);
$BLEntries = $BLService->getAllFromDownloadTaskId( $Downloads[0]->getId());
print_r( $BLEntries);

View File

@ -0,0 +1,82 @@
<?php
namespace alphayax\freebox\api\v3\services\download;
use alphayax\freebox\api\v3\Service;
use alphayax\freebox\api\v3\models;
/**
* Class BlackList
* @package alphayax\freebox\api\v3\services\download
* For bittorrent downloads, we use a blacklist to store information about “useless” or broken peers. For instance if a peer is complete and we are trying to seed data, there is no use attempting to connect to this peer again.
* The download blacklist api allow you to retrieve information about this blacklist, and remove, or add peers to the blacklist.
* Each DownloadBlacklistEntry can be specific to a torrent, or “global” and apply to any torrent.
*/
class BlackList extends Service {
const API_DOWNLOAD_ITEM_BLACKLIST = '/api/v3/downloads/%u/blacklist';
const API_DOWNLOAD_ITEM_BLACKLIST_EMPTY = '/api/v3/downloads/%u/blacklist/empty';
const API_DOWNLOAD_BLACKLIST_HOST = '/api/v3/downloads/blacklist/%s';
const API_DOWNLOAD_BLACKLIST = '/api/v3/downloads/blacklist';
/**
* Get the list of blacklist entries for a given download
* Attempting to call this method on a download other than bittorent will fail.
* @param $downloadTaskId
* @return models\Download\BlackListEntry[]
*/
public function getAllFromDownloadTaskId( $downloadTaskId) {
$service = sprintf( self::API_DOWNLOAD_ITEM_BLACKLIST, $downloadTaskId);
$rest = $this->getAuthService( $service);
$rest->GET();
$BlackListEntry_xs = @$rest->getCurlResponse()['result'] ?: [];
$BlackListEntries = [];
foreach( $BlackListEntry_xs as $BlackListEntry_x) {
$BlackListEntries[] = new models\Download\BlackListEntry( $BlackListEntry_x);
}
return $BlackListEntries;
}
/**
* Empty the blacklist for a given download
* This call allow to remove all global entries, and entries related to the given download
* @param $downloadTaskId
* @return bool
*/
public function emptyBlackListFromDownloadId( $downloadTaskId) {
$service = sprintf( self::API_DOWNLOAD_ITEM_BLACKLIST_EMPTY, $downloadTaskId);
$rest = $this->getAuthService( $service);
$rest->DELETE();
return $rest->getCurlResponse()['success'];
}
/**
* Delete a particular blacklist entry
* @param $host
* @return bool
*/
public function removeBlackListEntry( $host) {
$service = sprintf( self::API_DOWNLOAD_ITEM_BLACKLIST_EMPTY, $host);
$rest = $this->getAuthService( $service);
$rest->DELETE();
return $rest->getCurlResponse()['success'];
}
/**
* Add a blacklist entry
* @param $host
* @param int $expire
* @return models\Download\BlackListEntry
*/
public function addBlackListEntry( $host, $expire = 3600) {
$rest = $this->getAuthService( self::API_DOWNLOAD_BLACKLIST);
$rest->POST([
'host' => $host,
'expire' => $expire,
]);
return new models\Download\BlackListEntry( $rest->getCurlResponse()['result']);
}
}

View File

@ -4,6 +4,7 @@ namespace alphayax\freebox\api\v3\symbols\Download\BlackListEntry;
/**
* Symbol Reason
* @package alphayax\freebox\api\v3\symbols\Download\BlackListEntry
* @see alphayax\freebox\api\v3\models\Download\BlackListEntry
*/
interface Reason {