Skip to content

Commit 1a42c34

Browse files
committed
added getter to initial data of playlist and instance
1 parent b7bca59 commit 1a42c34

File tree

3 files changed

+94
-13
lines changed

3 files changed

+94
-13
lines changed

src/API.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function getPlaylists()
8585
$playlists = $this->request('/bot/playlists');
8686
$out = [];
8787
foreach ($playlists as $playlist) {
88-
array_push($out, new Playlist($this->token, $this->url, $this->timeout, $playlist["uuid"]));
88+
array_push($out, new Playlist($this->token, $this->url, $this->timeout, $playlist));
8989
}
9090
return $out;
9191
}
@@ -101,7 +101,7 @@ public function createPlaylist($playlistName)
101101
$resp = $this->request('/bot/playlists', 'POST', [
102102
"name" => $playlistName,
103103
]);
104-
return new Playlist($this->token, $this->url, $this->timeout, $resp["uuid"]);
104+
return new Playlist($this->token, $this->url, $this->timeout, $resp);
105105
}
106106

107107
/**
@@ -398,7 +398,7 @@ public function getInstances()
398398
$instances = $this->request('/bot/instances');
399399
$out = [];
400400
foreach ($instances as $instance) {
401-
array_push($out, new Instance($this->token, $this->url, $this->timeout, $instance["uuid"]));
401+
array_push($out, new Instance($this->token, $this->url, $this->timeout, $instance));
402402
}
403403
return $out;
404404
}

src/Instance.class.php

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ class Instance extends RestClient
2323
*/
2424
public $uuid = null;
2525
/**
26+
* Instance stores the initial received instance data
27+
* @var array
28+
*/
29+
private $instance = null;
30+
/**
2631
* __construct
2732
*
2833
* @param string $token SinusBot auth token
@@ -31,35 +36,78 @@ class Instance extends RestClient
3136
* @param array $instance SinusBot Instance array.
3237
* @return void
3338
*/
34-
public function __construct($token, $url, $timeout, $uuid)
39+
public function __construct($token, $url, $timeout, $instance)
3540
{
3641
$this->token = $token;
3742
$this->url = $url;
3843
$this->timeout = $timeout;
39-
$this->uuid = $uuid;
44+
$this->uuid = $instance['uuid'];
45+
$this->instance = $instance;
4046
}
4147
/**
4248
* isPlaying returns true when the instance is playing something
4349
*
44-
* @param string $instanceUUID UUID of the SinusBot instance
4550
* @return boolean
4651
*/
4752
public function isPlaying()
4853
{
49-
return $this->getStatus()['playing'];
54+
return $this->instance['playing'];
5055
}
5156

5257
/**
5358
* isRunning returns true when the instance is running
5459
*
55-
* @param string $instanceUUID UUID of the SinusBot instance
5660
* @return boolean
5761
*/
5862
public function isRunning()
5963
{
60-
return $this->getStatus()['running'];
64+
return $this->instance['running'];
6165
}
62-
66+
/**
67+
* getBackend returns the SinusBot backend (Discord, TS³)
68+
*
69+
* @return string instance backend
70+
*/
71+
public function getBackend()
72+
{
73+
return $this->instance['backend'];
74+
}
75+
/**
76+
* getNick returns the Bot's nickname
77+
*
78+
* @return string nick
79+
*/
80+
public function getNick()
81+
{
82+
return $this->instance['nick'];
83+
}
84+
/**
85+
* getName returns the Bot's name
86+
*
87+
* @return string name
88+
*/
89+
public function getName()
90+
{
91+
return $this->instance['name'];
92+
}
93+
/**
94+
* getServerHost returns the Bot's server host
95+
*
96+
* @return string host
97+
*/
98+
public function getServerHost()
99+
{
100+
return $this->instance['serverHost'];
101+
}
102+
/**
103+
* getServerPort returns the Bot's server port
104+
*
105+
* @return string port
106+
*/
107+
public function getServerPort()
108+
{
109+
return $this->instance['serverPort'];
110+
}
63111
/**
64112
* delete deletes the instance
65113
*

src/Playlist.class.php

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ class Playlist extends RestClient
2323
*/
2424
public $uuid = null;
2525
/**
26+
* Playlist stores the initial received playlist data
27+
* @var array
28+
*/
29+
private $playlist = null;
30+
/**
2631
* __construct
2732
*
2833
* @param string $token SinusBot auth token
@@ -31,12 +36,13 @@ class Playlist extends RestClient
3136
* @param array $playlist SinusBot Playlist array.
3237
* @return void
3338
*/
34-
public function __construct($token, $url, $timeout, $uuid)
39+
public function __construct($token, $url, $timeout, $playlist)
3540
{
3641
$this->token = $token;
3742
$this->url = $url;
3843
$this->timeout = $timeout;
39-
$this->uuid = $uuid;
44+
$this->uuid = $playlist['uuid'];
45+
$this->playlist = $playlist;
4046
}
4147

4248
/**
@@ -60,8 +66,35 @@ public function getPlaylistTracks()
6066
{
6167
return $this->request('/bot/playlists/'.$this->uuid);
6268
}
69+
/**
70+
* getName returns the name of the playlist
71+
*
72+
* @return string name
73+
*/
74+
public function getName()
75+
{
76+
return array_key_exists('name', $this->playlist)?$this->playlist['name']:'';
77+
}
78+
/**
79+
* getEntries returns the track entries
80+
*
81+
* @return array track entries
82+
*/
83+
public function getEntries()
84+
{
85+
return array_key_exists('entries', $this->playlist)?$this->playlist['entries']:'';
86+
}
87+
/**
88+
* getSource returns the source of the playlist
89+
*
90+
* @return string source
91+
*/
92+
public function getSource()
93+
{
94+
return array_key_exists('source', $this->playlist)?$this->playlist['source']:'';
95+
}
6396

64-
/**
97+
/**
6598
* addPlaylistTrack adds a track to the playlist
6699
*
67100
* @param string $trackUUID uuid of the track

0 commit comments

Comments
 (0)