kylewlawrence / gridpane-api-client-php
GridPane API PHP SDK
Requires
- php: >=8.1
- doctrine/inflector: ^2.0
- guzzlehttp/guzzle: ^7.0
- guzzlehttp/psr7: ^2.0
Requires (Dev)
- bshaffer/phpunit-retry-annotations: ^0.3.0
- fzaninotto/faker: >=1.5.0
- phpmd/phpmd: @stable
- phpunit/phpunit: ^9.5
- psy/psysh: ^0.11
- squizlabs/php_codesniffer: 2.*
README
API 客户端版本
这是 GridPane API 的第一个社区赞助 PHP SDK 客户端版本。
API 版本支持
此客户端 仅 支持 GridPane 的 API v1。有关更多信息,请参阅他们的 API 文档。
要求
- PHP 8.1+
安装
GridPane API PHP SDK 客户端可以使用 Composer 安装。
您是否正在与 Laravel 一起使用?如果是这样,请使用 Laravel 包装器。
Composer
要安装,请运行 composer require kylewlawrence/gridpane-api-client-php
配置
配置通过 GridPane\Api\HttpClient
实例完成。该块是必需的,如果不传递,将抛出错误。
// load Composer require 'vendor/autoload.php'; use KyleWLawrence\GridPane\Api\HttpClient as GridPaneAPI; $bearer = "6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv"; // replace this with your GridPane Personal Access/Bearer token $client = new GridPaneAPI(); $client->setAuth('bearer', ['bearer' => $bearer]);
使用方法
基本操作
// Get all servers $servers = $client->servers()->getAll(); print_r($servers); // Create a new server $newServer = $client->servers()->create([ 'servername' => 'hal9000', 'ip' => '199.199.199.199', 'datacenter' => 'space-station-v', 'webserver' => 'nginx', 'database' => 'percona' ]); print_r($newServer); // Update a server $client->servers()->update(12345,[ 'security_updates_reboot_time' => '04:00' ]); // Delete a server $client->servers()->delete(12345); // Get all sites $sites = $client->sites()->getAll(); print_r($sites);
发现方法和类
// Get the base methods/classes available $client->getValidSubResrouces() // The above example will output something like: [ "backups" => "GridPane\Api\Resources\Core\Backups", "bundle" => "GridPane\Api\Resources\Core\Bundle", "domain" => "GridPane\Api\Resources\Core\Domain", "server" => "GridPane\Api\Resources\Core\Server", "site" => "GridPane\Api\Resources\Core\Site", "systemUser" => "GridPane\Api\Resources\Core\SystemUser", "teams" => "GridPane\Api\Resources\Core\Teams", "user" => "GridPane\Api\Resources\Core\User", ] // These are methods/classes that can be chained to the client. For instance: // For instance, "backups" => "GridPane\Api\Resources\Core\Backups", can be used as $client->backups() // To find the chained methods available to the class, now do: $client->site()->getRoutes() // The above example will output something like: [ "getAll" => "site", "get" => "site/{id}", "create" => "site", "update" => "site/{id}", "runCLICommand" => "site/run-wp-cli/{id}", "addWPUser" => "site/add-wp-user/{id}", "delete" => "site", "deleteByID" => "site/{id}", ] // Those routes can be compared with the GridPane documentation routes and run as chained methods such as the below command to get all sites: $client->site()->getAll()
分页
GridPane API 提供了一种获取请求的下一页的方法,并在 GridPane 开发者文档 中进行了说明。
要这样做,请将其作为选项传递给您的请求。
$servers = $this->client->servers()->getAll(['per_page' => 100, 'page' => 2]);
允许的选项有
- per_page
- page
重试请求
在您的 GuzzleHttp\Client
实例的 HandlerStack
上添加 RetryHandler
中间件。默认情况下,GridPane\Api\HttpClient
重试
- 超时请求
- 那些抛出
Psr\Http\Message\RequestInterface\ConnectException:class
- 以及那些抛出
Psr\Http\Message\RequestInterface\RequestException:class
并被识别为 ssl 问题的。
可用选项
选项作为值的数组传递给 RetryHandler
。
- max = 2 重试次数限制
- interval = 300 重试之间的基本延迟(毫秒)
- max_interval = 20000 最大延迟值
- backoff_factor = 1 退避因子
- exceptions = [ConnectException::class] 不检查重试_if 的异常
- retry_if = null 可调用函数,可以决定是否重试请求
贡献
欢迎 Pull Requests。我很快就会开发贡献指南。在此期间,只需打开问题或创建一个 pull request。
版权和许可
版权 2013-至今 GridPane
根据 Apache 许可证 2.0 版(“许可证”)许可;除非适用法律要求或经书面同意,否则不得使用此文件。您可以在以下位置获取许可证副本:
https://apache.ac.cn/licenses/LICENSE-2.0
除非适用法律要求或经书面同意,否则在许可证下分发的软件按“原样”提供,不提供任何明示或暗示的保证或条件。有关许可证的具体语言管理权限和限制,请参阅许可证。