Update Documentation & readme

Clean up & comment download & FileSystem services
Refractor public functions services
This commit is contained in:
alphayax 2016-06-12 16:25:26 +02:00
parent 13389615be
commit af7a15c8e8
15 changed files with 139 additions and 188 deletions

View File

@ -16,7 +16,7 @@
"monolog/monolog": "^1.9.1" "monolog/monolog": "^1.9.1"
}, },
"require-dev" : { "require-dev" : {
"alphayax/phpdoc_md" : "^1.0.1", "alphayax/phpdoc_md" : "^1.0.3",
"codacy/coverage": "<2.0.0", "codacy/coverage": "<2.0.0",
"phpunit/phpunit": "^5.4.0", "phpunit/phpunit": "^5.4.0",
"zf1/zend-reflection": "1.12.*" "zf1/zend-reflection": "1.12.*"

View File

@ -20,9 +20,9 @@
| Method | Description | | Method | Description |
|---|---| |---|---|
| `getAll` | Retrieve a File Sharing link | | `getAll` | Retrieve all File Sharing links |
| `getFromToken` | | | `getFromToken` | Get a file sharing link from his token identifier |
| `deleteFromToken` | Delete a File Sharing link Deletes the ShareLink task with the given token, if the task was running, stop it. | | `deleteFromToken` | Delete a File Sharing link for his token identifier Deletes the ShareLink task with the given token, if the task was running, stop it. |
| `create` | Create a File Sharing link | | `create` | Create a File Sharing link |
<a name="FileSystemListing"></a> <a name="FileSystemListing"></a>
@ -34,7 +34,7 @@
| Method | Description | | Method | Description |
|---|---| |---|---|
| `getFilesFromDirectory` | | | `getFilesFromDirectory` | Get all files in a given directory |
| `getFileInformation` | Get file information | | `getFileInformation` | Get file information |
<a name="FileSystemOperation"></a> <a name="FileSystemOperation"></a>
@ -57,7 +57,7 @@
| `getHashValue` | Get the hash value To get the hash, the task must have succeed and be in the state “done”. | | `getHashValue` | Get the hash value To get the hash, the task must have succeed and be in the state “done”. |
| `createDirectory` | Create a directory Contrary to other file system tasks, this operation is done synchronously. | | `createDirectory` | Create a directory Contrary to other file system tasks, this operation is done synchronously. |
| `rename` | Rename a file/folder Contrary to other file system tasks, this operation is done synchronously. | | `rename` | Rename a file/folder Contrary to other file system tasks, this operation is done synchronously. |
| `download` | Download a file from the freebox server | | `download` | Download a file from the freebox server (return the file content) |
<a name="FileSystemTask"></a> <a name="FileSystemTask"></a>
## FileSystemTask ## FileSystemTask

View File

@ -50,12 +50,16 @@
|---|---| |---|---|
| `getAll` | Returns the collection of all Download tasks | | `getAll` | Returns the collection of all Download tasks |
| `getFromId` | Returns the Download task with the given id | | `getFromId` | Returns the Download task with the given id |
| `getLogFromId` | Get the current system info |
| `deleteFromId` | Delete a download task (conserve data) |
| `eraseFromId` | Delete a download task (erase data) |
| `update` | Update a download task | | `update` | Update a download task |
| `addFromUrl` | | | `addFromUrl` | Add a download task with the specified URL |
| `addFromUrls` | | | `addFromUrls` | Add a download task with all the specified URLs |
| `addFromFile` | | | `addFromFile` | Add a download task with the specified file (torrent, nzb...) |
| `getStats` | Returns the Download task with the given id | | `getStats` | Returns the Download task with the given id |
| `getFilesFromId` | Returns the Download task with the given id | | `getFilesFromId` | Returns the downloaded files with the given task id |
| `updateFilePriority` | Update a download priority |
<a name="Feed"></a> <a name="Feed"></a>
## Feed ## Feed
@ -75,8 +79,8 @@
| `refreshFeeds` | Remotely fetches the RSS feed and updates it. Note that if the remote feed specifies a TTL, trying to update before the ttl will result in feed_is_recent error | | `refreshFeeds` | Remotely fetches the RSS feed and updates it. Note that if the remote feed specifies a TTL, trying to update before the ttl will result in feed_is_recent error |
| `getFeedItems` | Returns the collection of all DownloadFeedItems for a given DownloadFeed | | `getFeedItems` | Returns the collection of all DownloadFeedItems for a given DownloadFeed |
| `updateFeedItem` | Returns the collection of all DownloadFeedItems for a given DownloadFeed | | `updateFeedItem` | Returns the collection of all DownloadFeedItems for a given DownloadFeed |
| `downloadFeedItem` | Returns the collection of all DownloadFeedItems for a given DownloadFeed | | `downloadFeedItem` | Download the specified feed item |
| `markFeedAsRead` | Returns the collection of all DownloadFeedItems for a given DownloadFeed | | `markFeedAsRead` | Mark the specified feed id as "Read" |
<a name="Peer"></a> <a name="Peer"></a>
## Peer ## Peer

View File

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

View File

@ -1,6 +1,6 @@
<?php <?php
namespace alphayax\freebox\api\v3\services\FileSystem; namespace alphayax\freebox\api\v3\services\FileSystem;
use alphayax\freebox\api\v3\models\FileSystem\ShareLink; use alphayax\freebox\api\v3\models;
use alphayax\freebox\api\v3\Service; use alphayax\freebox\api\v3\Service;
@ -13,35 +13,30 @@ class FileSharingLink extends Service {
const API_SHARE_LINK = '/api/v3/share_link/'; const API_SHARE_LINK = '/api/v3/share_link/';
/** /**
* Retrieve a File Sharing link * Retrieve all File Sharing links
* @return ShareLink[] * @return models\FileSystem\ShareLink[]
*/ */
public function getAll(){ public function getAll(){
$rest = $this->getAuthService( self::API_SHARE_LINK); $rest = $this->getAuthService( self::API_SHARE_LINK);
$rest->GET(); $rest->GET();
$ApiReturn = $rest->getCurlResponse(); return $rest->getResultAsArray( models\FileSystem\ShareLink::class);
$FileSharingLinks = [];
$FileSharingLink_xs = @$ApiReturn['result'] ?: [];
foreach( $FileSharingLink_xs as $fileSharingLink_x){
$FileSharingLinks[] = new ShareLink( $fileSharingLink_x);
}
return $FileSharingLinks;
} }
/** /**
* Get a file sharing link from his token identifier
* @param $Token * @param $Token
* @return ShareLink * @return models\FileSystem\ShareLink
*/ */
public function getFromToken( $Token){ public function getFromToken( $Token){
$rest = $this->getAuthService( self::API_SHARE_LINK . $Token); $rest = $this->getAuthService( self::API_SHARE_LINK . $Token);
$rest->GET(); $rest->GET();
return new ShareLink( $rest->getCurlResponse()['result']); return $rest->getResult( models\FileSystem\ShareLink::class);
} }
/** /**
* Delete a File Sharing link * Delete a File Sharing link for his token identifier
* Deletes the ShareLink task with the given token, if the task was running, stop it. * Deletes the ShareLink task with the given token, if the task was running, stop it.
* No rollback is done, if a file as already been processed it will be left as is. * No rollback is done, if a file as already been processed it will be left as is.
* @param $Token * @param $Token
@ -51,7 +46,7 @@ class FileSharingLink extends Service {
$rest = $this->getAuthService( self::API_SHARE_LINK . $Token); $rest = $this->getAuthService( self::API_SHARE_LINK . $Token);
$rest->DELETE(); $rest->DELETE();
return $rest->getCurlResponse()['success']; return $rest->getSuccess();
} }
/** /**
@ -59,7 +54,7 @@ class FileSharingLink extends Service {
* @param string $Path * @param string $Path
* @param int $expire * @param int $expire
* @param string $fullUrl * @param string $fullUrl
* @return ShareLink * @return models\FileSystem\ShareLink
*/ */
public function create( $Path, $expire = 0, $fullUrl = ''){ public function create( $Path, $expire = 0, $fullUrl = ''){
$Path_b64 = base64_encode( $Path); $Path_b64 = base64_encode( $Path);
@ -71,7 +66,7 @@ class FileSharingLink extends Service {
'fullurl' => $fullUrl, 'fullurl' => $fullUrl,
]); ]);
return new ShareLink( $rest->getCurlResponse()['result']); return $rest->getResult( models\FileSystem\ShareLink::class);
} }
} }

View File

@ -1,6 +1,6 @@
<?php <?php
namespace alphayax\freebox\api\v3\services\FileSystem; namespace alphayax\freebox\api\v3\services\FileSystem;
use alphayax\freebox\api\v3\models\FileSystem\FileInfo; use alphayax\freebox\api\v3\models;
use alphayax\freebox\api\v3\Service; use alphayax\freebox\api\v3\Service;
@ -14,11 +14,12 @@ class FileSystemListing extends Service {
const API_FS_INFO = '/api/v3/fs/info/'; const API_FS_INFO = '/api/v3/fs/info/';
/** /**
* Get all files in a given directory
* @param string $DirectoryName * @param string $DirectoryName
* @param bool $onlyFolder Only list folders * @param bool $onlyFolder Only list folders
* @param bool $countSubFolder Return files and subfolder count for folders * @param bool $countSubFolder Return files and sub-folder count for folders
* @param bool $removeHidden Dont return hidden files in directory listing * @param bool $removeHidden Dont return hidden files in directory listing
* @return FileInfo[] * @return models\FileSystem\FileInfo[]
*/ */
public function getFilesFromDirectory( $DirectoryName = '/Disque dur/', $onlyFolder = true, $countSubFolder = false, $removeHidden = true){ public function getFilesFromDirectory( $DirectoryName = '/Disque dur/', $onlyFolder = true, $countSubFolder = false, $removeHidden = true){
$Directory_b64 = base64_encode( $DirectoryName); $Directory_b64 = base64_encode( $DirectoryName);
@ -29,25 +30,20 @@ class FileSystemListing extends Service {
'removeHidden' => $removeHidden, 'removeHidden' => $removeHidden,
]); ]);
$FileInfo_xs = $rest->getCurlResponse()['result']; return $rest->getResultAsArray( models\FileSystem\FileInfo::class);
$FileInfos = [];
foreach( $FileInfo_xs as $FileInfo_x) {
$FileInfos[] = new FileInfo( $FileInfo_x);
}
return $FileInfos;
} }
/** /**
* Get file information * Get file information
* @param string $DirectoryName * @param string $DirectoryName
* @return FileInfo * @return models\FileSystem\FileInfo
*/ */
public function getFileInformation( $DirectoryName){ public function getFileInformation( $DirectoryName){
$Directory_b64 = base64_encode( $DirectoryName); $Directory_b64 = base64_encode( $DirectoryName);
$rest = $this->getAuthService( self::API_FS_INFO . $Directory_b64); $rest = $this->getAuthService( self::API_FS_INFO . $Directory_b64);
$rest->GET(); $rest->GET();
return new FileInfo( $rest->getCurlResponse()['result']); return $rest->getResult( models\FileSystem\FileInfo::class);
} }
} }

View File

@ -1,6 +1,6 @@
<?php <?php
namespace alphayax\freebox\api\v3\services\FileSystem; namespace alphayax\freebox\api\v3\services\FileSystem;
use alphayax\freebox\api\v3\models\FileSystem\FsTask; use alphayax\freebox\api\v3\models;
use alphayax\freebox\api\v3\Service; use alphayax\freebox\api\v3\Service;
@ -28,7 +28,7 @@ class FileSystemOperation extends Service {
* @param string[] $sourceFiles * @param string[] $sourceFiles
* @param string $destination * @param string $destination
* @param string $conflictMode * @param string $conflictMode
* @return FsTask * @return models\FileSystem\FsTask
*/ */
public function move( array $sourceFiles = [], $destination, $conflictMode = 'recent'){ public function move( array $sourceFiles = [], $destination, $conflictMode = 'recent'){
/// Convert all paths in base64 /// Convert all paths in base64
@ -45,7 +45,7 @@ class FileSystemOperation extends Service {
'mode' => $conflictMode, 'mode' => $conflictMode,
]); ]);
return new FsTask( $rest->getCurlResponse()['result']); return $rest->getResult( models\FileSystem\FsTask::class);
} }
/** /**
@ -53,7 +53,7 @@ class FileSystemOperation extends Service {
* @param string[] $sourceFiles * @param string[] $sourceFiles
* @param string $destination * @param string $destination
* @param string $conflictMode * @param string $conflictMode
* @return FsTask * @return models\FileSystem\FsTask
*/ */
public function copy( array $sourceFiles = [], $destination, $conflictMode = 'recent'){ public function copy( array $sourceFiles = [], $destination, $conflictMode = 'recent'){
/// Convert all paths in base64 /// Convert all paths in base64
@ -70,13 +70,13 @@ class FileSystemOperation extends Service {
'mode' => $conflictMode, 'mode' => $conflictMode,
]); ]);
return new FsTask( $rest->getCurlResponse()['result']); return $rest->getResult( models\FileSystem\FsTask::class);
} }
/** /**
* Delete files * Delete files
* @param string[] $RemoveFiles * @param string[] $RemoveFiles
* @return FsTask * @return models\FileSystem\FsTask
*/ */
public function remove( array $RemoveFiles = []){ public function remove( array $RemoveFiles = []){
/// Convert all paths in base64 /// Convert all paths in base64
@ -90,7 +90,7 @@ class FileSystemOperation extends Service {
'files' => $removedFiles_b64, 'files' => $removedFiles_b64,
]); ]);
return new FsTask( $rest->getCurlResponse()['result']); return $rest->getResult( models\FileSystem\FsTask::class);
} }
/** /**
@ -101,7 +101,7 @@ class FileSystemOperation extends Service {
* @param bool $isToDelete : Deletes source files * @param bool $isToDelete : Deletes source files
* @param bool $isToOverwrite : Overwrites the destination * @param bool $isToOverwrite : Overwrites the destination
* @param bool $isToAppend : Append to the destination * @param bool $isToAppend : Append to the destination
* @return FsTask * @return models\FileSystem\FsTask
*/ */
public function cat( array $fileParts = [], $destination, $isMultiVolumes = false, $isToDelete = false, $isToOverwrite = false, $isToAppend = false){ public function cat( array $fileParts = [], $destination, $isMultiVolumes = false, $isToDelete = false, $isToOverwrite = false, $isToAppend = false){
/// Convert all paths in base64 /// Convert all paths in base64
@ -121,14 +121,14 @@ class FileSystemOperation extends Service {
'overwrite' => $isToOverwrite, 'overwrite' => $isToOverwrite,
]); ]);
return new FsTask( $rest->getCurlResponse()['result']); return $rest->getResult( models\FileSystem\FsTask::class);
} }
/** /**
* Create an archive * Create an archive
* @param string[] $fileParts : The list of files to concatenate * @param string[] $fileParts : The list of files to concatenate
* @param string $destination : The destination file * @param string $destination : The destination file
* @return FsTask * @return models\FileSystem\FsTask
*/ */
public function archive( array $fileParts = [], $destination){ public function archive( array $fileParts = [], $destination){
/// Convert all paths in base64 /// Convert all paths in base64
@ -144,7 +144,7 @@ class FileSystemOperation extends Service {
'dst' => $destination_b64, 'dst' => $destination_b64,
]); ]);
return new FsTask( $rest->getCurlResponse()['result']); return $rest->getResult( models\FileSystem\FsTask::class);
} }
/** /**
@ -154,7 +154,7 @@ class FileSystemOperation extends Service {
* @param string $password : The archive password * @param string $password : The archive password
* @param bool $isToDelete : Delete archive after extraction * @param bool $isToDelete : Delete archive after extraction
* @param bool $isToOverwrite : Overwrites the destination * @param bool $isToOverwrite : Overwrites the destination
* @return FsTask * @return models\FileSystem\FsTask
*/ */
public function extract( $source, $destination, $password = '', $isToDelete = false, $isToOverwrite = false){ public function extract( $source, $destination, $password = '', $isToDelete = false, $isToOverwrite = false){
/// Convert all paths in base64 /// Convert all paths in base64
@ -170,14 +170,14 @@ class FileSystemOperation extends Service {
'overwrite' => $isToOverwrite, 'overwrite' => $isToOverwrite,
]); ]);
return new FsTask( $rest->getCurlResponse()['result']); return $rest->getResult( models\FileSystem\FsTask::class);
} }
/** /**
* Repair files from a .par2 * Repair files from a .par2
* @param string $source : The .par2 file * @param string $source : The .par2 file
* @param bool $isToDelete : Delete par2 files after repair * @param bool $isToDelete : Delete par2 files after repair
* @return FsTask * @return models\FileSystem\FsTask
*/ */
public function repair( $source, $isToDelete = false){ public function repair( $source, $isToDelete = false){
/// Convert all paths in base64 /// Convert all paths in base64
@ -189,7 +189,7 @@ class FileSystemOperation extends Service {
'delete_archive' => $isToDelete, 'delete_archive' => $isToDelete,
]); ]);
return new FsTask( $rest->getCurlResponse()['result']); return $rest->getResult( models\FileSystem\FsTask::class);
} }
/** /**
@ -198,7 +198,7 @@ class FileSystemOperation extends Service {
* @see * @see
* @param string $source : The file to hash * @param string $source : The file to hash
* @param string $hashType : The type of hash (md5, sha1, ...) - Default is md5 * @param string $hashType : The type of hash (md5, sha1, ...) - Default is md5
* @return FsTask * @return models\FileSystem\FsTask
*/ */
public function computeHash( $source, $hashType = 'md5'){ public function computeHash( $source, $hashType = 'md5'){
/// Convert all paths in base64 /// Convert all paths in base64
@ -210,7 +210,7 @@ class FileSystemOperation extends Service {
'hash_type' => $hashType, 'hash_type' => $hashType,
]); ]);
return new FsTask( $rest->getCurlResponse()['result']); return $rest->getResult( models\FileSystem\FsTask::class);
} }
/** /**
@ -224,7 +224,7 @@ class FileSystemOperation extends Service {
$rest = $this->getAuthService( $service); $rest = $this->getAuthService( $service);
$rest->GET(); $rest->GET();
return $rest->getCurlResponse()['result']; return $rest->getResult();
} }
/** /**
@ -242,7 +242,7 @@ class FileSystemOperation extends Service {
'dirname' => $newDirectoryName, 'dirname' => $newDirectoryName,
]); ]);
return $rest->getCurlResponse()['success']; return $rest->getSuccess();
} }
/** /**
@ -260,11 +260,11 @@ class FileSystemOperation extends Service {
'dst' => $newFileName, 'dst' => $newFileName,
]); ]);
return $rest->getCurlResponse()['success']; return $rest->getSuccess();
} }
/** /**
* Download a file from the freebox server * Download a file from the freebox server (return the file content)
* @param string $sourceFilePath * @param string $sourceFilePath
* @return mixed * @return mixed
*/ */

View File

@ -1,6 +1,6 @@
<?php <?php
namespace alphayax\freebox\api\v3\services\FileSystem; namespace alphayax\freebox\api\v3\services\FileSystem;
use alphayax\freebox\api\v3\models\FileSystem\FsTask; use alphayax\freebox\api\v3\models;
use alphayax\freebox\api\v3\Service; use alphayax\freebox\api\v3\Service;
@ -14,36 +14,31 @@ class FileSystemTask extends Service {
/** /**
* @throws \Exception * @throws \Exception
* @return FsTask[] * @return models\FileSystem\FsTask[]
*/ */
public function getAllTasks(){ public function getAllTasks(){
$rest = $this->getAuthService( self::API_FS_TASK); $rest = $this->getAuthService( self::API_FS_TASK);
$rest->GET(); $rest->GET();
$FsTask_xs = $rest->getCurlResponse()['result']; return $rest->getResultAsArray( models\FileSystem\FsTask::class);
$FsTasks = [];
foreach( $FsTask_xs as $fsTask_x) {
$FsTasks[] = new FsTask( $fsTask_x);
}
return $FsTasks;
} }
/** /**
* @param int $TaskId * @param int $TaskId
* @return FsTask * @return models\FileSystem\FsTask
*/ */
public function getTaskById( $TaskId){ public function getTaskById( $TaskId){
$rest = $this->getAuthService( self::API_FS_TASK . $TaskId); $rest = $this->getAuthService( self::API_FS_TASK . $TaskId);
$rest->GET(); $rest->GET();
return new FsTask( $rest->getCurlResponse()['result']); return $rest->getResult( models\FileSystem\FsTask::class);
} }
/** /**
* @param FsTask $FsTask * @param models\FileSystem\FsTask $FsTask
* @return bool * @return bool
*/ */
public function deleteTask( FsTask $FsTask){ public function deleteTask( models\FileSystem\FsTask $FsTask){
return $this->deleteTaskById( $FsTask->getId()); return $this->deleteTaskById( $FsTask->getId());
} }
@ -55,18 +50,18 @@ class FileSystemTask extends Service {
$rest = $this->getAuthService( self::API_FS_TASK . $TaskId); $rest = $this->getAuthService( self::API_FS_TASK . $TaskId);
$rest->DELETE(); $rest->DELETE();
return $rest->getCurlResponse()['success']; return $rest->getSuccess();
} }
/** /**
* @param FsTask $FsTask * @param models\FileSystem\FsTask $FsTask
* @return bool * @return bool
*/ */
public function updateTask( FsTask $FsTask){ public function updateTask( models\FileSystem\FsTask $FsTask){
$rest = $this->getAuthService( self::API_FS_TASK . $FsTask->getId()); $rest = $this->getAuthService( self::API_FS_TASK . $FsTask->getId());
$rest->PUT( $FsTask->toArray()); $rest->PUT( $FsTask);
return $rest->getCurlResponse()['success']; return $rest->getSuccess();
} }
} }

View File

@ -28,7 +28,7 @@ class FileUpload extends Service {
'upload_name' => $FileName, 'upload_name' => $FileName,
]); ]);
return (int) $rest->getCurlResponse()['result']['id']; return (int) $rest->getResult()['id'];
} }
/** /**
@ -45,7 +45,7 @@ class FileUpload extends Service {
basename( $fileToUpload_afi) => new \CurlFile( $fileToUpload_afi), basename( $fileToUpload_afi) => new \CurlFile( $fileToUpload_afi),
]); ]);
return $rest->getCurlResponse()['success']; return $rest->getSuccess();
} }
/** /**
@ -56,12 +56,7 @@ class FileUpload extends Service {
$rest = $this->getAuthService( self::API_UPLOAD); $rest = $this->getAuthService( self::API_UPLOAD);
$rest->GET(); $rest->GET();
$FileUpload_xs = @$rest->getCurlResponse()['result'] ?: []; return $rest->getResultAsArray( models\FileSystem\FileUpload::class);
$FileUploads = [];
foreach( $FileUpload_xs as $FileUpload_x) {
$FileUploads[] = new models\FileSystem\FileUpload( $FileUpload_x);
}
return $FileUploads;
} }
/** /**
@ -73,7 +68,7 @@ class FileUpload extends Service {
$rest = $this->getAuthService( self::API_UPLOAD . $FileUploadId); $rest = $this->getAuthService( self::API_UPLOAD . $FileUploadId);
$rest->GET(); $rest->GET();
return new models\FileSystem\FileUpload( $rest->getCurlResponse()['result']); return $rest->getResult( models\FileSystem\FileUpload::class);
} }
/** /**
@ -87,7 +82,7 @@ class FileUpload extends Service {
$rest = $this->getAuthService( $Service); $rest = $this->getAuthService( $Service);
$rest->DELETE(); $rest->DELETE();
return $rest->getCurlResponse()['success']; return $rest->getSuccess();
} }
/** /**
@ -99,7 +94,7 @@ class FileUpload extends Service {
$rest = $this->getAuthService( self::API_UPLOAD . $FileUploadId); $rest = $this->getAuthService( self::API_UPLOAD . $FileUploadId);
$rest->DELETE(); $rest->DELETE();
return $rest->getCurlResponse()['success']; return $rest->getSuccess();
} }
/** /**
@ -110,7 +105,7 @@ class FileUpload extends Service {
$rest = $this->getAuthService( self::API_UPLOAD_CLEAN); $rest = $this->getAuthService( self::API_UPLOAD_CLEAN);
$rest->DELETE(); $rest->DELETE();
return $rest->getCurlResponse()['success']; return $rest->getSuccess();
} }
} }

View File

@ -28,12 +28,7 @@ class BlackList extends Service {
$rest = $this->getAuthService( $service); $rest = $this->getAuthService( $service);
$rest->GET(); $rest->GET();
$BlackListEntry_xs = @$rest->getCurlResponse()['result'] ?: []; return $rest->getResultAsArray( models\Download\BlackListEntry::class);
$BlackListEntries = [];
foreach( $BlackListEntry_xs as $BlackListEntry_x) {
$BlackListEntries[] = new models\Download\BlackListEntry( $BlackListEntry_x);
}
return $BlackListEntries;
} }
/** /**
@ -47,7 +42,7 @@ class BlackList extends Service {
$rest = $this->getAuthService( $service); $rest = $this->getAuthService( $service);
$rest->DELETE(); $rest->DELETE();
return $rest->getCurlResponse()['success']; return $rest->getSuccess();
} }
/** /**
@ -60,7 +55,7 @@ class BlackList extends Service {
$rest = $this->getAuthService( $service); $rest = $this->getAuthService( $service);
$rest->DELETE(); $rest->DELETE();
return $rest->getCurlResponse()['success']; return $rest->getSuccess();
} }
/** /**
@ -76,7 +71,7 @@ class BlackList extends Service {
'expire' => $expire, 'expire' => $expire,
]); ]);
return new models\Download\BlackListEntry( $rest->getCurlResponse()['result']); return $rest->getResult( models\Download\BlackListEntry::class);
} }
} }

View File

@ -20,7 +20,7 @@ class Configuration extends Service {
$rest = $this->getAuthService( self::API_DOWNLOAD_CONFIG); $rest = $this->getAuthService( self::API_DOWNLOAD_CONFIG);
$rest->GET(); $rest->GET();
return new models\Download\Config\DownloadConfig( $rest->getCurlResponse()['result']); return $rest->getResult( models\Download\Config\DownloadConfig::class);
} }
/** /**
@ -32,7 +32,7 @@ class Configuration extends Service {
$rest = $this->getAuthService( self::API_DOWNLOAD_CONFIG); $rest = $this->getAuthService( self::API_DOWNLOAD_CONFIG);
$rest->PUT( $downloadConfig->toArray()); $rest->PUT( $downloadConfig->toArray());
return new models\Download\Config\DownloadConfig( $rest->getCurlResponse()['result']); return $rest->getResult( models\Download\Config\DownloadConfig::class);
} }
/** /**
@ -49,7 +49,7 @@ class Configuration extends Service {
'throttling' => $throttlingMode, 'throttling' => $throttlingMode,
]); ]);
return $rest->getCurlResponse()['result']; return $rest->getSuccess();
} }
} }

View File

@ -26,12 +26,7 @@ class Download extends Service {
$rest = $this->getAuthService( self::API_DOWNLOAD); $rest = $this->getAuthService( self::API_DOWNLOAD);
$rest->GET(); $rest->GET();
$DownloadTask_xs = @$rest->getCurlResponse()['result'] ?: []; return $rest->getResultAsArray( models\Download\Task::class);
$DownloadTasks = [];
foreach( $DownloadTask_xs as $DownloadTask_x) {
$DownloadTasks[] = new models\Download\Task( $DownloadTask_x);
}
return $DownloadTasks;
} }
/** /**
@ -43,46 +38,46 @@ class Download extends Service {
$rest = $this->getAuthService( self::API_DOWNLOAD . $download_id); $rest = $this->getAuthService( self::API_DOWNLOAD . $download_id);
$rest->GET(); $rest->GET();
return new models\Download\Task( $rest->getCurlResponse()['result']); return $rest->getResult( models\Download\Task::class);
} }
/** /**
* Get the current system info * Get the current system info
* @param int $download_id * @param int $download_id
* @return * @return string
*/ */
public function getLogFromId( $download_id){ public function getLogFromId( $download_id){
$logService = sprintf( self::API_DOWNLOAD_LOG, $download_id); $logService = sprintf( self::API_DOWNLOAD_LOG, $download_id);
$rest = $this->getAuthService( $logService); $rest = $this->getAuthService( $logService);
$rest->GET(); $rest->GET();
return $rest->getCurlResponse()['result']; return $rest->getResult();
} }
/** /**
* Delete a download task (conserve data) * Delete a download task (conserve data)
* @param int $download_id * @param int $download_id
* @return * @return bool
*/ */
public function deleteFromId( $download_id){ public function deleteFromId( $download_id){
$rest = $this->getAuthService( self::API_DOWNLOAD . $download_id); $rest = $this->getAuthService( self::API_DOWNLOAD . $download_id);
$rest->DELETE(); $rest->DELETE();
return $rest->getCurlResponse()['success']; return $rest->getSuccess();
} }
/** /**
* Delete a download task (erase data) * Delete a download task (erase data)
* @param int $download_id * @param int $download_id
* @return * @return bool
*/ */
public function eraseFromId( $download_id){ public function eraseFromId( $download_id){
$eraseService = sprintf( self::API_DOWNLOAD_ERASE, $download_id); $eraseService = sprintf( self::API_DOWNLOAD_ERASE, $download_id);
$rest = $this->getAuthService( $eraseService); $rest = $this->getAuthService( $eraseService);
$rest->DELETE(); $rest->DELETE();
return $rest->getCurlResponse()['success']; return $rest->getSuccess();
} }
@ -96,10 +91,11 @@ class Download extends Service {
$rest = $this->getAuthService( $eraseService); $rest = $this->getAuthService( $eraseService);
$rest->PUT( $downloadTask->toArray()); $rest->PUT( $downloadTask->toArray());
return new models\Download\Task( $rest->getCurlResponse()['result']); return $rest->getResult( models\Download\Task::class);
} }
/** /**
* Add a download task with the specified URL
* @param string $download_url * @param string $download_url
* @param string $download_dir * @param string $download_dir
* @param bool|false $recursive * @param bool|false $recursive
@ -114,6 +110,7 @@ class Download extends Service {
} }
/** /**
* Add a download task with all the specified URLs
* @param array $download_urls A list of URL * @param array $download_urls A list of URL
* @param string $download_dir The download destination directory (optional: will use the configuration download_dir by default) * @param string $download_dir The download destination directory (optional: will use the configuration download_dir by default)
* @param bool $recursive If true the download will be recursive * @param bool $recursive If true the download will be recursive
@ -162,16 +159,16 @@ class Download extends Service {
$rest = $this->getAuthService( self::API_DOWNLOAD_ADD); $rest = $this->getAuthService( self::API_DOWNLOAD_ADD);
$rest->setContentType_XFormURLEncoded(); $rest->setContentType_XFormURLEncoded();
$rest->POST( $data); $rest->POST( $data);
$response = $rest->getCurlResponse();
return $response['result']['id']; return $rest->getResult()['id'];
} }
/** /**
* Add a download task with the specified file (torrent, nzb...)
* @param $download_file_rdi * @param $download_file_rdi
* @param string $download_dir_rdi * @param string $download_dir_rdi
* @param string $archive_password * @param string $archive_password
* @return bool * @return int
*/ */
public function addFromFile( $download_file_rdi, $download_dir_rdi = '', $archive_password = ''){ public function addFromFile( $download_file_rdi, $download_dir_rdi = '', $archive_password = ''){
$rest = $this->getAuthService( self::API_DOWNLOAD_ADD); $rest = $this->getAuthService( self::API_DOWNLOAD_ADD);
@ -182,22 +179,22 @@ class Download extends Service {
'archive_password' => $archive_password, 'archive_password' => $archive_password,
]); ]);
return $rest->getCurlResponse()['result']['id']; return $rest->getResult()['id'];
} }
/** /**
* Returns the Download task with the given id * Returns the Download task with the given id
* @return models\Download\Task * @return models\Download\Stats\DownloadStats
*/ */
public function getStats( ){ public function getStats(){
$rest = $this->getAuthService( self::API_DOWNLOAD_STATS); $rest = $this->getAuthService( self::API_DOWNLOAD_STATS);
$rest->GET(); $rest->GET();
return new models\Download\Stats\DownloadStats( $rest->getCurlResponse()['result']); return $rest->getResult( models\Download\Stats\DownloadStats::class);
} }
/** /**
* Returns the Download task with the given id * Returns the downloaded files with the given task id
* @param int $taskId * @param int $taskId
* @return models\Download\File[] * @return models\Download\File[]
*/ */
@ -206,20 +203,16 @@ class Download extends Service {
$rest = $this->getAuthService( $Service); $rest = $this->getAuthService( $Service);
$rest->GET(); $rest->GET();
$DownloadFile_xs = @$rest->getCurlResponse()['result'] ?: []; return $rest->getResultAsArray( models\Download\File::class);
$DownloadFiles = [];
foreach( $DownloadFile_xs as $DownloadFile_x) {
$DownloadFiles[] = new models\Download\File( $DownloadFile_x);
}
return $DownloadFiles;
} }
/** /**
* Update a download priority
* @param int $downloadTaskId * @param int $downloadTaskId
* @param string $FileId * @param string $FileId
* @param string $Priority * @param string $Priority
* @see alphayax\freebox\api\v3\symbols\Download\File\Priority * @see alphayax\freebox\api\v3\symbols\Download\File\Priority
* @return * @return bool
*/ */
public function updateFilePriority( $downloadTaskId, $FileId, $Priority){ public function updateFilePriority( $downloadTaskId, $FileId, $Priority){
$Service = sprintf( self::API_DOWNLOAD_FILES, $downloadTaskId); $Service = sprintf( self::API_DOWNLOAD_FILES, $downloadTaskId);
@ -228,7 +221,7 @@ class Download extends Service {
'priority' => $Priority, 'priority' => $Priority,
]); ]);
return $rest->getCurlResponse()['success']; return $rest->getSuccess();
} }
} }

View File

@ -27,12 +27,7 @@ class Feed extends Service {
$rest = $this->getAuthService( self::API_DOWNLOAD_FEEDS); $rest = $this->getAuthService( self::API_DOWNLOAD_FEEDS);
$rest->GET(); $rest->GET();
$DownloadFeed_xs = @$rest->getCurlResponse()['result'] ?: []; return $rest->getResultAsArray( models\Download\Feed\DownloadFeed::class);
$DownloadFeeds = [];
foreach( $DownloadFeed_xs as $DownloadFeed_x) {
$DownloadFeeds[] = new models\Download\Feed\DownloadFeed( $DownloadFeed_x);
}
return $DownloadFeeds;
} }
/** /**
@ -45,7 +40,7 @@ class Feed extends Service {
$rest = $this->getAuthService( $service); $rest = $this->getAuthService( $service);
$rest->GET(); $rest->GET();
return new models\Download\Feed\DownloadFeed( $rest->getCurlResponse()['result']); return $rest->getResult( models\Download\Feed\DownloadFeed::class);
} }
/** /**
@ -59,7 +54,7 @@ class Feed extends Service {
'url' => $downloadFeedUrl, 'url' => $downloadFeedUrl,
]); ]);
return new models\Download\Feed\DownloadFeed( $rest->getCurlResponse()['result']); return $rest->getResult( models\Download\Feed\DownloadFeed::class);
} }
/** /**
@ -72,20 +67,20 @@ class Feed extends Service {
$rest = $this->getAuthService( $service); $rest = $this->getAuthService( $service);
$rest->DELETE(); $rest->DELETE();
return (bool) $rest->getCurlResponse()['success']; return $rest->getSuccess();
} }
/** /**
* Update a Download Feed * Update a Download Feed
* @param \alphayax\freebox\api\v3\models\Download\Feed\DownloadFeed $downloadFeed * @param models\Download\Feed\DownloadFeed $downloadFeed
* @return \alphayax\freebox\api\v3\models\Download\Feed\DownloadFeed * @return models\Download\Feed\DownloadFeed
*/ */
public function updateFeed(models\Download\Feed\DownloadFeed $downloadFeed){ public function updateFeed( models\Download\Feed\DownloadFeed $downloadFeed){
$service = sprintf( self::API_DOWNLOAD_FEEDS_ITEM, $downloadFeed->getId()); $service = sprintf( self::API_DOWNLOAD_FEEDS_ITEM, $downloadFeed->getId());
$rest = $this->getAuthService( $service); $rest = $this->getAuthService( $service);
$rest->PUT( $downloadFeed->toArray()); $rest->PUT( $downloadFeed);
return new models\Download\Feed\DownloadFeed( $rest->getCurlResponse()['result']); return $rest->getResult( models\Download\Feed\DownloadFeed::class);
} }
/** /**
@ -99,7 +94,7 @@ class Feed extends Service {
$rest = $this->getAuthService( $service); $rest = $this->getAuthService( $service);
$rest->POST(); $rest->POST();
return (bool) $rest->getCurlResponse()['success']; return $rest->getSuccess();
} }
/** /**
@ -111,57 +106,50 @@ class Feed extends Service {
$rest = $this->getAuthService( self::API_DOWNLOAD_FEEDS_FETCH); $rest = $this->getAuthService( self::API_DOWNLOAD_FEEDS_FETCH);
$rest->POST(); $rest->POST();
return (bool) $rest->getCurlResponse()['success']; return $rest->getSuccess();
} }
/** /**
* Returns the collection of all DownloadFeedItems for a given DownloadFeed * Returns the collection of all DownloadFeedItems for a given DownloadFeed
* @param $downloadFeedId * @param $downloadFeedId
* @return \alphayax\freebox\api\v3\models\Download\Feed\DownloadFeedItem[] * @return models\Download\Feed\DownloadFeedItem[]
*/ */
public function getFeedItems( $downloadFeedId){ public function getFeedItems( $downloadFeedId){
$service = sprintf( self::API_DOWNLOAD_FEEDS_ITEMS, $downloadFeedId); $service = sprintf( self::API_DOWNLOAD_FEEDS_ITEMS, $downloadFeedId);
$rest = $this->getAuthService( $service); $rest = $this->getAuthService( $service);
$rest->GET(); $rest->GET();
$DownloadFeedItem_xs = @$rest->getCurlResponse()['result'] ?: []; return $rest->getResultAsArray( models\Download\Feed\DownloadFeedItem::class);
$DownloadFeedItems = [];
foreach( $DownloadFeedItem_xs as $DownloadFeedItem_x) {
$DownloadFeedItems[] = new models\Download\Feed\DownloadFeedItem( $DownloadFeedItem_x);
}
return $DownloadFeedItems;
} }
/** /**
* Returns the collection of all DownloadFeedItems for a given DownloadFeed * Returns the collection of all DownloadFeedItems for a given DownloadFeed
* @param $downloadFeedId * @param models\Download\Feed\DownloadFeedItem $DownloadFeedItem
* @param \alphayax\freebox\api\v3\models\Download\Feed\DownloadFeedItem $DownloadFeedItem
* @return bool * @return bool
*/ */
public function updateFeedItem( $downloadFeedId, models\Download\Feed\DownloadFeedItem $DownloadFeedItem){ public function updateFeedItem( models\Download\Feed\DownloadFeedItem $DownloadFeedItem){
$service = sprintf( self::API_DOWNLOAD_FEEDS_ITEMS_ITEM, $downloadFeedId, $DownloadFeedItem->getId()); $service = sprintf( self::API_DOWNLOAD_FEEDS_ITEMS_ITEM, $DownloadFeedItem->getFeedId(), $DownloadFeedItem->getId());
$rest = $this->getAuthService( $service); $rest = $this->getAuthService( $service);
$rest->PUT( $DownloadFeedItem->toArray()); $rest->PUT( $DownloadFeedItem);
return (bool) $rest->getCurlResponse()['success']; return $rest->getSuccess();
} }
/** /**
* Returns the collection of all DownloadFeedItems for a given DownloadFeed * Download the specified feed item
* @param $downloadFeedId * @param models\Download\Feed\DownloadFeedItem $DownloadFeedItem
* @param \alphayax\freebox\api\v3\models\Download\Feed\DownloadFeedItem $DownloadFeedItem
* @return bool * @return bool
*/ */
public function downloadFeedItem( $downloadFeedId, models\Download\Feed\DownloadFeedItem $DownloadFeedItem){ public function downloadFeedItem( models\Download\Feed\DownloadFeedItem $DownloadFeedItem){
$service = sprintf( self::API_DOWNLOAD_FEEDS_ITEMS_ITEM_DOWNLOAD, $downloadFeedId, $DownloadFeedItem->getId()); $service = sprintf( self::API_DOWNLOAD_FEEDS_ITEMS_ITEM_DOWNLOAD, $DownloadFeedItem->getFeedId(), $DownloadFeedItem->getId());
$rest = $this->getAuthService( $service); $rest = $this->getAuthService( $service);
$rest->POST( $DownloadFeedItem->toArray()); $rest->POST( $DownloadFeedItem);
return (bool) $rest->getCurlResponse()['success']; return $rest->getSuccess();
} }
/** /**
* Returns the collection of all DownloadFeedItems for a given DownloadFeed * Mark the specified feed id as "Read"
* @param int $downloadFeedId * @param int $downloadFeedId
* @return bool * @return bool
*/ */
@ -170,7 +158,7 @@ class Feed extends Service {
$rest = $this->getAuthService( $service); $rest = $this->getAuthService( $service);
$rest->POST(); $rest->POST();
return (bool) $rest->getCurlResponse()['success']; return $rest->getSuccess();
} }
} }

View File

@ -23,12 +23,7 @@ class Peer extends Service {
$rest = $this->getAuthService( $service); $rest = $this->getAuthService( $service);
$rest->GET(); $rest->GET();
$DownloadPeer_xs = @$rest->getCurlResponse()['result'] ?: []; return $rest->getResultAsArray( models\Download\Peer::class);
$DownloadPeers = [];
foreach( $DownloadPeer_xs as $DownloadPeer_x) {
$DownloadPeers[] = new models\Download\Peer( $DownloadPeer_x);
}
return $DownloadPeers;
} }
} }

View File

@ -24,12 +24,7 @@ class Tracker extends Service {
$rest = $this->getAuthService( $service); $rest = $this->getAuthService( $service);
$rest->GET(); $rest->GET();
$DownloadTracker_xs = @$rest->getCurlResponse()['result'] ?: []; return $rest->getResultAsArray( models\Download\Tracker::class);
$DownloadTrackers = [];
foreach( $DownloadTracker_xs as $DownloadTracker_x) {
$DownloadTrackers[] = new models\Download\Tracker( $DownloadTracker_x);
}
return $DownloadTrackers;
} }
/** /**
@ -46,14 +41,14 @@ class Tracker extends Service {
'announce' => $announceUrl, 'announce' => $announceUrl,
]); ]);
return (bool) $rest->getCurlResponse()['success']; return $rest->getSuccess();
} }
/** /**
* Remove a tracker * Remove a tracker
* Attempting to call this method on a download other than bittorent will fail * Attempting to call this method on a download other than bittorent will fail
* @param int $downloadTaskId * @param int $downloadTaskId
* @param string $announceUrl (eg: udp://tracker.openbittorrent.com:80) * @param string $announceUrl (eg: udp://tracker.openbittorrent.com:80)
* @return bool * @return bool
*/ */
public function remove( $downloadTaskId, $announceUrl) { public function remove( $downloadTaskId, $announceUrl) {
@ -61,7 +56,7 @@ class Tracker extends Service {
$rest = $this->getAuthService( $service); $rest = $this->getAuthService( $service);
$rest->DELETE(); $rest->DELETE();
return (bool) $rest->getCurlResponse()['success']; return $rest->getSuccess();
} }
/** /**
@ -75,9 +70,9 @@ class Tracker extends Service {
public function update( $downloadTaskId, $announceUrl, models\Download\Tracker $Tracker) { public function update( $downloadTaskId, $announceUrl, models\Download\Tracker $Tracker) {
$service = sprintf( self::API_DOWNLOAD_TRACKER_ITEM, $downloadTaskId, $announceUrl); $service = sprintf( self::API_DOWNLOAD_TRACKER_ITEM, $downloadTaskId, $announceUrl);
$rest = $this->getAuthService( $service); $rest = $this->getAuthService( $service);
$rest->PUT( $Tracker->toArray()); $rest->PUT( $Tracker);
return (bool) $rest->getCurlResponse()['success']; return $rest->getSuccess();
} }
} }