myvariety / wisp-sdk
Wisp SDK
1.0.1
2023-05-11 11:38 UTC
Requires
- php: >=5.4.0
- blesta/composer-installer: ~1.0
This package is auto-updated.
Last update: 2024-09-11 14:48:31 UTC
README
这是一个集成了 Pterodactyl API 的 SDK,可以访问Pterodactyl 的 API。最终将支持 Wisp API。
安装 | 即将推出
您可以通过 composer 安装 SDK
composer require myvariety/wisp-sdk
使用方法
初始化 API
$useSsl = true;
$api = new \MyVariety\WispSDK\WispApi('API_KEY', 'PANEL_URL', $useSsl);
需要注意的是,Pterodactyl 控制面板有两个 API:应用程序 API 和账户 API。账户 API/密钥应用于访问客户端请求者,而应用程序 API/密钥应用于所有其他请求者。
加载请求者
请求者定义:SDK 使用的一个类,用于访问特定类型(例如服务器、巢穴或位置)的 API 端点。
SDK 利用 PHP 的 __get() 魔术方法,因此请求者可以像访问加载的 API 的属性一样访问。例如
$clientRequestor = $api->Client;
调用端点
所有端点都作为请求者的方法存在。例如,应用程序/位置/端点可以这样调用
$locationResponse = $api->Locations->getAll();
或者要调用相同的端点,但使用 post 参数添加新位置,它看起来像这样
$locationResponse = $api->Locations->add($parameters);
使用响应对象
响应对象旨在使访问返回的数据和识别错误更加容易。它具有以下方法
$locationResponse->raw(); // Useful for logging the full response from Pterodactyl
$locationResponse->response(); // The json decoded data returned
$locationResponse->headers(); // An array of http headers returned
$locationResponse->status(); // The status code returned
$locationResponse->errors(); // An array of the errors returned
最常用的方法是 response() 和 errors()
$errors = $locationResponse->errors();
if (empty($errors)) {
$locations = $locationResponse->response();
...
...
...
}