|
10 | 10 | namespace RetailCrm\Api\ResourceGroup;
|
11 | 11 |
|
12 | 12 | use RetailCrm\Api\Enum\RequestMethod;
|
| 13 | +use RetailCrm\Api\Exception\ApiException; |
| 14 | +use RetailCrm\Api\Exception\Client\HandlerException; |
| 15 | +use RetailCrm\Api\Exception\ClientException; |
| 16 | +use RetailCrm\Api\Interfaces\ApiExceptionInterface; |
| 17 | +use RetailCrm\Api\Model\Request\Tasks\TaskGetCommentsRequest; |
13 | 18 | use RetailCrm\Api\Model\Request\Tasks\TaskHistoryRequest;
|
14 | 19 | use RetailCrm\Api\Model\Request\Tasks\TasksCreateRequest;
|
15 | 20 | use RetailCrm\Api\Model\Request\Tasks\TasksRequest;
|
16 | 21 | use RetailCrm\Api\Model\Response\IdResponse;
|
17 | 22 | use RetailCrm\Api\Model\Response\SuccessResponse;
|
| 23 | +use RetailCrm\Api\Model\Response\Tasks\TaskGetCommentsResponse; |
18 | 24 | use RetailCrm\Api\Model\Response\Tasks\TasksGetResponse;
|
19 | 25 | use RetailCrm\Api\Model\Response\Tasks\TasksHistoryResponse;
|
20 | 26 | use RetailCrm\Api\Model\Response\Tasks\TasksResponse;
|
@@ -329,4 +335,60 @@ public function history(?TaskHistoryRequest $request = null): TasksHistoryRespon
|
329 | 335 |
|
330 | 336 | return $response;
|
331 | 337 | }
|
| 338 | + |
| 339 | + /** |
| 340 | + * Makes GET "/api/v5/tasks/{id}/comments" request. |
| 341 | + * |
| 342 | + * Example: |
| 343 | + * ```php |
| 344 | + * use RetailCrm\Api\Factory\SimpleClientFactory; |
| 345 | + * use RetailCrm\Api\Interfaces\ApiExceptionInterface; |
| 346 | + * use RetailCrm\Api\Model\Request\Tasks\TaskGetCommentsRequest; |
| 347 | + * |
| 348 | + * $client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey'); |
| 349 | + * |
| 350 | + * $request = new TaskGetCommentsRequest(); |
| 351 | + * $request->limit = 100; |
| 352 | + * $request->page = 1; |
| 353 | + * |
| 354 | + * try { |
| 355 | + * $response = $client->tasks->getComments(1, $request); |
| 356 | + * } catch (ApiExceptionInterface $exception) { |
| 357 | + * echo sprintf( |
| 358 | + * 'Error from RetailCRM API (status code: %d): %s', |
| 359 | + * $exception->getStatusCode(), |
| 360 | + * $exception->getMessage() |
| 361 | + * ); |
| 362 | + * |
| 363 | + * if (count($exception->getErrorResponse()->errors) > 0) { |
| 364 | + * echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors); |
| 365 | + * } |
| 366 | + * |
| 367 | + * return; |
| 368 | + * } |
| 369 | + * |
| 370 | + * echo 'Task: ' . print_r($response->task, true); |
| 371 | + * ``` |
| 372 | + * |
| 373 | + * @param int $id |
| 374 | + * @param TaskGetCommentsRequest $request |
| 375 | + * |
| 376 | + * @return TaskGetCommentsResponse |
| 377 | + * @throws ApiException |
| 378 | + * @throws ClientException |
| 379 | + * @throws HandlerException |
| 380 | + * @throws ApiExceptionInterface |
| 381 | + */ |
| 382 | + public function getComments(int $id, TaskGetCommentsRequest $request): TaskGetCommentsResponse |
| 383 | + { |
| 384 | + /** @var TaskGetCommentsResponse $response */ |
| 385 | + $response = $this->sendRequest( |
| 386 | + RequestMethod::GET, |
| 387 | + 'tasks/' . $id . '/comments', |
| 388 | + $request, |
| 389 | + TaskGetCommentsResponse::class |
| 390 | + ); |
| 391 | + |
| 392 | + return $response; |
| 393 | + } |
332 | 394 | }
|
0 commit comments