jamosaur/guzzle-toggl

基于 Guzzle PHP 编写的 Toggl API 客户端。由 AJT 分支。

v0.13 2015-10-22 17:02 UTC

This package is auto-updated.

Last update: 2024-09-22 20:23:03 UTC


README

基于 Guzzle PHP 的 Toggl API 客户端。由 AJT 分支。

功能

  • 支持完整版本 8 API,带有 API 密钥认证(感谢 @dirx)
  • 由于 Toggl 6 Api 将于 2013 年 9 月 1 日弃用,v0.8 版本中已移除。
  • 支持 Toggl Report Api v2(感谢 @dirx)

安装

此库通过 Composer 提供,因此很容易获取。只需运行以下命令即可安装

composer require jamosaur/guzzle-toggl

用法

要使用 Toggl API 客户端,只需使用 API 密钥实例化客户端。有关密钥和认证的更多信息,请参阅 https://github.com/toggl/toggl_api_docs/blob/master/chapters/authentication.md

<?php

require dirname(__FILE__).'/../vendor/autoload.php';

use Jamosaur\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 了解可用的方法和调用它们可用的参数的详细信息。

待办事项

  • 添加一些示例
  • 添加测试
  • 添加一些响应模型

欢迎贡献

发现错误,打开一个问题,最好附带调试输出和您所做的事情。错误修复?打开一个 Pull Request,我将查看它。

许可

Toggl API 客户端在 MIT 许可证下提供。