valandur/webapi-client-php

5.4.2.1 2019-07-23 11:43 UTC

This package is auto-updated.

Last update: 2024-09-23 23:42:05 UTC


README

通过WebAPI访问Sponge驱动的Minecraft服务器

简介

这是WebAPI插件提供的各种API路由的文档。
本文档假设您熟悉Web API的基本概念,例如 GETPUTPOSTDELETE 方法,请求 HEADERSRESPONSE CODES 以及 JSON 数据。
默认情况下,本文档可在 http:/localhost:8080(您的Minecraft服务器运行时)找到,并且各种路由以 http:/localhost:8080/api/v5... 开头。
作为一个快速测试,尝试访问路由 http:/localhost:8080/api/v5/info(请记住,您只能在运行Minecraft的服务器上访问“localhost”路由)。此路由应显示有关您服务器的基本信息,如motd和玩家数量。

列出端点

许多对象提供列出所有对象的端点(例如,GET: /world 获取所有世界)。默认情况下,这些端点仅返回标记为 'required' 的属性,因为列表可能很大。如果您想为列表端点返回所有数据,请添加查询参数 details,(例如,GET: /world?details)。

请注意,在这种情况下,端点返回的数据可能相当大。

调试端点

除了 ?details 标志外,您还可以传递一些其他标志用于调试目的。请记住,您必须使用 ? 包含第一个查询参数,并使用 & 包含后续参数

  • details:为列表端点包含详细信息
  • accept=[json/xml]:手动设置接受内容类型。这对于浏览器测试很有用,但不要在生产环境中使用,您可以为它提供 Accepts 头部
  • pretty:格式化打印数据,也适用于在浏览器中进行调试。

一个示例请求可能如下所示:https://:8080/api/v5/world?details&accpet=json&pretty&key=MY-API-KEY

附加数据

某些端点(如 /player/entity/tile-entity)具有一些未在本文档中记录的附加属性,因为这些数据取决于具体对象类型(例如,Sheep 有羊毛颜色,其他没有)以及运行在您服务器上的其他插件/模组,它们可能会添加附加数据。
您还可以在github文档中找到更多信息(https:/github.com/Valandur/Web-API/tree/master/docs/DATA.md)

Swagger

此PHP包由Swagger Codegen项目自动生成

  • API版本:5.4.2-S7.1.0
  • 构建包:io.swagger.codegen.languages.PhpClientCodegen。更多信息,请访问https://github.com/Valandur

要求

PHP 5.5 及以上

安装 & 使用

Composer

要通过Composer安装绑定,请将以下内容添加到 composer.json

{
  "repositories": [
    {
      "type": "git",
      "url": "https://github.com/GIT_USER_ID/GIT_REPO_ID.git"
    }
  ],
  "require": {
    "GIT_USER_ID/GIT_REPO_ID": "*@dev"
  }
}

然后运行 composer install

手动安装

下载文件并包含 autoload.php

    require_once('/path/to/SwaggerClient-php/vendor/autoload.php');

测试

要运行单元测试

composer install
./vendor/bin/phpunit

入门

请遵循安装过程,然后运行以下命令

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure API key authorization: ApiKeyHeader
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('X-WebAPI-Key', 'YOUR_API_KEY');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// $config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('X-WebAPI-Key', 'Bearer');
// Configure API key authorization: ApiKeyQuery
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('key', 'YOUR_API_KEY');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// $config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('key', 'Bearer');

$apiInstance = new Swagger\Client\Api\ActiveTimeApi(
    // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
    // This is optional, `GuzzleHttp\Client` will be used as default.
    new GuzzleHttp\Client(),
    $config
);
$details = true; // bool | Add to include additional details, omit or false otherwise
$accept = "accept_example"; // string | Override the 'Accept' request header (useful for debugging your requests)
$pretty = true; // bool | Add to make the Web-API pretty print the response (useful for debugging your requests)

try {
    $result = $apiInstance->getServerReport($details, $accept, $pretty);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling ActiveTimeApi->getServerReport: ', $e->getMessage(), PHP_EOL;
}

?>

API端点文档

所有URI均相对于 https:///api/v5

模型文档

授权文档

ApiKeyHeader

  • 类型:API密钥
  • API密钥参数名称:X-WebAPI-Key
  • 位置:HTTP头

ApiKeyQuery

  • 类型:API密钥
  • API密钥参数名称:key
  • 位置:URL查询字符串

作者

inithilian@gmail.com