ember-devops / guzzle-toggl
基于 Guzzle PHP 的 Toggl API 客户端。
9.0.0
2024-06-21 03:16 UTC
Requires
- gimler/guzzle-description-loader: ^0.0.4
- guzzlehttp/guzzle: ^7.3
- guzzlehttp/guzzle-services: ^1.2
README
基于 Guzzle PHP 的 Toggl API 客户端
特性
- 支持部分版本 9 API,并使用 API Key 进行身份验证(感谢 @edward-simpson)
- 支持 Toggl Report Api v2(感谢 @dirx)
- 现在基于 guzzle 7
查看 v1.2.0 了解基于 guzzle6 的最后一个版本。目前这两个版本除了支持的 guzzle 版本不同之外,其他都相同。新版本将基于 guzzle7。
安装
该库通过 Composer 提供,因此获取它非常简单。只需运行以下命令即可安装:
composer require ember-devops/guzzle-toggl
用法
要使用 Toggl API 客户端,只需使用 API 密钥实例化客户端。有关密钥和身份验证的更多信息,请参阅 https://github.com/toggl/toggl_api_docs/blob/master/chapters/authentication.md
<?php require __DIR__.'/../vendor/autoload.php'; use AJT\Toggl\TogglClient; $toggl_token = ''; // Fill in your token here $toggl_client = TogglClient::factory(['api_key' => $toggl_token]); // if you want to see what is happening, add debug => true to the factory call $toggl_client = TogglClient::factory(['api_key' => $toggl_token, 'debug' => true]);
使用我们的 __call
方法调用命令(包括自动完成的 phpDocs)
<?php use AJT\Toggl\TogglClient; $toggl_client = TogglClient::factory(['api_key' => $toggl_token]); $workspaces = $toggl_client->getWorkspaces([]); foreach($workspaces as $workspace){ $id = $workspace['id']; print $workspace['name'] . "\n"; }
或者使用 getCommand
方法(在这种情况下,您需要处理 $response['data'] 数组)
<?php use AJT\Toggl\TogglClient; $toggl_client = TogglClient::factory(['api_key' => $toggl_token]); //Retrieve the Command from Guzzle $command = $toggl_client->getCommand('GetWorkspaces', []); $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 中查看可用的方法和调用它们的参数详细信息。
迁移到 v9
几乎所有的方法都保留了相同的命名,但一些参数已经更改。
以下端点现在需要在参数中传递 workspace_id
- CreateClient
- GetClient
- UpdateClient
- DeleteClient
- CreateProject
- GetProject
- UpdateProject
- CreateProjectUser
- CreateProjectUsers
- UpdateProjectUser
- UpdateProjectUsers
- DeleteProjectUser
- DeleteProjectUsers
- CreateTag
- UpdateTag
- DeleteTag
- CreateTask(还需要
project_id
) - GetTask(还需要
project_id
) - UpdateTask(还需要
project_id
) - UpdateTasks(还需要
project_id
) - DeleteTask(还需要
project_id
) - DeleteTasks(还需要
project_id
) - StartTimeEntry
- StopTimeEntry
- UpdateTimeEntry
- DeleteTimeEntry
以下端点现在需要在参数中传递 project_id
- CreateTask
- GetTask
- UpdateTask
- UpdateTasks
- DeleteTask
- DeleteTasks
以下端点是新的
- ArchiveClient
- RestoreClient
以下端点已更改其参数
- GetProjects(
id
现在是workspace_id
,以增强清晰度) - GetProjectUsers 不再接受
project_id
参数,而是接受workspace_id
参数
以下端点已更改名称,以更接近 toggl 文档
- InviteWorkspaceUser -> InviteOrganizationUser
以下端点已删除
- GetWorkspaceWorkspaceUsers
- GetWorkspaceProjects(使用 GetProjects 代替)
待办事项
- 添加更多示例
- 添加测试
- 添加一些 Response 模型
欢迎贡献力量
发现了一个错误,请创建一个 issue,最好附带调试输出和您所做的事情。修复错误?请提交一个 Pull Request,我会查看。
许可
Toggl API 客户端可在 MIT 许可证下获得。