Skip to content

Commit b74b367

Browse files
authored
Merge pull request #15 from SinusBot/added-track-class
Added Track and Folder class
2 parents f0e15d6 + 013bbe3 commit b74b367

File tree

8 files changed

+911
-632
lines changed

8 files changed

+911
-632
lines changed

src/API.php

Lines changed: 205 additions & 242 deletions
Large diffs are not rendered by default.

src/File.php

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?php
2+
/**
3+
* Class File | src/File.php
4+
*
5+
* A single File with it's available actions
6+
*
7+
* @package SinusBot
8+
* @author Max Schmitt <max@schmitt.mx>
9+
*/
10+
11+
namespace SinusBot;
12+
13+
/**
14+
* Class File
15+
*
16+
* File represents a single File of the SinusBot
17+
*/
18+
class File extends RestClient
19+
{
20+
/**
21+
* UUID holds the File UUID
22+
* @var array
23+
*/
24+
public $uuid = null;
25+
/**
26+
* File stores the initial received file data
27+
* @var array
28+
*/
29+
private $file = null;
30+
/**
31+
* __construct
32+
*
33+
* @param API $api SinusBot API
34+
* @param array $file SiusBot File array
35+
*/
36+
public function __construct($api, $file)
37+
{
38+
parent::__construct($api);
39+
$this->uuid = $file['uuid'];
40+
$this->file = $file;
41+
}
42+
43+
/**
44+
* getTitle returns the title
45+
*
46+
* @return string filename
47+
* @api
48+
*/
49+
public function getTitle()
50+
{
51+
return array_key_exists('title', $this->file)?$this->file['title']:$this->file["filename"];
52+
}
53+
54+
/**
55+
* getUUID returns the uuid
56+
*
57+
* @return string file UUID
58+
* @api
59+
*/
60+
public function getUUID()
61+
{
62+
return $this->uuid;
63+
}
64+
65+
/**
66+
* getType returns the file type
67+
*
68+
* @return string type: url, folder
69+
* @api
70+
*/
71+
public function getType()
72+
{
73+
return array_key_exists('type', $this->file)?$this->file['type']:'';
74+
}
75+
76+
/**
77+
* getArtist returns the artist
78+
*
79+
* @return string file UUID
80+
* @api
81+
*/
82+
public function getArtist()
83+
{
84+
return array_key_exists('artist', $this->file)?$this->file['artist']:'';
85+
}
86+
87+
/**
88+
* getUUID returns the uuid
89+
*
90+
* @return string file UUID
91+
* @api
92+
*/
93+
public function getParent()
94+
{
95+
return $this->file["parent"];
96+
}
97+
98+
/**
99+
* delete
100+
*
101+
* @return array status
102+
* @api
103+
*/
104+
public function delete()
105+
{
106+
return $this->request('/bot/files/'.$this->uuid, 'DELETE');
107+
}
108+
109+
/**
110+
* getThumbnail
111+
*
112+
* @return string url
113+
*/
114+
public function getThumbnail()
115+
{
116+
return array_key_exists('thumbnail', $this->file)?$this->url.'/cache/'.$this->file["thumbnail"]:null;
117+
}
118+
119+
120+
/**
121+
* edit
122+
*
123+
* @param Array $options - keys: displayTitle, title, artist, album...
124+
* @return array status
125+
* @api
126+
*/
127+
public function edit($options)
128+
{
129+
return $this->request('/bot/files/'.$this->uuid, 'PATCH', $options);
130+
}
131+
132+
/**
133+
* move
134+
*
135+
* @param string $parent subfolder UUID, empty value means root folder
136+
* @return array status
137+
*/
138+
public function move($parent = "")
139+
{
140+
return $this->request('/bot/files/'.$this->uuid, 'PATCH', [
141+
"parent" => $parent,
142+
]);
143+
}
144+
}

src/Folder.php

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
<?php
2+
/**
3+
* Class Folder | src/Folder.php
4+
*
5+
* A single Folder with it's available actions
6+
*
7+
* @package SinusBot
8+
* @author Max Schmitt <max@schmitt.mx>
9+
*/
10+
11+
namespace SinusBot;
12+
13+
/**
14+
* Class Folder
15+
*
16+
* Folder represents a single Folder of the SinusBot
17+
*/
18+
class Folder extends RestClient
19+
{
20+
/**
21+
* UUID holds the Folder UUID
22+
* @var array
23+
*/
24+
public $uuid = null;
25+
/**
26+
* Folder stores the initial received folder data
27+
* @var array
28+
*/
29+
private $folder = null;
30+
/**
31+
* Children stores the folder childrens
32+
* @var array
33+
*/
34+
private $children = [];
35+
/**
36+
* __construct
37+
*
38+
* @param API $api SinusBot API
39+
* @param array $folder SiusBot Folder array
40+
*/
41+
public function __construct($api, $folder)
42+
{
43+
parent::__construct($api);
44+
$this->uuid = $folder['uuid'];
45+
$this->folder = $folder;
46+
}
47+
48+
/**
49+
* getTitle returns the title
50+
*
51+
* @return string foldername
52+
* @api
53+
*/
54+
public function getTitle()
55+
{
56+
return $this->folder['title'];
57+
}
58+
59+
/**
60+
* getType returns the file type
61+
*
62+
* @return string type: url, folder
63+
* @api
64+
*/
65+
public function getType()
66+
{
67+
return array_key_exists('type', $this->folder)?$this->folder['type']:'';
68+
}
69+
70+
/**
71+
* getUUID returns the uuid
72+
*
73+
* @return string folder UUID
74+
* @api
75+
*/
76+
public function getUUID()
77+
{
78+
return $this->uuid;
79+
}
80+
81+
/**
82+
* getUUID returns the uuid
83+
*
84+
* @return string folder UUID
85+
* @api
86+
*/
87+
public function getParent()
88+
{
89+
return $this->folder["parent"];
90+
}
91+
92+
/**
93+
* addChildrenIfOK checks recursive if the given file should be
94+
* added as a child element. Determined via the "parent" attribute
95+
*
96+
* @return File file
97+
* @api
98+
*/
99+
public function addChildrenIfOK($file)
100+
{
101+
if ($this->getUUID()=== $file->getParent()) {
102+
array_push($this->children, $file);
103+
return true;
104+
}
105+
foreach ($this->children as $children) {
106+
if ($children->getType() === "folder") {
107+
if ($children->addChildrenIfOK($file)) {
108+
return true;
109+
}
110+
}
111+
}
112+
return false;
113+
}
114+
115+
/**
116+
* getChildren returns the children of the folder
117+
*
118+
* @return (\File|\Folder)[]
119+
* @api
120+
*/
121+
public function getChildren()
122+
{
123+
return $this->children;
124+
}
125+
126+
/**
127+
* delete
128+
*
129+
* @return array status
130+
* @api
131+
*/
132+
public function delete()
133+
{
134+
return $this->request('/bot/files/'.$this->uuid, 'DELETE');
135+
}
136+
137+
/**
138+
* edit
139+
*
140+
* @param Array $options - keys: displayTitle, title, artist, album...
141+
* @return array status
142+
* @api
143+
*/
144+
public function edit($options)
145+
{
146+
return $this->request('/bot/files/'.$this->uuid, 'PATCH', $options);
147+
}
148+
149+
/**
150+
* move
151+
*
152+
* @param string $parent subfolder UUID, empty value means root folder
153+
* @return array status
154+
*/
155+
public function move($parent = "")
156+
{
157+
return $this->request('/bot/files/'.$this->uuid, 'PATCH', [
158+
"parent" => $parent,
159+
]);
160+
}
161+
}

0 commit comments

Comments
 (0)