kylewlawrence / infinity-api-client-php
Infinity API PHP SDK
Requires
- php: >=8.1
- doctrine/inflector: ^2.0
- guzzlehttp/guzzle: ^7.0
- guzzlehttp/psr7: ^2.0
- ramsey/uuid: >=4.7
Requires (Dev)
- fzaninotto/faker: >=1.5.0
- phpmd/phpmd: @stable
- phpunit/phpunit: ^9.5
- psy/psysh: ^0.11
- squizlabs/php_codesniffer: 2.*
This package is auto-updated.
Last update: 2024-09-30 01:41:17 UTC
README
API客户端版本
这是Infinity API的第一个社区赞助的PHP SDK客户端版本。
API版本支持
此客户端 仅 支持Infinity API v2。有关更多信息,请参阅他们的 API文档。
要求
- PHP 8.1+
安装
Infinity API PHP SDK客户端可以使用 Composer 安装。
您是否在使用Laravel?如果是,请使用 Laravel包装器。
Composer
要安装,请运行 composer require kylewlawrence/infinity-api-client-php
配置
配置是通过一个 KyleWLawrence\Infinity\Api\HttpClient
实例来完成的。此块是强制性的,如果不传递,将会抛出错误。
// load Composer require 'vendor/autoload.php'; use KyleWLawrence\Infinity\Api\HttpClient as InfinityAPI; $workspace = 1234; // replace this with your Infinity workspace ID $bearer = "6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv"; // replace this with your Infinity Personal Access/Bearer token $client = new InfinityAPI($workspace); $client->setAuth('bearer', ['bearer' => $bearer]);
用法
基本操作
// Get all boards $boards = $client->boards()->getAll(); print_r($boards); // Create a new board $newBoard = $client->boards()->create([ 'name' => 'Blah Blah', 'description' => 'Bler bleman blope', 'user_ids' => [1234, 1235, 12346], ]); print_r($newBoard); // Update an item $client->boards('PWefUeHA8Pd')->items('364019f5-0198-407b-931a-4f8ea51ecc28')->update(',[ 'folder_id' => 'U7MjUC5jNpM' ]); // Delete an item value $client->boards('PWefUeHA8Pd')->items(''364019f5-0198-407b-931a-4f8ea51ecc28'')->values()->delete('8b9fee67-600c-499f-ab19-04bd9092be4e'); // Get all workspaces $workspaces = $client->workspaces()->getAll(); print_r($workspaces);
发现方法和类
// Get the base methods/classes available $client->getValidSubResrouces() // The above example will output something like: [ "boards" => "KyleWLawrence\Infinity\Api\Resources\Core\Boards", "profile" => "KyleWLawrence\Infinity\Api\Resources\Core\Profile", "attachments" => "KyleWLawrence\Infinity\Api\Resources\Core\Attachments", "users" => "KyleWLawrence\Infinity\Api\Resources\Core\Users", "workspaces" => "KyleWLawrence\Infinity\Api\Resources\Core\Workspaces", ] // Most available subresources are on the boards class, accessible by: $client->boards()->getValidSubResources() // These are methods/classes that can be chained to the client. For instance: // For instance, "boards" => "KyleWLawrence\Infinity\Api\Resources\Core\Boards", can be used as $client->boards() // To find the chained methods available to the class, now do: $client->boards()->getRoutes() // The above example will output something like: [ "getAll" => "boards", "get" => "board/{id}", "create" => "boards", ] // Those routes can be compared with the Infinity documentation routes and run as chained methods such as the below command to get all sites: $client->boards()->getAll()
分页
Infinity API提供了一种获取请求的下一页的方式,并在Infinity开发者文档中有记录。
要这样做,只需将其作为选项传递给您的请求即可。
$boards = $this->client->boards('PWefUeHA8Pd')->items()->getAll(['after' => '8b9fee67-600c-499f-ab19-04bd9092be4e', 'sort_by' => 'created_at', 'limit' => 100]);
一些允许的选项包括
- sort_by
- after
- before
- limit
请求重试
在您的 GuzzleHttp\Client
实例的 HandlerStack
上添加 RetryHandler
中间件。默认情况下,KyleWLawrence\Infinity\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] 不需要检查retry_if的重试异常
- retry_if = null 可以决定是否重试请求的调用函数
贡献
欢迎提交拉取请求。我很快会跟进并开发贡献指南。在此期间,只需打开问题或创建拉取请求。
版权和许可
版权 2023-至今 Infinity
在Apache License,版本2.0(“许可证”)下许可;除非适用法律要求或书面同意,否则不得使用此文件,除非遵守许可证。您可以在以下位置获得许可证副本:
https://apache.ac.cn/licenses/LICENSE-2.0
除非适用法律要求或书面同意,否则在许可证下分发的软件按“原样”基础分发,不提供任何明示或暗示的保证或条件。有关许可证的具体语言,请参阅许可证。