pjz9n/pterodactyl-php-sdk

Simple and lightweight Pterodactyl API SDK

v1.0.0 2020-03-08 09:03 UTC

This package is auto-updated.

Last update: 2025-06-09 11:27:10 UTC


README

Overview

Language:

English

Simple and lightweight Pterodactyl API SDK

Feature

  • Simply SDK
  • Clean code
  • No dependency on other libraries
  • use the complement function of the IDE
  • Can be used intuitively
  • Object-oriented code

Supported Action

Client API:

  • Get All Servers
  • Get Server (By ID)
  • Get Resource (For example, get the amount of memory currently used)
  • Send Console Command
  • Send Power Action (For example, server start)

Application API:

  • User
    • Get All Users
    • Get User (By ID)
    • Get User (By External ID)
    • Create User
    • Edit User
    • Delete User
  • Nodes
    • Now Development...

How to use

Run the following command in the command line

composer require pjz9n/pterodactyl-php-sdk

Write the code!

<?php

declare(strict_types=1);

require_once __DIR__ . "/vendor/autoload.php";

$url = "https://panel.example.com/api";
$key = "API Key";

$clientAPI = new \PJZ9n\PterodactylSDK\ClientAPI($url, $key);

echo "Server Counts: ";
try {
    echo count($clientAPI->getServers()) . PHP_EOL;
} catch (\PJZ9n\PterodactylSDK\Errors\PterodactylSDKError $pterodactylSDKError) {
    echo "Error: " . $pterodactylSDKError->getMessage();
}

$serverID = "1ab234c5";

echo "Start Server" . PHP_EOL;
try {
    $clientAPI->sendPowerAction($serverID, \PJZ9n\PterodactylSDK\Variables\PowerAction\PowerAction::POWERACTION_START);
} catch (\PJZ9n\PterodactylSDK\Errors\PterodactylSDKError $pterodactylSDKError) {
    echo "Error: " . $pterodactylSDKError->getMessage();
}

echo "Server Memory Limit: ";
try {
    echo $clientAPI->getResource($serverID)->getMemory()->getLimit() . "MB" . PHP_EOL;
} catch (\PJZ9n\PterodactylSDK\Errors\PterodactylSDKError $pterodactylSDKError) {
    echo "Error: " . $pterodactylSDKError->getMessage();
}

/*
 * Result
 * 
 * Server Counts: 100
 * Start Server
 * Server Memory Limit: 1000MB
 */

日本語

シンプルで軽量なPterodactyl APIのSDK

特徴

  • シンプルなSDK
  • クリーンなコード
  • 他ライブラリへの依存性無し
  • IDEによる補完を利用できる
  • 直観的に扱える
  • オブジェクト指向なコード

サポートしている操作

Client API:

  • 全てのサーバーを取得
  • サーバーを取得 (IDから)
  • リソースを取得 (例えば、現在使っているメモリの量を取得)
  • コンソールコマンドを送信
  • 電源アクションを送信 (例えば、サーバーの起動)

Application API:

  • User
    • 全てのユーザーを取得
    • ユーザーを取得 (IDから)
    • ユーザーを取得 (External IDから)
    • ユーザーを作成
    • ユーザーを編集
    • ユーザーを削除
  • Nodes
    • 開発中...

使い方

コマンドラインで以下のコマンドを実行する

composer require pjz9n/pterodactyl-php-sdk

コードを書く!

<?php

declare(strict_types=1);

require_once __DIR__ . "/vendor/autoload.php";

$url = "https://panel.example.com/api";
$key = "API Key";

$clientAPI = new \PJZ9n\PterodactylSDK\ClientAPI($url, $key);

echo "Server Counts: ";
try {
    echo count($clientAPI->getServers()) . PHP_EOL;
} catch (\PJZ9n\PterodactylSDK\Errors\PterodactylSDKError $pterodactylSDKError) {
    echo "Error: " . $pterodactylSDKError->getMessage();
}

$serverID = "1ab234c5";

echo "Start Server" . PHP_EOL;
try {
    $clientAPI->sendPowerAction($serverID, \PJZ9n\PterodactylSDK\Variables\PowerAction\PowerAction::POWERACTION_START);
} catch (\PJZ9n\PterodactylSDK\Errors\PterodactylSDKError $pterodactylSDKError) {
    echo "Error: " . $pterodactylSDKError->getMessage();
}

echo "Server Memory Limit: ";
try {
    echo $clientAPI->getResource($serverID)->getMemory()->getLimit() . "MB" . PHP_EOL;
} catch (\PJZ9n\PterodactylSDK\Errors\PterodactylSDKError $pterodactylSDKError) {
    echo "Error: " . $pterodactylSDKError->getMessage();
}

/*
 * 結果
 * 
 * Server Counts: 100
 * Start Server
 * Server Memory Limit: 1000MB
 */