Skip to content

Commit af8a793

Browse files
authored
Add history method for tasks
2 parents fe18dce + a2d7035 commit af8a793

File tree

7 files changed

+373
-0
lines changed

7 files changed

+373
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/**
4+
* PHP version 7.3
5+
*
6+
* @category TaskComment
7+
* @package RetailCrm\Api\Model\Entity\Tasks
8+
*/
9+
10+
namespace RetailCrm\Api\Model\Entity\Tasks;
11+
12+
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
13+
14+
class TaskComment
15+
{
16+
/**
17+
* @var int
18+
*
19+
* @JMS\Type("int")
20+
* @JMS\SerializedName("id")
21+
*/
22+
public $id;
23+
24+
/**
25+
* @var string
26+
*
27+
* @JMS\Type("string")
28+
* @JMS\SerializedName("comment")
29+
*/
30+
public $comment;
31+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
3+
/**
4+
* PHP version 7.3
5+
*
6+
* @category TaskHistory
7+
* @package RetailCrm\Api\Model\Entity\Tasks
8+
*/
9+
10+
namespace RetailCrm\Api\Model\Entity\Tasks;
11+
12+
use DateTime;
13+
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
14+
15+
/**
16+
* Class TaskHistory
17+
*
18+
* @category TaskHistory
19+
* @package RetailCrm\Api\Model\Entity\Tasks
20+
*/
21+
class TaskHistory
22+
{
23+
/**
24+
* @var int
25+
*
26+
* @JMS\Type("int")
27+
* @JMS\SerializedName("id")
28+
*/
29+
public $id;
30+
31+
/**
32+
* @var DateTime
33+
*
34+
* @JMS\Type("DateTime<'Y-m-d H:i:s'>")
35+
* @JMS\SerializedName("createdAt")
36+
*/
37+
public $createdAt;
38+
39+
/**
40+
* @var bool
41+
*
42+
* @JMS\Type("bool")
43+
* @JMS\SerializedName("created")
44+
*/
45+
public $created;
46+
47+
/**
48+
* @var string
49+
*
50+
* @JMS\Type("string")
51+
* @JMS\SerializedName("source")
52+
*/
53+
public $source;
54+
55+
/**
56+
* @var \RetailCrm\Api\Model\Entity\HistoryUser
57+
*
58+
* @JMS\Type("RetailCrm\Api\Model\Entity\HistoryUser")
59+
* @JMS\SerializedName("user")
60+
*/
61+
public $user;
62+
63+
/**
64+
* @var string
65+
*
66+
* @JMS\Type("string")
67+
* @JMS\SerializedName("field")
68+
*/
69+
public $field;
70+
71+
/**
72+
* @var mixed
73+
*
74+
* @JMS\Type("mixed")
75+
* @JMS\SerializedName("oldValue")
76+
*/
77+
public $oldValue;
78+
79+
/**
80+
* @var mixed
81+
*
82+
* @JMS\Type("mixed")
83+
* @JMS\SerializedName("newValue")
84+
*/
85+
public $newValue;
86+
87+
/**
88+
* @var \RetailCrm\Api\Model\Entity\HistoryApiKey
89+
*
90+
* @JMS\Type("RetailCrm\Api\Model\Entity\HistoryApiKey")
91+
* @JMS\SerializedName("apiKey")
92+
*/
93+
public $apiKey;
94+
95+
/**
96+
* @var \RetailCrm\Api\Model\Entity\Tasks\Task
97+
*
98+
* @JMS\Type("RetailCrm\Api\Model\Entity\Tasks\Task")
99+
* @JMS\SerializedName("task")
100+
*/
101+
public $task;
102+
103+
/**
104+
* @var \RetailCrm\Api\Model\Entity\Tasks\TaskComment
105+
*
106+
* @JMS\Type("RetailCrm\Api\Model\Entity\Tasks\TaskComment")
107+
* @JMS\SerializedName("comment")
108+
*/
109+
public $comment;
110+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/**
4+
* PHP version 7.3
5+
*
6+
* @category TaskHistoryFilter
7+
* @package RetailCrm\Api\Model\Filter\Tasks
8+
*/
9+
10+
namespace RetailCrm\Api\Model\Filter\Tasks;
11+
12+
use DateTime;
13+
use RetailCrm\Api\Component\FormData\Mapping as Form;
14+
15+
/**
16+
* Class TaskHistoryFilter
17+
*
18+
* @category TaskHistoryFilter
19+
* @package RetailCrm\Api\Model\Filter\Tasks
20+
*/
21+
class TaskHistoryFilter
22+
{
23+
/**
24+
* @var int
25+
*
26+
* @Form\Type("int")
27+
* @Form\SerializedName("taskId")
28+
*/
29+
public $taskId;
30+
31+
/**
32+
* @var int
33+
*
34+
* @Form\Type("int")
35+
* @Form\SerializedName("sinceId")
36+
*/
37+
public $sinceId;
38+
39+
/**
40+
* @var DateTime|null
41+
*
42+
* @Form\Type("DateTime<'Y-m-d H:i:s'>")
43+
* @Form\SerializedName("startDate")
44+
*/
45+
public $startDate;
46+
47+
/**
48+
* @var DateTime|null
49+
*
50+
* @Form\Type("DateTime<'Y-m-d H:i:s'>")
51+
* @Form\SerializedName("endDate")
52+
*/
53+
public $endDate;
54+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/**
4+
* PHP version 7.3
5+
*
6+
* @category TaskHistoryRequest
7+
* @package RetailCrm\Api\Model\Request\Tasks
8+
*/
9+
10+
namespace RetailCrm\Api\Model\Request\Tasks;
11+
12+
use RetailCrm\Api\Interfaces\RequestInterface;
13+
use RetailCrm\Api\Model\Filter\Tasks\TaskHistoryFilter;
14+
use RetailCrm\Api\Model\Request\Traits\HistoryPageLimitTrait;
15+
use RetailCrm\Api\Component\FormData\Mapping as Form;
16+
17+
class TaskHistoryRequest implements RequestInterface
18+
{
19+
use HistoryPageLimitTrait;
20+
21+
/**
22+
* @var TaskHistoryFilter
23+
*
24+
* @Form\Type("RetailCrm\Api\Model\Filter\Tasks\TaskHistoryFilter")
25+
* @Form\SerializedName("filter")
26+
*/
27+
public $filter;
28+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/**
4+
* PHP version 7.3
5+
*
6+
* @category TasksHistoryResponse
7+
* @package RetailCrm\Api\Model\Response\Tasks
8+
*/
9+
10+
namespace RetailCrm\Api\Model\Response\Tasks;
11+
12+
use DateTime;
13+
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
14+
use RetailCrm\Api\Model\Response\AbstractPaginatedResponse;
15+
16+
class TasksHistoryResponse extends AbstractPaginatedResponse
17+
{
18+
/**
19+
* @var DateTime
20+
*
21+
* @JMS\Type("DateTime<'Y-m-d H:i:s'>")
22+
* @JMS\SerializedName("generatedAt")
23+
*/
24+
public $generatedAt;
25+
26+
/**
27+
* @var \RetailCrm\Api\Model\Entity\Tasks\TaskHistory[]
28+
*
29+
* @JMS\Type("array<RetailCrm\Api\Model\Entity\Tasks\TaskHistory>")
30+
* @JMS\SerializedName("history")
31+
*/
32+
public $history;
33+
}

src/ResourceGroup/Tasks.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
namespace RetailCrm\Api\ResourceGroup;
1111

1212
use RetailCrm\Api\Enum\RequestMethod;
13+
use RetailCrm\Api\Model\Request\Tasks\TaskHistoryRequest;
1314
use RetailCrm\Api\Model\Request\Tasks\TasksCreateRequest;
1415
use RetailCrm\Api\Model\Request\Tasks\TasksRequest;
1516
use RetailCrm\Api\Model\Response\IdResponse;
1617
use RetailCrm\Api\Model\Response\SuccessResponse;
1718
use RetailCrm\Api\Model\Response\Tasks\TasksGetResponse;
19+
use RetailCrm\Api\Model\Response\Tasks\TasksHistoryResponse;
1820
use RetailCrm\Api\Model\Response\Tasks\TasksResponse;
1921

2022
/**
@@ -264,4 +266,67 @@ public function edit(int $id, TasksCreateRequest $request): SuccessResponse
264266
);
265267
return $response;
266268
}
269+
270+
/**
271+
* Makes GET "/api/v5/tasks/history" request.
272+
*
273+
* Example:
274+
* ```php
275+
* use RetailCrm\Api\Factory\SimpleClientFactory;
276+
* use RetailCrm\Api\Interfaces\ApiExceptionInterface;
277+
* use RetailCrm\Api\Model\Filter\Tasks\TaskHistoryFilter;
278+
* use RetailCrm\Api\Model\Request\Tasks\TaskHistoryRequest;
279+
*
280+
* $client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
281+
*
282+
* $request = new TaskHistoryRequest();
283+
* $request->limit = 100;
284+
* $request->page = 1;
285+
* $request->filter = new TaskHistoryFilter();
286+
* $request->filter->sinceId = 1;
287+
*
288+
* try {
289+
* $response = $client->tasks->history($request);
290+
* } catch (ApiExceptionInterface $exception) {
291+
* echo sprintf(
292+
* 'Error from RetailCRM API (status code: %d): %s',
293+
* $exception->getStatusCode(),
294+
* $exception->getMessage()
295+
* );
296+
*
297+
* if (count($exception->getErrorResponse()->errors) > 0) {
298+
* echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
299+
* }
300+
*
301+
* return;
302+
* }
303+
*
304+
* echo 'Tasks history: ' . print_r($response->history, true);
305+
* ```
306+
*
307+
* @param \RetailCrm\Api\Model\Request\Tasks\TaskHistoryRequest|null $request
308+
*
309+
* @return \RetailCrm\Api\Model\Response\Tasks\TasksHistoryResponse
310+
* @throws \RetailCrm\Api\Interfaces\ApiExceptionInterface
311+
* @throws \RetailCrm\Api\Interfaces\ClientExceptionInterface
312+
* @throws \RetailCrm\Api\Exception\Api\AccountDoesNotExistException
313+
* @throws \RetailCrm\Api\Exception\Api\ApiErrorException
314+
* @throws \RetailCrm\Api\Exception\Api\MissingCredentialsException
315+
* @throws \RetailCrm\Api\Exception\Api\MissingParameterException
316+
* @throws \RetailCrm\Api\Exception\Api\ValidationException
317+
* @throws \RetailCrm\Api\Exception\Client\HandlerException
318+
* @throws \RetailCrm\Api\Exception\Client\HttpClientException
319+
*/
320+
public function history(?TaskHistoryRequest $request = null): TasksHistoryResponse
321+
{
322+
/** @var TasksHistoryResponse $response */
323+
$response = $this->sendRequest(
324+
RequestMethod::GET,
325+
'tasks/history',
326+
$request,
327+
TasksHistoryResponse::class
328+
);
329+
330+
return $response;
331+
}
267332
}

0 commit comments

Comments
 (0)