ixudra / toggl
连接Toggl API的自定义PHP库 - 由Ixudra开发
Requires
- php: >=5.6.0
- ixudra/curl: ~6.0
- nesbot/carbon: >=1.19
Suggests
- illuminate/support: Support for laravel using the TogglServiceProvider
README
连接Toggl API的自定义PHP库 - 由Ixudra开发。
此包任何人任何时候都可以使用,但请注意,它是针对我个人的定制工作流程进行优化的。它可能不适合您的项目,可能需要进行修改。
安装
通过Composer拉取此包。
{ 'require': { 'ixudra/toggl': '2.*' } }
重要:此包支持Toggle API的最新版本(v9)。如果您想使用即将被弃用的API v8,请拉取版本
1.2.0
。
Laravel集成
Laravel 5.5+
自动包发现将负责注册服务提供者和外观。
Laravel < 5.5
将服务提供者添加到您的 config/app.php
文件
'providers' => array( //... Ixudra\Toggl\TogglServiceProvider::class, ),
将外观添加到您的 config/app.php
文件
'aliases' => array( //... 'Toggl' => Ixudra\Toggl\Facades\Toggl::class, ),
配置
将工作空间ID和您的个人API令牌添加到您的 .env
文件
TOGGL_WORKSPACE=123
TOGGL_TOKEN=your_toggl_api_token
将以下行代码添加到您的 config/services.php
文件
'toggl' => [ 'workspace' => env('TOGGL_WORKSPACE'), 'token' => env('TOGGL_TOKEN'), ],
配置文件中的凭据将用作包的默认值。如果您出于任何原因想使用不同的工作空间ID和/或API令牌,您可以使用两个实用方法。您可以根据个人需求使用任意一个、不使用或同时使用这两个方法。
// Sets the workspace ID to a new value Toggl::setWorkspaceId( 456 ); // Sets the API token to a new value Toggl::setApiToken( 'second_toggl_api_token' ); $response = Toggl::createClient( array( 'name' => 'Test company' ) );
请注意,工作空间ID和API令牌存储在服务配置中。这意味着一旦更新了这些值之一,在下一次请求完成后,它不会回到默认值。它将保持新的值,直到使用相同的实用方法将其重置为原始值。
Lumen 5.*集成
在您的 bootstrap/app.php
中,确保您已取消注释以下行(大约在第26行)
$app->withFacades();
然后,注册您的类别名
class_alias('Ixudra\Toggl\Facades\Toggl', 'Toggl');
最后,您必须注册您的ServiceProvider(大约在第70-80行)
/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
|
| Here we will register all of the application's service providers which
| are used to bind services into the container. Service providers are
| totally optional, so you are not required to uncomment this line.
|
*/
// $app->register('App\Providers\AppServiceProvider');
// Package service providers
$app->register(Ixudra\Toggl\TogglServiceProvider::class);
没有Laravel的集成
在您想使用此包的地方创建一个新的 TogglService
实例
$workspaceId = 123; $apiToken = 'your_toggl_api_token'; $togglService = new \Ixudra\Toggl\TogglService( $workspaceId, $apiToken );
用法
此包提供了一个易于使用的接口来向Toggl API发送请求。有关API的完整信息、所有可用方法和所有可能的参数,请参阅GitHub上的官方Toggl API文档。该包提供了(几乎)与API文档中描述的所有函数完全匹配的(几乎)所有函数。确切的功能定义可以在 src/Traits
目录中找到。
为了方便起见,该包将自动添加几个必需参数,因此您不必担心这样做。这些参数包括工作空间ID和API令牌。这些参数不应包含在任何请求中。此外,该包还提供了一些针对Laravel使用和未使用Laravel使用的实用方法。
Laravel使用
// Return an overview of what users in the workspace are doing and have been doing $response = Toggl::dashboard(); // Create a client $response = Toggl::createClient( array( 'name' => 'Test company' ) ); // Get a summary information of this month for all user $response = Toggl::summaryThisMonth(); // Get a summary information of last month for one specific user $response = Toggl::summaryLastMonth( array( 'user_ids' => '123' ) );
非Laravel使用
$workspaceId = 123; $apiToken = 'your_toggl_api_token'; $togglService = new \Ixudra\Toggl\TogglService( $workspaceId, $apiToken ); // Return an overview of what users in the workspace are doing and have been doing $response = $togglService->dashboard(); // Create a client $response = $togglService->createClient( array( 'name' => 'Test company' ) ); // Get a summary information of this month for all user $response = $togglService->summaryThisMonth(); // Get a summary information of last month for one specific user $response = $togglService->summaryLastMonth( array( 'user_ids' => '123' ) );
计划
- 添加缺少的API方法
- 提高现有API方法的可用性
- 添加额外的便捷方法
- 更新和改进文档
- 支持多个工作空间
支持
通过Patreon支持我,以帮助我进一步开发和维护此包!!
许可证
本软件包是开源软件,根据MIT许可证授权。
联系方式
关于软件包的问题、错误、建议和/或功能请求,请使用GitHub问题系统并/或提交一个拉取请求。提交问题时,请始终提供详细的问题说明、收到的任何响应或反馈、可能相关的日志消息以及演示问题的源代码示例。否则,我可能无法帮助您解决问题。在提交问题或拉取请求之前,请先查看贡献指南。
对于任何其他问题,请自由使用以下提供的凭据
Jan Oris(开发者)
- 邮箱:jan.oris@ixudra.be
- 电话:+32 496 94 20 57