Skip to content

Commit

Permalink
Merge pull request #18 from Morning-Train/feature/v9-update
Browse files Browse the repository at this point in the history
✨ Update endpoints to use v9 and include workspace grouping
  • Loading branch information
SimonJnsson authored Oct 11, 2023
2 parents f907585 + f3caf8c commit 9f96d97
Showing 1 changed file with 49 additions and 17 deletions.
66 changes: 49 additions & 17 deletions src/TogglApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,22 @@ class TogglApi
* @var \GuzzleHttp\Client
*/
protected $client;
/**
* @var mixed
*/
private $workspaceId;

/**
* TogglApi constructor.
*
* @param string $apiToken
*/
public function __construct($apiToken)
public function __construct($apiToken, $workspaceId)
{
$this->apiToken = $apiToken;
$this->workspaceId = $workspaceId;
$this->client = new Client([
'base_uri' => 'https://api.track.toggl.com/api/v8/',
'base_uri' => 'https://api.track.toggl.com/api/v9/',
'auth' => [$this->apiToken, 'api_token'],
]);
}
Expand Down Expand Up @@ -66,7 +71,7 @@ public function getAvailableEndpoints()
*/
public function createClient($client)
{
return $this->POST('clients', ['client' => $client]);
return $this->POST("workspaces/{$this->workspaceId}/clients", ['client' => $client]);
}

/**
Expand Down Expand Up @@ -161,7 +166,7 @@ public function getAllClientProjects($clientId)
*/
public function getClientById($clientId)
{
return $this->GET('clients/'.$clientId);
return $this->GET("workspaces/{$this->workspaceId}/clients/{$clientId}");
}

/**
Expand Down Expand Up @@ -350,7 +355,7 @@ public function deleteProjectGroups($projectGroupIds)
*/
public function createProject($project)
{
return $this->POST('projects', ['project' => $project]);
return $this->POST("workspaces/{$this->workspaceId}/projects", ['project' => $project]);
}

/**
Expand All @@ -363,7 +368,7 @@ public function createProject($project)
*/
public function updateProject($projectId, $project)
{
return $this->PUT('projects/'.$projectId, ['project' => $project]);
return $this->PUT("workspaces/{$this->workspaceId}/projects/{$projectId}", ['project' => $project]);
}

/**
Expand Down Expand Up @@ -435,7 +440,7 @@ public function getProjectTasks($projectId)
*/
public function getProject($projectId)
{
return $this->GET('projects/'.$projectId);
return $this->GET("workspaces/{$this->workspaceId}/projects/{$projectId}");
}

/**
Expand Down Expand Up @@ -618,14 +623,39 @@ public function getWorkspaceClients($wid)
/**
* Get workspace projects.
*
* @param int $wid
* @param int $workspaceId
* @param array $options
*
* @return bool|mixed|object
*/
public function getWorkspaceProjects($workspaceId, $options = [])
{
return $this->GET("workspaces/{$workspaceId}/projects", $options);
}

/**
* Get projects.
*
* @param array $options
*
* @return bool|mixed|object
*/
public function getProjects($options = [])
{
return $this->GET("workspaces/{$this->workspaceId}/projects", $options);
}

/**
* Get projects.
*
* @param int $workspaceId
* @param array $options
*
* @return bool|mixed|object
*/
public function getWorkspaceProjects($wid, $options = [])
public function getProjects($options = [])
{
return $this->GET('workspaces/'.$wid.'/projects', $options);
return $this->GET("workspaces/{$this->workspaceId}/projects", $options);
}

/**
Expand Down Expand Up @@ -785,9 +815,9 @@ public function deleteTag($tagId)
*
* @see https://github.com/toggl/toggl_api_docs/blob/master/chapters/tasks.md
*/
public function getTask($taskId)
public function getTask($projectId, $taskId)
{
return $this->GET('tasks/'.$taskId);
return $this->GET("workspaces/{$this->workspaceId}/projects/{$projectId}/tasks/{$taskId}");
}

/**
Expand All @@ -797,9 +827,9 @@ public function getTask($taskId)
*
* @return bool|mixed|object
*/
public function createTask($task)
public function createTask($projectId, $task)
{
return $this->POST('tasks', ['task' => $task]);
return $this->POST("workspaces/{$this->workspaceId}/projects/{$projectId}/tasks", ['task' => $task]);
}

/**
Expand All @@ -810,9 +840,11 @@ public function createTask($task)
*
* @return bool|mixed|object
*/
public function updateTask($taskId, $task)
public function updateTask($projectId, $taskId, $task)
{
return $this->PUT('tasks/'.$taskId, ['task' => $task]);
return $this->PUT("workspaces/{$this->workspaceId}/projects/{$projectId}/tasks/{$taskId}", [
'task' => $task,
]);
}

/**
Expand All @@ -837,7 +869,7 @@ public function updateTasks($taskIds, $task)
*/
public function deleteTask($taskId)
{
return $this->DELETE('tasks/'.$taskId);
return $this->DELETE("workspaces/{$this->workspaceId}/tasks/{$taskId}");
}

/**
Expand Down

0 comments on commit 9f96d97

Please sign in to comment.