diff --git a/src/Model/Entity/Tasks/TaskComment.php b/src/Model/Entity/Tasks/TaskComment.php new file mode 100644 index 0000000..a394c10 --- /dev/null +++ b/src/Model/Entity/Tasks/TaskComment.php @@ -0,0 +1,29 @@ +") + * @JMS\SerializedName("createdAt") + */ + public $createdAt; + + /** + * @var bool + * + * @JMS\Type("bool") + * @JMS\SerializedName("created") + */ + public $created; + + /** + * @var string + * + * @JMS\Type("string") + * @JMS\SerializedName("source") + */ + public $source; + + /** + * @var \RetailCrm\Api\Model\Entity\HistoryUser + * + * @JMS\Type("RetailCrm\Api\Model\Entity\HistoryUser") + * @JMS\SerializedName("user") + */ + public $user; + + /** + * @var string + * + * @JMS\Type("string") + * @JMS\SerializedName("field") + */ + public $field; + + /** + * @var mixed + * + * @JMS\Type("mixed") + * @JMS\SerializedName("oldValue") + */ + public $oldValue; + + /** + * @var mixed + * + * @JMS\Type("mixed") + * @JMS\SerializedName("newValue") + */ + public $newValue; + + /** + * @var \RetailCrm\Api\Model\Entity\HistoryApiKey + * + * @JMS\Type("RetailCrm\Api\Model\Entity\HistoryApiKey") + * @JMS\SerializedName("apiKey") + */ + public $apiKey; + + /** + * @var \RetailCrm\Api\Model\Entity\Tasks\Task + * + * @JMS\Type("RetailCrm\Api\Model\Entity\Tasks\Task") + * @JMS\SerializedName("task") + */ + public $task; + + /** + * @var \RetailCrm\Api\Model\Entity\Tasks\TaskComment + * + * @JMS\Type("RetailCrm\Api\Model\Entity\Tasks\TaskComment") + * @JMS\SerializedName("comment") + */ + public $comment; +} diff --git a/src/Model/Filter/Tasks/TaskHistoryFilter.php b/src/Model/Filter/Tasks/TaskHistoryFilter.php new file mode 100644 index 0000000..4186fb4 --- /dev/null +++ b/src/Model/Filter/Tasks/TaskHistoryFilter.php @@ -0,0 +1,53 @@ +") + * @Form\SerializedName("startDate") + */ + public $startDate; + + /** + * @var DateTime|null + * + * @Form\Type("DateTime<'Y-m-d H:i:s'>") + * @Form\SerializedName("endDate") + */ + public $endDate; +} diff --git a/src/Model/Request/Tasks/TaskHistoryRequest.php b/src/Model/Request/Tasks/TaskHistoryRequest.php new file mode 100644 index 0000000..a9de66b --- /dev/null +++ b/src/Model/Request/Tasks/TaskHistoryRequest.php @@ -0,0 +1,28 @@ +") + * @JMS\SerializedName("generatedAt") + */ + public $generatedAt; + + /** + * @var \RetailCrm\Api\Model\Entity\Tasks\TaskHistory[] + * + * @JMS\Type("array") + * @JMS\SerializedName("history") + */ + public $history; +} diff --git a/src/ResourceGroup/Tasks.php b/src/ResourceGroup/Tasks.php index 0f0d21e..5d34bec 100644 --- a/src/ResourceGroup/Tasks.php +++ b/src/ResourceGroup/Tasks.php @@ -10,11 +10,13 @@ namespace RetailCrm\Api\ResourceGroup; use RetailCrm\Api\Enum\RequestMethod; +use RetailCrm\Api\Model\Request\Tasks\TaskHistoryRequest; use RetailCrm\Api\Model\Request\Tasks\TasksCreateRequest; use RetailCrm\Api\Model\Request\Tasks\TasksRequest; use RetailCrm\Api\Model\Response\IdResponse; use RetailCrm\Api\Model\Response\SuccessResponse; use RetailCrm\Api\Model\Response\Tasks\TasksGetResponse; +use RetailCrm\Api\Model\Response\Tasks\TasksHistoryResponse; use RetailCrm\Api\Model\Response\Tasks\TasksResponse; /** @@ -264,4 +266,66 @@ class Tasks extends AbstractApiResourceGroup ); return $response; } + + /** + * Makes GET "/api/v5/tasks/history" request. + * + * Example: + * ```php + * use RetailCrm\Api\Factory\SimpleClientFactory; + * use RetailCrm\Api\Interfaces\ApiExceptionInterface; + * use RetailCrm\Api\Model\Filter\Tasks\TaskHistoryFilter; + * use RetailCrm\Api\Model\Request\Tasks\TaskHistoryRequest; + * + * $client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey'); + * + * $request = new TaskHistoryRequest(); + * $request->limit = 100; + * $request->page = 1; + * $request->filter = new TaskHistoryFilter(); + * $request->filter->sinceId = 1111; + * + * try { + * $response = $client->tasks->history($request); + * } catch (ApiExceptionInterface $exception) { + * echo sprintf( + * 'Error from RetailCRM API (status code: %d): %s', + * $exception->getStatusCode(), + * $exception->getMessage() + * ); + * + * if (count($exception->getErrorResponse()->errors) > 0) { + * echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors); + * } + * + * return; + * } + * + * echo 'Tasks history: ' . print_r($response->history, true); + * ``` + * + * @param \RetailCrm\Api\Model\Request\Tasks\TaskHistoryRequest|null $request + * + * @return \RetailCrm\Api\Model\Response\Tasks\TasksHistoryResponse + * @throws \RetailCrm\Api\Interfaces\ApiExceptionInterface + * @throws \RetailCrm\Api\Interfaces\ClientExceptionInterface + * @throws \RetailCrm\Api\Exception\Api\AccountDoesNotExistException + * @throws \RetailCrm\Api\Exception\Api\ApiErrorException + * @throws \RetailCrm\Api\Exception\Api\MissingCredentialsException + * @throws \RetailCrm\Api\Exception\Api\MissingParameterException + * @throws \RetailCrm\Api\Exception\Api\ValidationException + * @throws \RetailCrm\Api\Exception\Client\HandlerException + * @throws \RetailCrm\Api\Exception\Client\HttpClientException + */ + public function history(?TaskHistoryRequest $request = null): TasksHistoryResponse + { + /** @var TasksHistoryResponse $response */ + $response = $this->sendRequest( + RequestMethod::GET, + 'tasks/history', + $request, + TasksHistoryResponse::class + ); + return $response; + } }