Skip to content
447 changes: 205 additions & 242 deletions src/API.php

Large diffs are not rendered by default.

144 changes: 144 additions & 0 deletions src/File.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?php
/**
* Class File | src/File.php
*
* A single File with it's available actions
*
* @package SinusBot
* @author Max Schmitt <max@schmitt.mx>
*/

namespace SinusBot;

/**
* Class File
*
* File represents a single File of the SinusBot
*/
class File extends RestClient
{
/**
* UUID holds the File UUID
* @var array
*/
public $uuid = null;
/**
* File stores the initial received file data
* @var array
*/
private $file = null;
/**
* __construct
*
* @param API $api SinusBot API
* @param array $file SiusBot File array
*/
public function __construct($api, $file)
{
parent::__construct($api);
$this->uuid = $file['uuid'];
$this->file = $file;
}

/**
* getTitle returns the title
*
* @return string filename
* @api
*/
public function getTitle()
{
return array_key_exists('title', $this->file)?$this->file['title']:$this->file["filename"];
}

/**
* getUUID returns the uuid
*
* @return string file UUID
* @api
*/
public function getUUID()
{
return $this->uuid;
}

/**
* getType returns the file type
*
* @return string type: url, folder
* @api
*/
public function getType()
{
return array_key_exists('type', $this->file)?$this->file['type']:'';
}

/**
* getArtist returns the artist
*
* @return string file UUID
* @api
*/
public function getArtist()
{
return array_key_exists('artist', $this->file)?$this->file['artist']:'';
}

/**
* getUUID returns the uuid
*
* @return string file UUID
* @api
*/
public function getParent()
{
return $this->file["parent"];
}

/**
* delete
*
* @return array status
* @api
*/
public function delete()
{
return $this->request('/bot/files/'.$this->uuid, 'DELETE');
}

/**
* getThumbnail
*
* @return string url
*/
public function getThumbnail()
{
return array_key_exists('thumbnail', $this->file)?$this->url.'/cache/'.$this->file["thumbnail"]:null;
}


/**
* edit
*
* @param Array $options - keys: displayTitle, title, artist, album...
* @return array status
* @api
*/
public function edit($options)
{
return $this->request('/bot/files/'.$this->uuid, 'PATCH', $options);
}

/**
* move
*
* @param string $parent subfolder UUID, empty value means root folder
* @return array status
*/
public function move($parent = "")
{
return $this->request('/bot/files/'.$this->uuid, 'PATCH', [
"parent" => $parent,
]);
}
}
161 changes: 161 additions & 0 deletions src/Folder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<?php
/**
* Class Folder | src/Folder.php
*
* A single Folder with it's available actions
*
* @package SinusBot
* @author Max Schmitt <max@schmitt.mx>
*/

namespace SinusBot;

/**
* Class Folder
*
* Folder represents a single Folder of the SinusBot
*/
class Folder extends RestClient
{
/**
* UUID holds the Folder UUID
* @var array
*/
public $uuid = null;
/**
* Folder stores the initial received folder data
* @var array
*/
private $folder = null;
/**
* Children stores the folder childrens
* @var array
*/
private $children = [];
/**
* __construct
*
* @param API $api SinusBot API
* @param array $folder SiusBot Folder array
*/
public function __construct($api, $folder)
{
parent::__construct($api);
$this->uuid = $folder['uuid'];
$this->folder = $folder;
}

/**
* getTitle returns the title
*
* @return string foldername
* @api
*/
public function getTitle()
{
return $this->folder['title'];
}

/**
* getType returns the file type
*
* @return string type: url, folder
* @api
*/
public function getType()
{
return array_key_exists('type', $this->folder)?$this->folder['type']:'';
}

/**
* getUUID returns the uuid
*
* @return string folder UUID
* @api
*/
public function getUUID()
{
return $this->uuid;
}

/**
* getUUID returns the uuid
*
* @return string folder UUID
* @api
*/
public function getParent()
{
return $this->folder["parent"];
}

/**
* addChildrenIfOK checks recursive if the given file should be
* added as a child element. Determined via the "parent" attribute
*
* @return File file
* @api
*/
public function addChildrenIfOK($file)
{
if ($this->getUUID()=== $file->getParent()) {
array_push($this->children, $file);
return true;
}
foreach ($this->children as $children) {
if ($children->getType() === "folder") {
if ($children->addChildrenIfOK($file)) {
return true;
}
}
}
return false;
}

/**
* getChildren returns the children of the folder
*
* @return (\File|\Folder)[]
* @api
*/
public function getChildren()
{
return $this->children;
}

/**
* delete
*
* @return array status
* @api
*/
public function delete()
{
return $this->request('/bot/files/'.$this->uuid, 'DELETE');
}

/**
* edit
*
* @param Array $options - keys: displayTitle, title, artist, album...
* @return array status
* @api
*/
public function edit($options)
{
return $this->request('/bot/files/'.$this->uuid, 'PATCH', $options);
}

/**
* move
*
* @param string $parent subfolder UUID, empty value means root folder
* @return array status
*/
public function move($parent = "")
{
return $this->request('/bot/files/'.$this->uuid, 'PATCH', [
"parent" => $parent,
]);
}
}
Loading