Skip to content

Commit

Permalink
Simplified class constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Sep 11, 2018
1 parent 4fad5ac commit 8d790c7
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 29 deletions.
10 changes: 5 additions & 5 deletions src/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function getPlaylists()
$playlists = $this->request('/bot/playlists');
$out = [];
foreach ($playlists as $playlist) {
array_push($out, new Playlist($this->token, $this->url, $this->timeout, $playlist));
array_push($out, new Playlist($this, $playlist));
}
return $out;
}
Expand All @@ -102,7 +102,7 @@ public function createPlaylist($playlistName)
"name" => $playlistName,
]);
$resp['name'] = $playlistName;
return new Playlist($this->token, $this->url, $this->timeout, $resp);
return new Playlist($this, $resp);
}

/**
Expand Down Expand Up @@ -300,7 +300,7 @@ public function getUsers()
$users = $this->request('/bot/users');
$out = [];
foreach ($users as $user) {
array_push($out, new User($this->token, $this->url, $this->timeout, $user));
array_push($out, new User($this, $user));
}
return $out;
}
Expand Down Expand Up @@ -369,7 +369,7 @@ public function getInstances()
$instances = $this->request('/bot/instances');
$out = [];
foreach ($instances as $instance) {
array_push($out, new Instance($this->token, $this->url, $this->timeout, $instance));
array_push($out, new Instance($this, $instance));
}
return $out;
}
Expand Down Expand Up @@ -448,6 +448,6 @@ public function getInstanceByUUID($uuid)
{
$instance = $this->request("/bot/i/".$uuid."/settings");
$instance['uuid'] = $uuid;
return new Instance($this->token, $this->url, $this->timeout, $instance);
return new Instance($this, $instance);
}
}
12 changes: 4 additions & 8 deletions src/Instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,13 @@ class Instance extends RestClient
/**
* __construct
*
* @param string $token SinusBot auth token
* @param string $url SinusBot Bot URL
* @param int $timeout HTTP Timeout which is used to perform HTTP API requests
* @param array $instance SinusBot Instance array.
* @param API $api SinusBot API
* @param array $instance SinusBot Instance array
* @return void
*/
public function __construct($token, $url, $timeout, $instance)
public function __construct($api, $instance)
{
$this->token = $token;
$this->url = $url;
$this->timeout = $timeout;
parent::__construct($api);
$this->uuid = $instance['uuid'];
$this->instance = $instance;
}
Expand Down
10 changes: 3 additions & 7 deletions src/Playlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,13 @@ class Playlist extends RestClient
/**
* __construct
*
* @param string $token SinusBot auth token
* @param string $url SinusBot Bot URL
* @param int $timeout HTTP Timeout which is used to perform HTTP API requests
* @param API $api SinusBot API
* @param array $playlist SinusBot Playlist array.
* @return void
*/
public function __construct($token, $url, $timeout, $playlist)
public function __construct($api, $playlist)
{
$this->token = $token;
$this->url = $url;
$this->timeout = $timeout;
parent::__construct($api);
$this->uuid = $playlist['uuid'];
$this->playlist = $playlist;
}
Expand Down
12 changes: 12 additions & 0 deletions src/RestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ class RestClient
*/
protected $headers = [];
/**
* __construct
*
* @param API $api SinusBot API
*/
protected function __construct($api)
{
$this->token = $api->token;
$this->url = $api->url;
$this->timeout = $api->timeout;
$this->headers = $api->headers;
}
/**
* request executes a request to the SinusBot API
*
* @param string $path /api/v1/<path>
Expand Down
13 changes: 4 additions & 9 deletions src/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,12 @@ class User extends RestClient
/**
* __construct
*
* @param string $token SinusBot auth token
* @param string $url SinusBot Bot URL
* @param int $timeout HTTP Timeout which is used to perform HTTP API requests
* @param array $user SinusBot User array.
* @return void
* @param API $api SinusBot API
* @param array $user SiusBot User array
*/
public function __construct($token, $url, $timeout, $user)
public function __construct($api, $user)
{
$this->token = $token;
$this->url = $url;
$this->timeout = $timeout;
parent::__construct($api);
$this->uuid = $user['id'];
$this->user = $user;
}
Expand Down

0 comments on commit 8d790c7

Please sign in to comment.