-
Notifications
You must be signed in to change notification settings - Fork 3
/
TaskEndpoint.php
55 lines (43 loc) · 1.42 KB
/
TaskEndpoint.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/*
* This file is part of the Freshheads Harvest API Client library.
*
* (c) Freshheads B.V. <info@freshheads.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace FH\HarvestApiClient\Endpoint;
use FH\HarvestApiClient\Client\Client;
use FH\HarvestApiClient\Model\Task\Task;
use FH\HarvestApiClient\Model\Task\TaskCollection;
use JMS\Serializer\Serializer;
final class TaskEndpoint
{
private $client;
private $serializer;
public function __construct(Client $client, Serializer $serializer)
{
$this->client = $client;
$this->serializer = $serializer;
}
/**
* @link https://help.getharvest.com/api-v2/tasks-api/tasks/tasks/#list-all-tasks
*/
public function list(array $parameters = []): TaskCollection
{
$response = $this->client->get('/tasks', $parameters);
$data = $response->getBody()->getContents();
return $this->serializer->deserialize($data, TaskCollection::class, 'json');
}
/**
* @link https://help.getharvest.com/api-v2/tasks-api/tasks/tasks/#retrieve-a-task
*/
public function retrieve(int $id): ?Task
{
$response = $this->client->get("/tasks/{$id}");
$data = $response->getBody()->getContents();
return $this->serializer->deserialize($data, Task::class, 'json');
}
}