activecollab / activecollab-feather-sdk
这是一个简单的PHP库,使得与Active Collab API通信变得简单
3.1.4
2019-03-15 22:37 UTC
Requires
- php: >=5.6.0
- ext-curl: *
- ext-json: *
Requires (Dev)
README
这是一个简单的PHP库,使得与Active Collab API通信变得简单。
安装
如果您选择使用Composer安装此应用程序而不是下拉git仓库,您需要在您想要下拉仓库的位置添加一个composer.json文件,包括以下内容
{ "require": { "activecollab/activecollab-feather-sdk": "^3.0" } }
运行composer update
来安装包。
注意:如果您使用了较旧的Active Collab API包装器并使用dev-master
加载它,请将其锁定到版本2.0,通过将require语句设置为^2.0
并调用composer update
。
连接到Active Collab云账户
<?php require_once '/path/to/vendor/autoload.php'; // Provide name of your company, name of the app that you are developing, your email address and password. $authenticator = new \ActiveCollab\SDK\Authenticator\Cloud('ACME Inc', 'My Awesome Application', 'you@acmeinc.com', 'hard to guess, easy to remember'); // Show all Active Collab 5 and up account that this user has access to. print_r($authenticator->getAccounts()); // Show user details (first name, last name and avatar URL). print_r($authenticator->getUser()); // Issue a token for account #123456789. $token = $authenticator->issueToken(123456789); // Did we get it? if ($token instanceof \ActiveCollab\SDK\TokenInterface) { print $token->getUrl() . "\n"; print $token->getToken() . "\n"; } else { print "Invalid response\n"; die(); }
连接到自托管的Active Collab账户
require_once '/path/to/vendor/autoload.php'; // Provide name of your company, name of the app that you are developing, your email address and password. Last parameter is URL where your Active Collab is installed. $authenticator = new \ActiveCollab\SDK\Authenticator\SelfHosted('ACME Inc', 'My Awesome Application', 'you@acmeinc.com', 'hard to guess, easy to remember', 'https://my.company.com/projects'); // Issue a token. $token = $authenticator->issueToken(); // Did we get what we asked for? if ($token instanceof \ActiveCollab\SDK\TokenInterface) { print $token->getUrl() . "\n"; print $token->getToken() . "\n"; } else { print "Invalid response\n"; die(); }
SSL问题?
如果curl抱怨SSL对等验证失败,您可以像这样将其关闭
// Cloud $authenticator = new \ActiveCollab\SDK\Authenticator\Cloud('ACME Inc', 'My Awesome Application', 'you@acmeinc.com', 'hard to guess, easy to remember', false); $authenticator->setSslVerifyPeer(false); // Self-hosted $authenticator = new \ActiveCollab\SDK\Authenticator\SelfHosted('ACME Inc', 'My Awesome Application', 'you@acmeinc.com', 'hard to guess, easy to remember', 'https://my.company.com/projects', false); $authenticator->setSslVerifyPeer(false); // Client $client = new \ActiveCollab\SDK\Client($token); $client->setSslVerifyPeer(false);
注意:在Active Collab SDK 3.1中已添加关闭SSL对等验证的选项。
构建客户端实例
一旦我们有了令牌,我们就可以构建一个客户端并执行API调用
$client = new \ActiveCollab\SDK\Client($token);
列出项目#65中的所有任务很简单。只需调用
$client->get('projects/65/tasks');
要创建任务,只需发送POST请求
try { $client->post('projects/65/tasks', [ 'name' => 'This is a task name', 'assignee_id' => 48 ]); } catch(AppException $e) { print $e->getMessage() . '<br><br>'; // var_dump($e->getServerResponse()); (need more info?) }
要更新任务,需要PUT请求
try { $client->put('projects/65/tasks/123', [ 'name' => 'Updated named' ]); } catch(AppException $e) { print $e->getMessage() . '<br><br>'; // var_dump($e->getServerResponse()); (need more info?) }
post()
和put()
方法可以接受两个参数
command
(必需)- API命令,variables
- 请求变量(有效负载)数组
要删除任务,调用
try { $client->delete('projects/65/tasks/123'); } catch(AppException $e) { print $e->getMessage() . '<br><br>'; // var_dump($e->getServerResponse()); (need more info?) }
delete()
方法只需要提供command
参数。
有关可用的API命令的完整列表,请参阅Active Collab API文档。