blesta/pterodactyl-sdk

Pterodactyl SDK

安装: 461

依赖: 1

建议: 0

安全性: 0

星星: 2

关注者: 6

分支: 1

开放问题: 1

类型:sdk

1.3.0 2021-09-17 20:41 UTC

This package is auto-updated.

Last update: 2024-09-20 04:13:18 UTC


README

这是一个与Pterodactyl API集成的SDK,详情请参考Pterodactyl 文档

安装

您可以通过composer安装SDK

composer require blesta/pterodactyl-sdk

用法

初始化API

$useSsl = true;
$api = new \Blesta\PterodactylSDK\PterodactylApi('API_KEY', 'PANEL_URL', $useSsl);

需要注意的是,Pterodactyl面板有两个API:应用程序API和账户API。账户API/密钥应用于访问客户端请求者,而应用程序API/密钥应用于其他所有请求者。

加载请求者

请求者定义:SDK用来访问特定类型API端点的一个类(例如服务器、巢或位置)。

SDK利用PHP的__get()魔术方法,请求者可以像访问加载的api的属性一样进行访问。例如

$clientRequestor = $api->Client;

调用端点

所有端点都存在于请求者的一个方法上。例如,application/locations/端点可以这样调用

$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();
    ...
    ...
    ...
}