From ff1e349b31a3dda6c3120d364fdb88304aa69fcd Mon Sep 17 00:00:00 2001 From: MaksimKutishchev Date: Mon, 2 Sep 2024 22:44:54 +0400 Subject: [PATCH] Feature: add event types --- src/AmoCRM/Client/AmoCRMApiClient.php | 14 +++ .../Collections/EventTypesCollections.php | 28 +++++ src/AmoCRM/EntitiesServices/EventTypes.php | 107 ++++++++++++++++++ src/AmoCRM/Helpers/EntityTypesInterface.php | 1 + src/AmoCRM/Models/EventTypeModel.php | 83 ++++++++++++++ 5 files changed, 233 insertions(+) create mode 100644 src/AmoCRM/Collections/EventTypesCollections.php create mode 100644 src/AmoCRM/EntitiesServices/EventTypes.php create mode 100644 src/AmoCRM/Models/EventTypeModel.php diff --git a/src/AmoCRM/Client/AmoCRMApiClient.php b/src/AmoCRM/Client/AmoCRMApiClient.php index dfe9e91..0b03d96 100644 --- a/src/AmoCRM/Client/AmoCRMApiClient.php +++ b/src/AmoCRM/Client/AmoCRMApiClient.php @@ -18,6 +18,7 @@ use AmoCRM\EntitiesServices\CustomFields; use AmoCRM\EntitiesServices\EntityFiles; use AmoCRM\EntitiesServices\EntityNotes; +use AmoCRM\EntitiesServices\EventTypes; use AmoCRM\EntitiesServices\Files; use AmoCRM\EntitiesServices\Sources; use AmoCRM\EntitiesServices\EntitySubscriptions; @@ -565,6 +566,19 @@ public function events(): Events return new Events($request); } + /** + * Метод вернет объект событий + * + * @return EventTypes + * @throws AmoCRMMissedTokenException + */ + public function eventTypes(): EventTypes + { + $request = $this->buildRequest(); + + return new EventTypes($request); + } + /** * Метод вернет объект хуков * diff --git a/src/AmoCRM/Collections/EventTypesCollections.php b/src/AmoCRM/Collections/EventTypesCollections.php new file mode 100644 index 0000000..1db8513 --- /dev/null +++ b/src/AmoCRM/Collections/EventTypesCollections.php @@ -0,0 +1,28 @@ +key; + } + + public function setKey(string $key): EventTypeModel + { + $this->key = $key; + + return $this; + } + + public function getType(): int + { + return $this->type; + } + + public function setType(int $type): EventTypeModel + { + $this->type = $type; + + return $this; + } + + public function getLang(): string + { + return $this->lang; + } + + public function setLang(string $lang): EventTypeModel + { + $this->lang = $lang; + + return $this; + } + + public static function fromArray(array $eventType): EventTypeModel + { + if (empty($eventType['key'])) { + throw new InvalidArgumentException('EventType key is empty in ' . \json_encode($eventType, JSON_THROW_ON_ERROR)); + } + + $eventTypeModel = new static(); + + $eventTypeModel->setKey($eventType['key']) + ->setType($eventType['type']) + ->setLang($eventType['lang']); + + return $eventTypeModel; + } + + /** + * @inheritDoc + */ + public function toArray(): array + { + return [ + 'key' => $this->getKey(), + 'type' => $this->getType(), + 'lang' => $this->getLang(), + ]; + } + + public function toApi(?string $requestId = "0"): array + { + return []; + } +}