noobj / guzzle-toggl
基于 Guzzle PHP 的 Toggl API 客户端。
v1.0.2
2019-02-01 14:54 UTC
Requires
- gimler/guzzle-description-loader: ^0.0.4
- guzzlehttp/guzzle: ^6.2
- guzzlehttp/guzzle-services: ^1.1
README
基于 Guzzle PHP 的 Toggl API 客户端
特性
- 支持完整版 8 API,并使用 API Key 进行认证(感谢 @dirx)
- 支持 Toggl Report Api v2(感谢 @dirx)
- 现在基于 guzzle 6(感谢 @echron)
安装
该库通过 Composer 提供,因此很容易获取。只需运行以下命令即可安装:
composer require ajt/guzzle-toggl
用法
要使用 Toggl API 客户端,只需使用 api key 创建客户端实例。有关键和认证的更多信息,请参阅 https://github.com/toggl/toggl_api_docs/blob/master/chapters/authentication.md
<?php require dirname(__FILE__).'/../vendor/autoload.php'; use AJT\Toggl\TogglClient; $toggl_token = ''; // Fill in your token here $toggl_client = TogglClient::factory(array('api_key' => $toggl_token)); // if you want to see what is happening, add debug => true to the factory call $toggl_client = TogglClient::factory(array('api_key' => $toggl_token, 'debug' => true));
使用我们的 __call 方法调用命令(包括自动完成 phpDocs)
<?php $toggl_client = TogglClient::factory(array('api_key' => $toggl_token)); $workspaces = $toggl_client->getWorkspaces(array()); foreach($workspaces as $workspace){ $id = $workspace['id']; print $workspace['name'] . "\n"; }
或者使用 getCommand 方法(在这种情况下,您需要与 $response['data'] 数组一起工作)
<?php $toggl_client = TogglClient::factory(array('api_key' => $toggl_token)); //Retrieve the Command from Guzzle $command = $toggl_client->getCommand('GetWorkspaces', array()); $command->prepare(); $response = $command->execute(); $workspaces = $response['data']; foreach($workspaces as $workspace){ $id = $workspace['id']; print $workspace['name'] . "\n"; }
示例
将 apikey-dist.php 复制到 apikey.php(在根目录中),并添加您的 apikey。之后,您可以在 examples 目录中执行示例。
您可以通过 services.json 了解可用的方法和调用它们所需的参数
待办事项
- 添加更多示例
- 添加测试
- 添加一些响应模型
欢迎贡献
发现错误,请提交问题,最好附带调试输出和您所做操作。修复错误?请提交拉取请求,我会查看。
许可证
Toggl API 客户端可在 MIT 许可证下使用。