vasyaxy / php-trello-api
Trello API v2 客户端
v0.7
2023-03-30 06:06 UTC
Requires
- php: >=8.0
- guzzlehttp/guzzle: *
- league/oauth1-client: *
- symfony/event-dispatcher: *
Requires (Dev)
Suggests
- symfony/http-foundation: Needed for the Trello webhook service
README
一个简单的PHP7.4编写的Trello API面向对象包装器。
使用Trello API v1。对象API与RESTful API非常相似。
特性
- 遵循PSR-0规范和编码标准:易于自动加载
- 由于API类按需加载,轻量且快速
- 经过广泛测试
- 在Symfony 6.2中测试
要求
"require": {
"php": ">=8.0",
"symfony/event-dispatcher": "*",
"league/oauth1-client": "*",
"guzzlehttp/guzzle": "*"
},
安装
推荐使用composer
$ composer require vasyaxy/php-trello-api
然而,php-trello-api
遵循PSR-0命名规范,这意味着您可以轻松地将php-trello-api
类加载集成到自己的自动加载器中。
创建认证URL
<?php namespace App; use Trello\Client; class TrelloApi { public Client|null $client; public function __construct() { $this->client = new Client(); } public function setupTrelloClient(): void { $this->client->authenticate( 'API_KEY', // Api key - get from https://dashboard.stripe.com/test/apikeys7 'USER_TOKEN (empty)', // Empty for this exampe Client::AUTH_URL_CLIENT_ID // nvm ); } public function getAuthUrl(): string { $this->setupTrelloClient(); return $this->client->getAuthUrl([ 'key' => 'API_KEY', // Api key - get from https://trello.com/power-ups/admin - NEW - get key 'secret' => 'API_SECRET', // ^^^ "Reveal test key" 'callbackUrl' => '!!CALL_BACK_URL!!', // example: 'http://mymegatite.com/trello-hook/' 'name' => 'My Mega Trello App!!!1', // nvm 'expiration' => 'never', // >> MH << 'scope' => 'read,write', // >> MH << ]); } }
基本用法
use Trello\Client; $client = new Client(); $client->authenticate('API_KEY', 'USER_KEY', Client::AUTH_URL_CLIENT_ID); $boards = $client->api('member')->boards()->all();
$client
对象为您提供了访问整个Trello API的权限。
使用Trello管理器的进阶用法
此包在API之上包含一个简单的模型层,并提供了一个方便的可链式API,允许对Trello对象进行后续操作
use Trello\Client; use Trello\Manager; $client = new Client(); $client->authenticate('API_KEY', 'USER_KEY', Client::AUTH_URL_CLIENT_ID); $manager = new Manager($client); $card = $manager->getCard('547440ad3f8b882bc11f0497'); $card ->setName('Test card') ->setDescription('Test description') ->save();
将Trello事件分发给您的应用
此服务使用Symfony EventDispatcher组件将发生在传入webhooks上的事件分发给事件。
查看Events类的常量,了解名称和相关的事件类。
use Trello\Client; use Trello\Service; use Trello\Events; $client = new Client(); $client->authenticate('API_KEY', 'USER_KEY', Client::AUTH_URL_CLIENT_ID); $service = new Service($client); // Bind a callable to a given event... $service->addListener(Events::BOARD_UPDATE, function ($event) { $board = $event->getBoard(); // do something }); // Check if the current request was made by a Trello webhook // This will dispatch any Trello event to listeners defined above $service->handleWebhook();
文档
贡献
请随意提出任何评论、提交问题或发起拉取请求。
许可
php-trello-api
采用MIT许可证 - 有关详细信息,请参阅LICENSE文件
致谢
- 由vasyaxy/php-trello-api分叉
- 很大程度上受到KnpLabs开发的优秀php-github-api的启发
- 感谢Trello提供的API和文档。