- Notifications
You must be signed in to change notification settings - Fork 11
Added Track and Folder class #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits Select commit Hold shift + click to select a range
4aa9623 initial start for File integration
68829ef added Folder class
mxschmitt 4bd2b99 fixed consistency of comments / spaces
mxschmitt 3e57bed moved methods into the corresponding new classes
mxschmitt ffae24a cleaned up
mxschmitt d438d76 fixed issues from GitHub PR review
mxschmitt 013bbe3 renamed 'Invalid data...' to 'Invalid parent'
mxschmitt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| 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, | ||
| ]); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| 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, | ||
| ]); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.