fozzy-hosting / winvps-api-php
该包已被弃用且不再维护。未建议替代包。
Fozzy Windows VPS APIv2 PHP 客户端库
2.3.0
2020-05-19 06:59 UTC
Requires
- php: >=5.5
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- guzzlehttp/guzzle: ^6.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ~1.12
- squizlabs/php_codesniffer: ~2.6
README
Fozzy Windows VPS API 客户端库 for PHP
API 客户端库允许您使用 Fozzy Windows VPS API 创建或管理您的机器。
要求
PHP 5.5 及更高版本
开发者文档
实际的 API 文档可在以下链接找到:链接。
文档文件夹 docs 提供了使用当前库的详细指南。
安装与使用
您可以使用 Composer 安装此包。
Composer
要通过 Composer 安装绑定,请将以下内容添加到 composer.json
fozzy-hosting
首选方法是使用 composer。如果您尚未安装 composer,请按照安装说明进行操作。
一旦安装了 composer,请在项目根目录下执行以下命令以安装此库
composer require fozzy-hosting/fozzy-winvps-api
最后,请确保包含自动加载器
require_once '/path/to/your-project/vendor/autoload.php';
授权
要发送请求,您需要获取 API 密钥,具体请参阅 API 文档。
完整示例
<?php require_once(__DIR__ . '/vendor/autoload.php'); use Fozzy\WinVPS\Api\Configuration; use Fozzy\WinVPS\Api\Repository; use Fozzy\WinVPS\Api\Models\MachineCreateRequestBody; $host = 'Endpoint from API docs'; $key = 'API key from WinVPS client area'; try { // Create configuration object. $config = Configuration::getDefaultConfiguration() ->setHost($host) ->setApiKey($key); /* Create repository by passing the `config` instance. Repository allows to get an Instance for each class of API Endpoints described in docs foler. */ $repository = new Repository($config); // Get API Instance object to make requests. $machinesInstance = $repository->get('machines'); // Prepare request to create new machine. $body = new \Fozzy\WinVPS\Api\Models\MachineCreateRequestBody([ 'productId' => 17, 'templateId' => 72, 'locationId' => 1, ]); // Create new machine $machinesInstance->machinesPost($body); /* Load all machines from the endpoint. Only the part of records will be returned because API uses pagination */ $allMachinesPage = $machinesInstance->machinesGet(); print_r($allMachinesPage); } catch (Exception $e) { echo 'Exception when calling BrandsApi->brandsGet: ', $e->getMessage(), PHP_EOL; } ?>
分页
<?php /** * Each of the API Instances supports the next methods: * * paginationSetLimit($limit) - setup new per-page amount * paginationNext() - go to the next page * paginationPrev() - go to the previous page * paginationGetTotal() - total recourds amount * paginationGetPage() - get current page number * paginationGetPages() - get total pages count * paginationHasMore() - does the next page exists */ // Example based on the previous code do { $allMachinesPage = $machinesInstance->machinesGet(); $machinesInstance->paginationNext(); } while ($machinesInstance->paginationHasMore()); ?>