ingress-it-solutions / palzin-sdk
这是一个简单的PHP库,可以轻松实现与Palzin API的通信
dev-master
2019-02-12 06:30 UTC
Requires
- php: >=5.6.0
- ext-curl: *
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-12 19:24:47 UTC
README
这是一个简单的PHP库,可以轻松实现与Palzin API的通信。
安装
如果您选择使用Composer而不是从Git仓库拉取来安装此应用程序,您需要将一个composer.json文件添加到您想要拉取仓库的位置,并包含以下内容
{ "require": { "ingress-it-solutions/palzin-sdk": "^3.0" } }
运行composer update
来安装此包。
注意:如果您使用的是较旧的Palzin API包装器版本,并使用dev-master
加载它,请将其锁定到版本2.0,通过设置require语句为^2.0
并调用composer update
。
连接到Palzin账户
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 Palzin is installed. $authenticator = new \Palzin\SDK\Authenticator\PalzinAuthenticator('ACME Inc', 'My Awesome Application', 'you@acmeinc.com', 'hard to guess, easy to remember', 'https://my.company.com/projects'); //SSL problems? //If curl complains that SSL peer verification has failed, you can turn it off like this: $authenticator->setSslVerifyPeer(false); // Issue a token. $token = $authenticator->issueToken(); // Did we get what we asked for? if ($token instanceof \Palzin\SDK\TokenInterface) { print $token->getUrl() . "\n"; print $token->getToken() . "\n"; } else { print "Invalid response\n"; die(); }
构造客户端实例
一旦我们有了令牌,我们就可以构造一个客户端并执行API调用
$client = new \Palzin\SDK\Client($token); //SSL problems? //If curl complains that SSL peer verification has failed, you can turn it off like this: $client->setSslVerifyPeer(false);
列出项目#65中的所有任务很简单。只需调用
$client->get('projects/65/tasks');
要创建任务,只需发送一个POST请求
try { $client->post('projects/6/tasks', [ 'name' => 'This is a task name', 'assignee_id' => 4 ]); } catch(AppException $e) { print $e->getMessage() . '<br><br>'; // var_dump($e->getServerResponse()); (need more info?) }
要更新任务,需要使用PUT请求
try { $client->put('projects/5/tasks/16', [ '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/5/tasks/16'); } catch(AppException $e) { print $e->getMessage() . '<br><br>'; // var_dump($e->getServerResponse()); (need more info?) }
仅需要提供command
参数的delete()
方法。
有关可用API命令的完整列表,请查阅support@ingressit.com