diff --git a/LICENSE.md b/LICENSE.md index f1b03a3..eb1d7d7 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,7 +1,7 @@ # MIT License Copyright (c) 2018 FruitBytes\ -Copyright (c) 2019 HCGCloud +Copyright (c) 2020 HCGCloud > Permission is hereby granted, free of charge, to any person obtaining a copy > of this software and associated documentation files (the "Software"), to deal diff --git a/composer.json b/composer.json index c9a450e..44ae289 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ ], "require": { "php": ">=5.6.4", - "guzzlehttp/guzzle": "~6.0" + "guzzlehttp/guzzle": "^6.0|^7.0" }, "require-dev": { "mockery/mockery": "0.9.*", diff --git a/src/Actions/ManagesAllocations.php b/src/Actions/ManagesAllocations.php deleted file mode 100644 index ae53af8..0000000 --- a/src/Actions/ManagesAllocations.php +++ /dev/null @@ -1,48 +0,0 @@ -get("api/application/nodes/$nodeId".'/allocations?page='.$page); - } - - /** - * Create new allocation(s). - * - * @param int $nodeId - * @param array $data - * - * @return void - */ - public function createAllocation(int $nodeId, array $data) - { - return $this->post("api/application/nodes/$nodeId/allocations", $data); - } - - /** - * Delete the given allocation. - * - * @param int $nodeId - * @param int $allocationId - * @param array $data - * - * @return void - */ - public function deleteAllocation(int $nodeId, int $allocationId) - { - return $this->delete("api/application/nodes/$nodeId/allocations/$allocationId"); - } -} diff --git a/src/Actions/ManagesEggs.php b/src/Actions/ManagesEggs.php deleted file mode 100644 index 8eca706..0000000 --- a/src/Actions/ManagesEggs.php +++ /dev/null @@ -1,34 +0,0 @@ -get("api/application/nests/$nestId/eggs"); - } - - /** - * Get a egg instance. - * - * @param int $nestId - * @param int $eggId - * @param array $includes - * - * @return Egg - */ - public function egg(int $nestId, int $eggId, array $includes = []) - { - return $this->get("api/application/nests/$nestId/eggs/$eggId".$this->include($includes)); - } -} diff --git a/src/Actions/ManagesLocations.php b/src/Actions/ManagesLocations.php deleted file mode 100644 index 30b9230..0000000 --- a/src/Actions/ManagesLocations.php +++ /dev/null @@ -1,70 +0,0 @@ -get('api/application/locations?page='.$page); - } - - /** - * Get a location instance. - * - * @param int $locationId - * @param array $includes - * - * @return Location - */ - public function location(int $locationId, array $includes = []) - { - return $this->get("api/application/locations/$locationId".$this->include($includes)); - } - - /** - * Create a new location. - * - * @param array $data - * - * @return Location - */ - public function createLocation(array $data) - { - return $this->post('api/application/locations', $data); - } - - /** - * Update a specified location. - * - * @param int $locationId - * @param array $data - * - * @return Location - */ - public function updateLocation(int $locationId, array $data) - { - return $this->patch("api/application/locations/$locationId", $data); - } - - /** - * Delete the given location. - * - * @param int $locationId - * - * @return void - */ - public function deleteLocation(int $locationId) - { - return $this->delete("api/application/locations/$locationId"); - } -} diff --git a/src/Actions/ManagesNests.php b/src/Actions/ManagesNests.php deleted file mode 100644 index ce82c2f..0000000 --- a/src/Actions/ManagesNests.php +++ /dev/null @@ -1,33 +0,0 @@ -get('api/application/nests?page='.$page); - } - - /** - * Get a nest instance. - * - * @param int $nestId - * @param array $includes - * - * @return Nest - */ - public function nest(int $nestId, array $includes = []) - { - return $this->get("api/application/nests/$nestId".$this->include($includes)); - } -} diff --git a/src/Actions/ManagesNodes.php b/src/Actions/ManagesNodes.php deleted file mode 100644 index 7c2600e..0000000 --- a/src/Actions/ManagesNodes.php +++ /dev/null @@ -1,70 +0,0 @@ -get('api/application/nodes?page='.$page); - } - - /** - * Get a node instance. - * - * @param int $nodeId - * @param array $includes - * - * @return Node - */ - public function node(int $nodeId, array $includes = []) - { - return $this->get("api/application/nodes/$nodeId".$this->include($includes)); - } - - /** - * Create a new node. - * - * @param array $data - * - * @return Node - */ - public function createNode(array $data) - { - return $this->post('api/application/nodes', $data); - } - - /** - * Update a specified node. - * - * @param int $nodeId - * @param array $data - * - * @return Node - */ - public function updateNode(int $nodeId, array $data) - { - return $this->patch("api/application/nodes/$nodeId", $data); - } - - /** - * Delete the given node. - * - * @param int $nodeId - * - * @return void - */ - public function deleteNode(int $nodeId) - { - return $this->delete("api/application/nodes/$nodeId"); - } -} diff --git a/src/Actions/ManagesServers.php b/src/Actions/ManagesServers.php deleted file mode 100644 index bf27caa..0000000 --- a/src/Actions/ManagesServers.php +++ /dev/null @@ -1,234 +0,0 @@ -get('api/application/servers?page='.$page); - } - - /** - * Get a server instance. - * - * @param int $serverId - * @param array $includes - * - * @return Server - */ - public function server(int $serverId, array $includes = ['allocations']) - { - return $this->get("api/application/servers/$serverId".$this->include($includes)); - } - - /** - * Get a server instance by external id. - * - * @param string $externalId - * @param array $includes - * - * @return Server - */ - public function serverEx(string $externalId, array $includes = ['allocations']) - { - return $this->get("api/application/servers/external/$externalId".$this->include($includes)); - } - - /** - * Create a new server. - * - * @param array $data - * - * @return Server - */ - public function createServer(array $data) - { - return $this->post('api/application/servers', $data); - } - - /** - * Delete the given server. - * - * @param int $serverId - * - * @return void - */ - public function deleteServer(int $serverId) - { - return $this->delete("api/application/servers/$serverId"); - } - - /** - * Force delete the given server. - * - * @param int $serverId - * - * @return void - */ - public function forceDeleteServer(int $serverId) - { - return $this->delete("api/application/servers/$serverId/force"); - } - - /** - * Update details of the given server. - * - * @param int $serverId - * @param array $data - * - * @return Server - */ - public function updateServerDetails(int $serverId, array $data) - { - return $this->patch("api/application/servers/$serverId/details", $data); - } - - /** - * Update build configuration of the given server. - * - * @param int $serverId - * @param array $data - * - * @return Server - */ - public function updateServerBuild(int $serverId, array $data) - { - return $this->patch("api/application/servers/$serverId/build", $data); - } - - /** - * Update startup parameters of the given server. - * - * @param int $serverId - * @param array $data - * - * @return Server - */ - public function updateServerStartup(int $serverId, array $data) - { - return $this->patch("api/application/servers/$serverId/startup", $data); - } - - /** - * Suspend the given server. - * - * @param int $serverId - * - * @return void - */ - public function suspendServer(int $serverId) - { - return $this->post("api/application/servers/$serverId/suspend"); - } - - /** - * Unsuspend the given server. - * - * @param int $serverId - * - * @return void - */ - public function unsuspendServer(int $serverId) - { - return $this->post("api/application/servers/$serverId/unsuspend"); - } - - /** - * Reinstall the given server. - * - * @param int $serverId - * - * @return void - */ - public function reinstallServer(int $serverId) - { - return $this->post("api/application/servers/$serverId/reinstall"); - } - - /** - * Rebuild the given server. - * - * @param int $serverId - * - * @return void - */ - public function rebuildServer(int $serverId) - { - return $this->post("api/application/servers/$serverId/rebuild"); - } - - /** - * Get a collection of databases of a server. - * - * @param int $serverId - * - * @return ServerDatabase[] - */ - public function serverDatabases(int $serverId) - { - return $this->get("api/application/servers/$serverId/databases"); - } - - /** - * Get a database instance of a server. - * - * @param int $serverId - * @param int $databaseId - * - * @return ServerDatabase - */ - public function serverDatabase(int $serverId, int $databaseId) - { - return $this->get("api/application/servers/$serverId/databases/$databaseId"); - } - - /** - * Create a database for a server. - * - * @param int $serverId - * @param array $data - * - * @return ServerDatabase - */ - public function createServerDatabase(int $serverId, array $data) - { - return $this->post("api/application/servers/$serverId/databases/", $data); - } - - /** - * Reset the password of a server's database. - * - * @param int $serverId - * @param int $databaseId - * - * @return void - */ - public function resetServerDatabasePassword(int $serverId, int $databaseId) - { - return $this->post("api/application/servers/$serverId/databases/$databaseId/reset-password"); - } - - /** - * Delete the given database of a server. - * - * @param int $serverId - * @param int $databaseId - * - * @return void - */ - public function deleteServerDatabase(int $serverId, int $databaseId) - { - return $this->delete("api/application/servers/$serverId/databases/$databaseId"); - } -} diff --git a/src/Actions/ManagesUsers.php b/src/Actions/ManagesUsers.php deleted file mode 100644 index 6456269..0000000 --- a/src/Actions/ManagesUsers.php +++ /dev/null @@ -1,83 +0,0 @@ -get('api/application/users?page='.$page); - } - - /** - * Get a user instance. - * - * @param int $userId - * @param array $includes - * - * @return User - */ - public function user(int $userId, array $includes = []) - { - return $this->get("api/application/users/$userId".$this->include($includes)); - } - - /** - * Get a user instance by external id. - * - * @param int $userExternalId - * @param array $includes - * - * @return User - */ - public function userEx(int $userExternalId, array $includes = []) - { - return $this->get("api/application/users/external/$userExternalId".$this->include($includes)); - } - - /** - * Create a new user. - * - * @param array $data - * - * @return User - */ - public function createUser(array $data) - { - return $this->post('api/application/users', $data); - } - - /** - * Update a specified user. - * - * @param int $userId - * @param array $data - * - * @return User - */ - public function updateUser(int $userId, array $data) - { - return $this->patch("api/application/users/$userId", $data); - } - - /** - * Delete the given user. - * - * @param int $userId - * - * @return void - */ - public function deleteUser(int $userId) - { - return $this->delete("api/application/users/$userId"); - } -} diff --git a/src/Actions/UsesServers.php b/src/Actions/UsesServers.php deleted file mode 100644 index 2aa1c27..0000000 --- a/src/Actions/UsesServers.php +++ /dev/null @@ -1,72 +0,0 @@ -get('api/client?page='.$page); - } - - /** - * Gets the details of a given server. - * - * @param string $serverIdentifier - * @param array $includes - * - * @return Server[] - */ - public function getServer(string $serverIdentifier, array $includes = []) - { - return $this->get("api/client/servers/$serverIdentifier".$this->include($includes)); - } - - /** - * Toggle the power on a given server. - * - * @param string $serverIdentifier - * @param string $action - * - * @return void - */ - public function powerServer(string $serverIdentifier, string $action) - { - return $this->post("api/client/servers/$serverIdentifier/power", ['signal'=>"$action"]); - } - - /** - * Send a command to a given server. - * - * @param string $serverIdentifier - * @param string $command - * - * @return void - */ - public function commandServer(string $serverIdentifier, string $command) - { - return $this->post("api/client/servers/$serverIdentifier/command", ['command'=>"$command"]); - } - - /** - * Get the utilization of a given server. - * - * @param string $serverIdentifier - * - * @return Stats[] - */ - public function utilizationServer(string $serverIdentifier) - { - return $this->get("api/client/servers/$serverIdentifier/utilization"); - } -} diff --git a/src/Exceptions/AccessDeniedHttpException.php b/src/Exceptions/AccessDeniedHttpException.php new file mode 100644 index 0000000..a8b1029 --- /dev/null +++ b/src/Exceptions/AccessDeniedHttpException.php @@ -0,0 +1,18 @@ +pterodactyl = $pterodactyl; + + $this->baseUri = $this->pterodactyl->baseUri; + + $this->apiKey = $this->pterodactyl->apiKey; + + $this->apiType = $this->pterodactyl->apiType; + + $this->guzzle = $guzzle ?: new Client([ + 'base_uri' => $this->baseUri, + 'http_errors' => false, + 'headers' => [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ], + ]); + + return $this; + } + + /** + * Make a GET request and return the response. + * + * @param string $uri + * + * @return mixed + */ + public function get($uri, array $query = []) + { + return $this->request('GET', $uri, [], $query); + } + + /** + * Make a POST request and return the response. + * + * @param string $uri + * @param array $query + * @param array $payload + * + * @return mixed + */ + public function post($uri, array $query = [], array $payload = []) + { + return $this->request('POST', $uri, $query, $payload); + } + + /** + * Make a PUT request and return the response. + * + * @param string $uri + * @param array $query + * @param array $payload + * + * @return mixed + */ + public function put($uri, array $query = [], array $payload = []) + { + return $this->request('PUT', $uri, $query, $payload); + } + + /** + * Make a PATCH request and return the response. + * + * @param string $uri + * @param array $query + * @param array $payload + * + * @return mixed + */ + public function patch($uri, array $query = [], array $payload = []) + { + return $this->request('PATCH', $uri, $query, $payload); + } + + /** + * Make a DELETE request and return the response. + * + * @param string $uri + * @param array $query + * @param array $payload + * + * @return mixed + */ + public function delete($uri, array $query = [], array $payload = []) + { + return $this->request('DELETE', $uri, $query, $payload); + } + + /** + * Make request and return the response. + * + * @param string $method + * @param string $uri + * @param array $query + * @param array $payload + * + * @return mixed + */ + public function request($method, $uri, array $query = [], array $payload = []) + { + $uri = $this->baseUri.'/api/'.$this->apiType.'/'.$uri; + + $body = json_encode($payload); + + $token = $this->apiKey; + + $options['query'] = $query; + $options['body'] = $body; + $options['debug'] = false; + $options['headers']['Authorization'] = 'Bearer '.$token; + + $response = $this->guzzle->request($method, $uri, $options); + + if ($response->getStatusCode() != 200 && $response->getStatusCode() != 204 && $response->getStatusCode() != 201) { + return $this->handleRequestError($response); + } + + $responseBody = (string) $response->getBody(); + + return $this->transform(json_decode($responseBody, true)) ?: $responseBody; + } + + /** + * Transform response data to resources. + * + * @param array $response + * + * @return mixed + */ + protected function transform($response) + { + if (empty($response['object'])) { + return $response; + } + + switch ($response['object']) { + case 'list': + $response['data'] = array_map(function ($object) { + return $this->transform($object); + }, $response['data']); + + // Rename to use the collection resource. + $response['object'] = 'collection'; + break; + } + + if (isset($response['attributes']['relationships'])) { + $response['attributes']['relationships'] = array_map(function ($object) { + return $this->transform($object); + }, $response['attributes']['relationships']); + } + + $object = ucwords($this->camelCase($response['object'])); + + $class = class_exists('\\HCGCloud\\Pterodactyl\\Resources\\'.$object) ? + '\\HCGCloud\\Pterodactyl\\Resources\\'.$object : + '\\HCGCloud\\Pterodactyl\\Resources\\'.$object; + + $resource = class_exists($class) ? new $class($response, $this->pterodactyl) : $response; + + return $resource; + } + + /** + * Convert the key name to camel case. + * + * @param $key + */ + private function camelCase($key) + { + $parts = explode('_', $key); + + foreach ($parts as $i => $part) { + if ($i !== 0) { + $parts[$i] = ucfirst($part); + } + } + + return str_replace(' ', '', implode(' ', $parts)); + } + + /** + * @param \Psr\Http\Message\ResponseInterface $response + * + * @return void + */ + private function handleRequestError(ResponseInterface $response) + { + switch ($response->getStatusCode()) { + case 400: + throw new FailedActionException((string) $response->getBody()); + case 403: + throw new AccessDeniedHttpException(); + case 404: + throw new NotFoundException(); + case 422: + throw new ValidationException(json_decode((string) $response->getBody(), true)); + default: + throw new \Exception((string) $response->getBody()); + } + } + + /** + * Retry the callback or fail after x seconds. + * + * @param int $timeout + * @param callable $callback + * + * @return mixed + */ + public function retry($timeout, $callback) + { + $start = time(); + + beginning: + + $output = $callback(); + + if ($output) { + return $output; + } + + if (time() - $start < $timeout) { + sleep(5); + + goto beginning; + } + + throw new TimeoutException($output); + } + + /** + * Set a new timeout. + * + * @param int $timeout + * + * @return $this + */ + public function setTimeout($timeout) + { + $this->timeout = $timeout; + + return $this; + } + + /** + * Get the timeout. + * + * @return int + */ + public function getTimeout() + { + return $this->timeout; + } +} diff --git a/src/MakesHttpRequests.php b/src/MakesHttpRequests.php deleted file mode 100644 index 54f3f6f..0000000 --- a/src/MakesHttpRequests.php +++ /dev/null @@ -1,159 +0,0 @@ -request('GET', $uri); - } - - /** - * Make a POST request to Pterodactyl servers and return the response. - * - * @param string $uri - * @param array $payload - * - * @return mixed - */ - private function post($uri, array $payload = []) - { - return $this->request('POST', $uri, $payload); - } - - /** - * Make a PUT request to Pterodactyl servers and return the response. - * - * @param string $uri - * @param array $payload - * - * @return mixed - */ - private function put($uri, array $payload = []) - { - return $this->request('PUT', $uri, $payload); - } - - /** - * Make a PATCH request to Pterodactyl servers and return the response. - * - * @param string $uri - * @param array $payload - * - * @return mixed - */ - private function patch($uri, array $payload = []) - { - return $this->request('PATCH', $uri, $payload); - } - - /** - * Make a DELETE request to Pterodactyl servers and return the response. - * - * @param string $uri - * @param array $payload - * - * @return mixed - */ - private function delete($uri, array $payload = []) - { - return $this->request('DELETE', $uri, $payload); - } - - /** - * Make request to Pterodactyl servers and return the response. - * - * @param string $verb - * @param string $uri - * @param array $payload - * - * @return mixed - */ - private function request($verb, $uri, array $payload = []) - { - $url = $this->baseUri.$uri; - - $body = json_encode($payload); - - $token = $this->apiKey; - - $options['body'] = $body; - $options['debug'] = false; - $options['headers']['Authorization'] = 'Bearer '.$token; - - $response = $this->guzzle->request($verb, $uri, $options); - - if ($response->getStatusCode() != 200 && $response->getStatusCode() != 204 && $response->getStatusCode() != 201) { - return $this->handleRequestError($response); - } - - $responseBody = (string) $response->getBody(); - - return $this->transform(json_decode($responseBody, true)) ?: $responseBody; - } - - /** - * @param \Psr\Http\Message\ResponseInterface $response - * - * @return void - */ - private function handleRequestError(ResponseInterface $response) - { - if ($response->getStatusCode() == 422) { - throw new ValidationException(json_decode((string) $response->getBody(), true)); - } - - if ($response->getStatusCode() == 404) { - throw new NotFoundException(); - } - - if ($response->getStatusCode() == 400) { - throw new FailedActionException((string) $response->getBody()); - } - - throw new \Exception((string) $response->getBody()); - } - - /** - * Retry the callback or fail after x seconds. - * - * @param int $timeout - * @param callable $callback - * - * @return mixed - */ - public function retry($timeout, $callback) - { - $start = time(); - - beginning: - - $output = $callback(); - - if ($output) { - return $output; - } - - if (time() - $start < $timeout) { - sleep(5); - - goto beginning; - } - - throw new TimeoutException($output); - } -} diff --git a/src/Managers/AccountManager.php b/src/Managers/AccountManager.php new file mode 100644 index 0000000..d5e4a4c --- /dev/null +++ b/src/Managers/AccountManager.php @@ -0,0 +1,29 @@ +http->get('account'); + } + + /** + * Get permissions of the account. + * + * @return SystemPermissions + */ + public function permissions() + { + return $this->http->get('permissions'); + } +} diff --git a/src/Managers/LocationManager.php b/src/Managers/LocationManager.php new file mode 100644 index 0000000..25862ae --- /dev/null +++ b/src/Managers/LocationManager.php @@ -0,0 +1,74 @@ +http->get('locations', array_merge([ + 'page' => $page, + ], $query)); + } + + /** + * Get a location instance. + * + * @param int $locationId + * @param array $query + * + * @return Location + */ + public function get(int $locationId, array $query = []) + { + return $this->http->get("locations/$locationId", $query); + } + + /** + * Create a new location. + * + * @param array $data + * + * @return Location + */ + public function create(array $data) + { + return $this->http->post('locations', [], $data); + } + + /** + * Update a specified location. + * + * @param int $locationId + * @param array $data + * + * @return Location + */ + public function update(int $locationId, array $data) + { + return $this->http->patch("locations/$locationId", [], $data); + } + + /** + * Delete the given location. + * + * @param int $locationId + * + * @return void + */ + public function delete(int $locationId) + { + return $this->http->delete("locations/$locationId"); + } +} diff --git a/src/Managers/Manager.php b/src/Managers/Manager.php new file mode 100644 index 0000000..04a38c9 --- /dev/null +++ b/src/Managers/Manager.php @@ -0,0 +1,39 @@ +pterodactyl = $pterodactyl; + + $this->http = $this->pterodactyl->http; + + $this->apiType = $this->pterodactyl->apiType; + } +} diff --git a/src/Managers/Nest/NestEggManager.php b/src/Managers/Nest/NestEggManager.php new file mode 100644 index 0000000..8ad89ea --- /dev/null +++ b/src/Managers/Nest/NestEggManager.php @@ -0,0 +1,40 @@ +http->get("nests/$nestId/eggs", array_merge([ + 'page' => $page, + ], $query)); + } + + /** + * Get a egg instance by id. + * + * @param int $nestId + * @param int $eggId + * @param array $query + * + * @return Egg + */ + public function get(int $nestId, int $eggId, array $query = []) + { + return $this->http->get("nests/$nestId/eggs/$eggId", $query); + } +} diff --git a/src/Managers/NestManager.php b/src/Managers/NestManager.php new file mode 100644 index 0000000..2b676fd --- /dev/null +++ b/src/Managers/NestManager.php @@ -0,0 +1,37 @@ +http->get('nests', array_merge([ + 'page' => $page, + ], $query)); + } + + /** + * Get a nest instance by id. + * + * @param int $nestId + * @param array $query + * + * @return Nest + */ + public function get(int $nestId, array $query = []) + { + return $this->http->get("nests/$nestId", $query); + } +} diff --git a/src/Managers/Node/NodeAllocationManager.php b/src/Managers/Node/NodeAllocationManager.php new file mode 100644 index 0000000..7158762 --- /dev/null +++ b/src/Managers/Node/NodeAllocationManager.php @@ -0,0 +1,52 @@ +http->get("nodes/$nodeId/allocations", array_merge([ + 'page' => $page, + ], $query)); + } + + /** + * Create a new allocation for a node. + * + * @param int $nodeId + * @param array $data + * + * @return Allocation + */ + public function create(int $nodeId, array $data) + { + return $this->http->post("nodes/$nodeId/allocations", [], $data); + } + + /** + * Delete the given allocation of a node. + * + * @param int $nodeId + * @param int $allocationId + * + * @return void + */ + public function delete(int $nodeId, int $allocationId) + { + return $this->http->delete("nodes/$nodeId/allocations/$allocationId"); + } +} diff --git a/src/Managers/NodeManager.php b/src/Managers/NodeManager.php new file mode 100644 index 0000000..2f7eb0b --- /dev/null +++ b/src/Managers/NodeManager.php @@ -0,0 +1,87 @@ +http->get('nodes', array_merge([ + 'page' => $page, + ], $query)); + } + + /** + * Get a node instance by id. + * + * @param int $nodeId + * @param array $query + * + * @return Node + */ + public function get(int $nodeId, array $query = []) + { + return $this->http->get("nodes/$nodeId", $query); + } + + /** + * Get node configuration by id. + * + * @param int $nodeId + * @param array $query + * + * @return array + */ + public function getConfiguration(int $nodeId) + { + return $this->http->get("nodes/$nodeId/configuration"); + } + + /** + * Create a new node. + * + * @param array $data + * + * @return Node + */ + public function create(array $data) + { + return $this->http->post('nodes', [], $data); + } + + /** + * Update a specified node. + * + * @param int $nodeId + * @param array $data + * + * @return Node + */ + public function update(int $nodeId, array $data) + { + return $this->http->patch("nodes/$nodeId", [], $data); + } + + /** + * Delete the given node. + * + * @param int $nodeId + * + * @return void + */ + public function delete(int $nodeId) + { + return $this->http->delete("nodes/$nodeId"); + } +} diff --git a/src/Managers/Server/ServerDatabaseManager.php b/src/Managers/Server/ServerDatabaseManager.php new file mode 100644 index 0000000..9ffc03d --- /dev/null +++ b/src/Managers/Server/ServerDatabaseManager.php @@ -0,0 +1,79 @@ +http->get("servers/$serverId/databases", array_merge([ + 'page' => $page, + ], $query)); + } + + /** + * Get a server database instance. + * + * @param mixed $serverId + * @param int $databaseId + * @param array $query + * + * @return ServerDatabase + */ + public function get($serverId, int $databaseId, array $query = []) + { + return $this->http->get("servers/$serverId/databases/$databaseId", $query); + } + + /** + * Create a new database for a server. + * + * @param mixed $serverId + * @param array $data + * + * @return ServerDatabase + */ + public function create($serverId, array $data) + { + return $this->http->post("servers/$serverId/databases", [], $data); + } + + /** + * Reset password for a specified database of a server. + * + * @param mixed $serverId + * @param int $databaseId + * + * @return void + */ + public function resetPassword($serverId, int $databaseId) + { + return $this->http->post("servers/$serverId/databases/$databaseId/reset-password"); + } + + /** + * Delete the given database of a server. + * + * @param mixed $serverId + * @param int $databaseId + * + * @return void + */ + public function delete($serverId, int $databaseId) + { + return $this->http->delete("servers/$serverId/databases/$databaseId"); + } +} diff --git a/src/Managers/ServerManager.php b/src/Managers/ServerManager.php new file mode 100644 index 0000000..604c132 --- /dev/null +++ b/src/Managers/ServerManager.php @@ -0,0 +1,221 @@ +apiType) { + case 'application': + return $this->http->get('servers', array_merge([ + 'page' => $page, + ], $query)); + break; + case 'client': + return $this->http->get('', array_merge([ + 'page' => $page, + ], $query)); + break; + } + } + + /** + * Get a server instance by id. + * + * @param mixed $serverId + * @param array $query + * + * @return Server + */ + public function get($serverId, array $query = []) + { + return $this->http->get("servers/$serverId", $query); + } + + /** + * Get a server instance by external id. + * + * @param int $externalId + * @param array $query + * + * @return Server + */ + public function getByExternalId(int $externalId, array $query = []) + { + return $this->http->get("servers/external/$externalId", $query); + } + + /** + * Create a new server. + * + * @param array $data + * + * @return Server + */ + public function create(array $data) + { + return $this->http->post('servers', [], $data); + } + + /** + * Update details of a specified server. + * + * @param int $serverId + * @param array $data + * + * @return void + */ + public function updateDetails(int $serverId, array $data) + { + return $this->http->patch("servers/$serverId/details", [], $data); + } + + /** + * Update build of a specified server. + * + * @param int $serverId + * @param array $data + * + * @return void + */ + public function updateBuild(int $serverId, array $data) + { + return $this->http->patch("servers/$serverId/build", [], $data); + } + + /** + * Update startup of a specified server. + * + * @param int $serverId + * @param array $data + * + * @return void + */ + public function updateStartup(int $serverId, array $data) + { + return $this->http->patch("servers/$serverId/startup", [], $data); + } + + /** + * Suspend a specified server. + * + * @param int $serverId + * + * @return void + */ + public function suspend(int $serverId) + { + return $this->http->post("servers/$serverId/suspend"); + } + + /** + * Unsuspend a specified server. + * + * @param int $serverId + * + * @return void + */ + public function unsuspend(int $serverId) + { + return $this->http->post("servers/$serverId/unsuspend"); + } + + /** + * Reinstall a specified server. + * + * @param int $serverId + * + * @return void + */ + public function reinstall(int $serverId) + { + return $this->http->post("servers/$serverId/reinstall"); + } + + /** + * Delete the given server. + * + * @param int $serverId + * + * @return void + */ + public function delete(int $serverId) + { + return $this->http->delete("servers/$serverId"); + } + + /** + * Force delete the given server. + * + * @param int $serverId + * + * @return void + */ + public function forceDelete(int $serverId) + { + return $this->http->delete("servers/$serverId/force"); + } + + /** + * Get information for websocket console of a specified server. + * + * @param string $serverId + * + * @return array + */ + public function websocket(string $serverId) + { + return $this->http->get("servers/$serverId/websocket"); + } + + /** + * Get resource utilization of a specified server. + * + * @param string $serverId + * + * @return Stats + */ + public function resources(string $serverId) + { + return $this->http->get("servers/$serverId/resources"); + } + + /** + * Send a command to a specified server. + * + * @param string $serverId + * @param string $command + * + * @return array + */ + public function command(string $serverId, string $command) + { + return $this->http->post("servers/$serverId/command", [], ['command' => $command]); + } + + /** + * Send a power signal to a specified server. + * + * @param string $serverId + * @param string $signal + * + * @return array + */ + public function power(string $serverId, string $signal) + { + return $this->http->post("servers/$serverId/power", [], ['signal' => $signal]); + } +} diff --git a/src/Managers/UserManager.php b/src/Managers/UserManager.php new file mode 100644 index 0000000..cd479e5 --- /dev/null +++ b/src/Managers/UserManager.php @@ -0,0 +1,87 @@ +http->get('users', array_merge([ + 'page' => $page, + ], $query)); + } + + /** + * Get a user instance by user id. + * + * @param int $userId + * @param array $query + * + * @return User + */ + public function get(int $userId, array $query = []) + { + return $this->http->get("users/$userId", $query); + } + + /** + * Get a user instance by user external id. + * + * @param string $externalId + * @param array $includes + * + * @return User + */ + public function getByExternalid(string $externalId, array $query = []) + { + return $this->http->get("users/external/$externalId", $query); + } + + /** + * Create a new user. + * + * @param array $data + * + * @return User + */ + public function create(array $data) + { + return $this->http->post('users', [], $data); + } + + /** + * Update a specified user. + * + * @param int $userId + * @param array $data + * + * @return User + */ + public function update(int $userId, array $data) + { + return $this->http->patch("users/$userId", [], $data); + } + + /** + * Delete the given user. + * + * @param int $userId + * + * @return void + */ + public function delete(int $userId) + { + return $this->http->delete("users/$userId"); + } +} diff --git a/src/Pterodactyl.php b/src/Pterodactyl.php index 021a2db..6f9f1d0 100644 --- a/src/Pterodactyl.php +++ b/src/Pterodactyl.php @@ -2,147 +2,140 @@ namespace HCGCloud\Pterodactyl; -use GuzzleHttp\Client as HttpClient; +use GuzzleHttp\Client as Client; +use HCGCloud\Pterodactyl\Exceptions\InvaildApiTypeException; +use HCGCloud\Pterodactyl\Managers\AccountManager; +use HCGCloud\Pterodactyl\Managers\LocationManager; +use HCGCloud\Pterodactyl\Managers\Nest\NestEggManager; +use HCGCloud\Pterodactyl\Managers\NestManager; +use HCGCloud\Pterodactyl\Managers\Node\NodeAllocationManager; +use HCGCloud\Pterodactyl\Managers\NodeManager; +use HCGCloud\Pterodactyl\Managers\Server\ServerDatabaseManager; +use HCGCloud\Pterodactyl\Managers\ServerManager; +use HCGCloud\Pterodactyl\Managers\UserManager; class Pterodactyl { - use MakesHttpRequests; - use Actions\ManagesUsers; - use Actions\ManagesServers; - use Actions\ManagesAllocations; - use Actions\UsesServers; - use Actions\ManagesNodes; - use Actions\ManagesNests; - use Actions\ManagesEggs; - use Actions\ManagesLocations; + /** + * The Pterodactyl base uri. + * + * @var string + */ + public $baseUri; /** - * The Pterodactyl API Key. + * The Pterodactyl API key. * * @var string */ public $apiKey; /** - * The Pterodactyl Base Uri. + * The API type of the API key. * * @var string */ - public $baseUri; + public $apiType; /** - * The Guzzle HTTP Client instance. + * The Http client. * - * @var \GuzzleHttp\Client + * @var Client */ - public $guzzle; + public $http; /** - * Number of seconds a request is retried. + * Account manager. * - * @var int + * @var AccountManager */ - public $timeout = 30; + public $account; /** - * Create a new Pterodactyl instance. + * Location manager. * - * @param string $apiKey - * @param \GuzzleHttp\Client $guzzle - * - * @return void + * @var LocationManager */ - public function __construct($apiKey, $baseUri, HttpClient $guzzle = null) - { - $this->apiKey = $apiKey; - - $this->baseUri = $baseUri; - - $this->guzzle = $guzzle ?: new HttpClient([ - 'base_uri' => $this->baseUri, - 'http_errors' => false, - 'headers' => [ - 'Accept' => 'application/json', - 'Content-Type' => 'application/json', - ], - ]); - } + public $locations; /** - * Transform response data to resources. - * - * @param array $response + * User manager. * - * @return mixed + * @var UserManager */ - protected function transform($response) - { - if (empty($response['object'])) { - return $response; - } - - switch ($response['object']) { - case 'list': - $data = array_map(function ($object) { - return $this->transform($object); - }, $response['data']); - - if (isset($response['meta'])) { - return [ - 'data' => $data, - 'meta' => $response['meta'], - ]; - } - - return $data; - } - - if (isset($response['attributes']['relationships'])) { - $response['attributes']['relationships'] = array_map(function ($object) { - return $this->transform($object); - }, $response['attributes']['relationships']); - } - - $class = '\\HCGCloud\\Pterodactyl\\Resources\\'.ucwords($response['object']); - - $resource = class_exists($class) ? new $class($response['attributes'], $this) : $response['attributes']; + public $users; - return $resource; - } + /** + * Nest manager. + * + * @var NestManager + */ + public $nests; /** - * Transform include array to url parameter. + * Node manager. * - * @param array $includes + * @var NodeManager + */ + public $nodes; + + /** + * Node allocation manager. * - * @return string + * @var NodeAllocationManager */ - protected function include($includes) - { - return empty($includes) ? '' : '?include='.implode(',', $includes); - } + public $node_allocations; /** - * Set a new timeout. + * Nest egg manager. * - * @param int $timeout + * @var NestEggManager + */ + public $nest_eggs; + + /** + * Server manager. * - * @return $this + * @var ServerManager */ - public function setTimeout($timeout) - { - $this->timeout = $timeout; + public $servers; - return $this; - } + /** + * Server database manager. + * + * @var ServerDatabaseManager + */ + public $server_databases; /** - * Get the timeout. + * Create a new Pterodactyl instance. + * + * @param string $apiKey + * @param \GuzzleHttp\Client $guzzle * - * @return int + * @return void */ - public function getTimeout() + public function __construct($baseUri, $apiKey, $apiType = 'application', Client $guzzle = null) { - return $this->timeout; + $this->baseUri = $baseUri; + + $this->apiKey = $apiKey; + + if (!in_array($apiType, ['application', 'client'], true)) { + throw new InvaildApiTypeException(); + } + $this->apiType = $apiType; + + $this->http = new Http($this, $guzzle); + + $this->locations = new LocationManager($this); + $this->users = new UserManager($this); + $this->nests = new NestManager($this); + $this->nest_eggs = new NestEggManager($this); + $this->nodes = new NodeManager($this); + $this->node_allocations = new NodeAllocationManager($this); + $this->account = new AccountManager($this); + $this->servers = new ServerManager($this); + $this->server_databases = new ServerDatabaseManager($this); } } diff --git a/src/Resources/Allocation.php b/src/Resources/Allocation.php index dfe11b2..40b0ff9 100644 --- a/src/Resources/Allocation.php +++ b/src/Resources/Allocation.php @@ -4,38 +4,4 @@ class Allocation extends Resource { - /** - * The id of the allocation. - * - * @var int - */ - public $id; - - /** - * The ip address of the allocation. - * - * @var string - */ - public $ip; - - /** - * The ip alias of the allocation. - * - * @var string - */ - public $alias; - - /** - * The port of the allocation. - * - * @var int - */ - public $port; - - /** - * The assign status of the allocation. - * - * @var bool - */ - public $assigned; } diff --git a/src/Resources/ApiKey.php b/src/Resources/ApiKey.php new file mode 100644 index 0000000..6d6615a --- /dev/null +++ b/src/Resources/ApiKey.php @@ -0,0 +1,7 @@ +attributes = $attributes; + + $this->pterodactyl = $pterodactyl; + } + + /** + * Convert resource to array. + * + * @return array + */ + public function toArray() + { + return $this->all(); + } + + /** + * Get meta data of resource. + * + * @return array + */ + public function meta() + { + return $this->attributes['meta']; + } + + public function all() + { + return $this->attributes['data']; + } + + public function get($offset) + { + return $this->attributes['data'][$offset]; + } + + public function set($offset, $value) + { + $this->attributes['data'][$offset] = $value; + } + + public function has($offset) + { + return isset($this->attributes['data'][$offset]); + } + + public function forget($offset) + { + unset($this->attributes['data'][$offset]); + } + + public function offsetGet($offset) + { + return $this->offsetExists($offset) ? $this->get($offset) : null; + } + + public function offsetSet($offset, $value) + { + $this->set($offset, $value); + } + + public function offsetUnset($offset) + { + if ($this->offsetExists($offset)) { + $this->forget($offset); + } + } + + public function offsetExists($offset) + { + return $this->has($offset); + } + + public function jsonSerialize() + { + return $this->attributes['data']; + } + + public function serialize() + { + return serialize($this->attributes['data']); + } + + public function unserialize($serialized) + { + return $this->attributes['data'] = unserialize($serialized); + } +} diff --git a/src/Resources/DatabasePassword.php b/src/Resources/DatabasePassword.php new file mode 100644 index 0000000..c9ef902 --- /dev/null +++ b/src/Resources/DatabasePassword.php @@ -0,0 +1,7 @@ +pterodactyl->deleteLocation($this->id); + return $this->pterodactyl->locations->delete($this->id); } /** - * Update the given location. + * Update the location. + * + * @param array $data * * @return void */ @@ -61,6 +28,6 @@ public function update(array $data = []) 'long' => $this->long, ], $data); - return $this->pterodactyl->updateLocation($this->id, $data); + return $this->pterodactyl->locations->update($this->id, $data); } } diff --git a/src/Resources/Nest.php b/src/Resources/Nest.php index 52993d4..b668672 100644 --- a/src/Resources/Nest.php +++ b/src/Resources/Nest.php @@ -2,77 +2,7 @@ namespace HCGCloud\Pterodactyl\Resources; + class Nest extends Resource { - /** - * The id of the nest. - * - * @var int - */ - public $id; - - /** - * The uuid of the nest. - * - * @var string - */ - public $uuid; - - /** - * The author of the nest. - * - * @var string - */ - public $author; - - /** - * The name of the nest. - * - * @var string - */ - public $name; - - /** - * The description of the nest. - * - * @var string - */ - public $description; - - /** - * The date/time the nest was created. - * - * @var string - */ - public $createdAt; - - /** - * The date/time the nest was updated. - * - * @var string - */ - public $updatedAt; - - /** - * Get a collection of eggs in the given nest. - * - * @return Egg[] - */ - public function eggs() - { - return $this->pterodactyl->eggs($this->id); - } - - /** - * Get a egg instance in the given nest. - * - * @param int $eggId - * @param array $includes - * - * @return Egg - */ - public function egg($eggId, array $includes = []) - { - return $this->pterodactyl->egg($this->id, $eggId, $includes); - } } diff --git a/src/Resources/Node.php b/src/Resources/Node.php index 6dc5bde..0a6af2c 100644 --- a/src/Resources/Node.php +++ b/src/Resources/Node.php @@ -5,193 +5,24 @@ class Node extends Resource { /** - * The id of the node. - * - * @var int - */ - public $id; - - /** - * The node is public or not. - * - * @var int - */ - public $public; - - /** - * The name of the node. - * - * @var string - */ - public $name; - - /** - * The description of the node. - * - * @var string - */ - public $description; - - /** - * The location id of the node. - * - * @var int - */ - public $locationId; - - /** - * The fqdn of the node. - * - * @var string - */ - public $fqdn; - - /** - * The scheme of the node. - * - * @var string - */ - public $scheme; - - /** - * The behind proxy set of the node. - * - * @var boolen - */ - public $behindProxy; - - /** - * The maintenance mode status of the node. - * - * @var string - */ - public $maintenanceMode; - - /** - * The memory of the node. - * - * @var int - */ - public $memory; - - /** - * The memory overallocate of the node. - * - * @var int - */ - public $memoryOverallocate; - - /** - * The disk of the node. - * - * @var int - */ - public $disk; - - /** - * The disk overallocate of the node. - * - * @var int - */ - public $diskOverallocate; - - /** - * The upload size of the node. - * - * @var int - */ - public $uploadSize; - - /** - * The daemon listen port of the node. - * - * @var int - */ - public $daemonListen; - - /** - * The daemon sftp port of the node. - * - * @var int - */ - public $daemonSftp; - - /** - * The daemon base of the node. - * - * @var string - */ - public $daemonBase; - - /** - * The date/time the node was created. - * - * @var string - */ - public $createdAt; - - /** - * The date/time the node was updated. - * - * @var string - */ - public $updatedAt; - - /** - * Delete the given node. + * Delete the node. * * @return void */ public function delete() { - return $this->pterodactyl->deleteNode($this->id); + return $this->pterodactyl->nodes->delete($this->id); } /** - * Update the given node. + * Update the node. * * @param array $data * * @return void */ - public function update(array $data) - { - return $this->pterodactyl->updateNode($this->id, $data); - } - - /** - * Get a collection of allocations of the given node. - * - * @param int $page - * - * @return array - */ - public function allocations(int $page = 1) - { - return $this->pterodactyl->allocations($this->id, $page); - } - - /** - * Create new allocation(s) of the given node. - * - * @param array $data - * - * @return void - */ - public function createAllocation(array $data) - { - return $this->pterodactyl->createAllocation($this->id, $data); - } - - /** - * Delete a allocation of the given node. - * - * @param int $allocationId - * - * @return void - */ - public function deleteAllocation(int $allocationId) + public function update(array $data = []) { - return $this->pterodactyl->deleteAllocation($this->id, $allocationId); + return $this->pterodactyl->nodes->update($this->id, $data); } } diff --git a/src/Resources/RecoveryTokens.php b/src/Resources/RecoveryTokens.php new file mode 100644 index 0000000..4cd3f62 --- /dev/null +++ b/src/Resources/RecoveryTokens.php @@ -0,0 +1,7 @@ +attributes = $attributes; + + $this->origin = $this->attributes = $attributes; + $this->pterodactyl = $pterodactyl; + } - $this->fill(); + public function getChangedData() + { + $data = array_diff($this->attributes, $this->origin); + + $this->origin = $this->attributes; + + return $data; } - /** - * Fill the resource with the array of attributes. - * - * @return void - */ - private function fill() + public function __set($key, $value) { - foreach ($this->attributes as $key => $value) { - $key = $this->camelCase($key); + $this->attributes[$key] = $value; + } - $this->{$key} = $value; - } + public function __get($key) + { + return $this->attributes[$key]; + } + + public function __isset($key) + { + return isset($this->attributes[$key]); + } + + public function __unset($key) + { + unset($this->attributes[$key]); } /** - * Convert the key name to camel case. + * Convert resource to array. * - * @param $key + * @return array */ - private function camelCase($key) + public function toArray() + { + return $this->all(); + } + + public function all() + { + return $this->attributes; + } + + public function get($offset) + { + return $this->attributes[$offset]; + } + + public function set($offset, $value) { - $parts = explode('_', $key); + $this->attributes[$offset] = $value; + } + + public function has($offset) + { + return isset($this->attributes[$offset]); + } - foreach ($parts as $i => $part) { - if ($i !== 0) { - $parts[$i] = ucfirst($part); - } + public function forget($offset) + { + unset($this->attributes[$offset]); + } + + public function offsetGet($offset) + { + return $this->offsetExists($offset) ? $this->get($offset) : null; + } + + public function offsetSet($offset, $value) + { + $this->set($offset, $value); + } + + public function offsetUnset($offset) + { + if ($this->offsetExists($offset)) { + $this->forget($offset); } + } + + public function offsetExists($offset) + { + return $this->has($offset); + } - return str_replace(' ', '', implode(' ', $parts)); + public function jsonSerialize() + { + return $this->attributes; + } + + public function serialize() + { + return serialize($this->attributes); + } + + public function unserialize($serialized) + { + return $this->attributes = unserialize($serialized); } } diff --git a/src/Resources/ScheduleTask.php b/src/Resources/ScheduleTask.php new file mode 100644 index 0000000..083ad3a --- /dev/null +++ b/src/Resources/ScheduleTask.php @@ -0,0 +1,7 @@ +pterodactyl->deleteServer($this->id); - } - - /** - * Force delete the given server. - * - * @return void - */ - public function forceDelete() - { - return $this->pterodactyl->forceDeleteServer($this->id); - } - - /** - * Suspend the server. - * - * @return void - */ - public function suspend() - { - return $this->pterodactyl->suspendServer($this->id); - } - - /** - * Unsuspend the server. - * - * @return void - */ - public function unsuspend() - { - return $this->pterodactyl->unsuspendServer($this->id); - } - - /** - * Update details of the server. - * - * @param array $data - * - * @return void - */ - public function updateDetails(array $data = []) - { - $data = array_merge([ - 'name' => $this->name, - 'user' => $this->user, - ], $data); - - return $this->pterodactyl->updateServerDetails($this->id, $data); - } - - /** - * Update build configuration of the server. - * - * @param array $data - * - * @return void - */ - public function updateBuild(array $data = []) - { - $data = array_merge([ - 'allocation' => $this->allocation, - 'limits' => $this->limits, - 'feature_limits' => $this->featureLimits, - ], $data); - - return $this->pterodactyl->updateServerBuild($this->id, $data); - } - - /** - * Update startup parameters of the server. - * - * @param array $data - * - * @return void - */ - public function updateStartup(array $data = []) - { - $data = array_merge([ - 'startup' => $this->container['startup_command'], - 'egg' => $this->egg, - 'image' => $this->container['image'], - 'environment' => $this->container['environment'], - 'skip_scripts' => 0, - ], $data); - - return $this->pterodactyl->updateServerStartup($this->id, $data); - } - - /** - * Reinstall the server. - * - * @return void - */ - public function reinstall() - { - return $this->pterodactyl->reinstallServer($this->id); - } - - /** - * Rebuild the server. - * - * @return void - */ - public function rebuild() - { - return $this->pterodactyl->rebuildServer($this->id); - } - - /** - * Power the server. - * - * @param string $action - * - * @return void - */ - public function power(string $action) - { - return $this->pterodactyl->powerServer($this->identifier, $action); - } - - /** - * Send command to the server. - * - * @param string $command - * - * @return void - */ - public function command(string $command) - { - return $this->pterodactyl->commandServer($this->identifier, $command); - } - - /** - * Get a collection of databases of the server. - * - * @return ServerDatabase[] - */ - public function databases() - { - return $this->pterodactyl->serverDatabases($this->id); - } - - /** - * Get a database instance of the server. - * - * @param int $databaseId - * - * @return ServerDatabase - */ - public function database(int $databaseId) - { - return $this->pterodactyl->serverDatabase($this->id, $databaseId); - } - - /** - * Create a database for the server. - * - * @param array $data - * - * @return ServerDatabase - */ - public function createDatabase(array $data) - { - return $this->pterodactyl->createServerDatabase($this->id, $data); - } - - /** - * Reset a database password of the server. - * - * @param int $databaseId - * - * @return void - */ - public function resetDatabasePassword(int $databaseId) - { - return $this->pterodactyl->resetServerDatabasePassword($this->id, $databaseId); - } - - /** - * Delete a database of the server. - * - * @param int $databaseId - * - * @return void - */ - public function deleteDatabase(int $databaseId) - { - return $this->pterodactyl->deleteServerDatabase($this->id, $databaseId); - } } diff --git a/src/Resources/ServerDatabase.php b/src/Resources/ServerDatabase.php index e20a9bd..693b86d 100644 --- a/src/Resources/ServerDatabase.php +++ b/src/Resources/ServerDatabase.php @@ -4,79 +4,4 @@ class ServerDatabase extends Resource { - /** - * The id of the server's database. - * - * @var int - */ - public $id; - - /** - * The server id of the server's database. - * - * @var int - */ - public $server; - - /** - * The host id of the server's database. - * - * @var int - */ - public $host; - - /** - * The name of the server's database. - * - * @var string - */ - public $database; - - /** - * The username of the server's database. - * - * @var string - */ - public $username; - - /** - * The remote hostname of the server's database. - * - * @var string - */ - public $remote; - - /** - * The date/time the server was created. - * - * @var string - */ - public $createdAt; - - /** - * The date/time the server was updated. - * - * @var string - */ - public $updatedAt; - - /** - * Reset password of the given server's database. - * - * @return void - */ - public function resetPassword() - { - return $this->pterodactyl->resetServerDatabasePassword($this->server, $this->id); - } - - /** - * Delete the given database of a server. - * - * @return void - */ - public function delete() - { - return $this->pterodactyl->deleteServerDatabase($this->server, $this->id); - } } diff --git a/src/Resources/ServerSchedule.php b/src/Resources/ServerSchedule.php new file mode 100644 index 0000000..859a5cb --- /dev/null +++ b/src/Resources/ServerSchedule.php @@ -0,0 +1,7 @@ +update(array_merge( + [ + 'email' => $this->email, + 'username' => $this->username, + 'first_name' => $this->first_name, + 'last_name' => $this->last_name, ], + $this->getChangedData() + )); + } /** - * The date/time the user was updated. + * Update the user. * - * @var string - */ - public $updatedAt; - - /** - * Delete the given user. + * @param array $data * * @return void */ - public function delete() + public function update(array $data) { - return $this->pterodactyl->deleteUser($this->id); + $this->pterodactyl->users->update($this->id, $data); } /** - * Update the given user. - * - * @param array $data + * Delete the user. * * @return void */ - public function update(array $data = []) + public function delete() { - $data = array_merge([ - 'username' => $this->username, - 'email' => $this->email, - 'first_name' => $this->firstName, - 'last_name' => $this->lastName, - ], $data); - - return $this->pterodactyl->updateUser($this->id, $data); + $this->pterodactyl->users->delete($this->id); } }