From d195faeeb792fdcb3175e6afdf1950a0cfdb1446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=B0=E6=9E=97?= Date: Thu, 15 Jul 2021 11:20:11 +0800 Subject: [PATCH] nylas event conference --- src/Events/Event.php | 138 +++++++++++++++++++++++++++++++------------ 1 file changed, 100 insertions(+), 38 deletions(-) diff --git a/src/Events/Event.php b/src/Events/Event.php index c61eac2..4adfbfa 100644 --- a/src/Events/Event.php +++ b/src/Events/Event.php @@ -15,7 +15,7 @@ * @see https://docs.nylas.com/reference#event-limitations * * @author lanlin - * @change 2020/09/30 + * @change 2021/07/15 */ class Event { @@ -268,6 +268,37 @@ public function deleteEvent(array $params): array // ------------------------------------------------------------------------------ + /** + * rules for add event + * + * @return \Nylas\Utilities\Validator + */ + private function addEventRules(): V + { + return V::keySet( + V::key('when', $this->timeRules()), + ...$this->getEventBaseRules(), + ); + } + + // ------------------------------------------------------------------------------ + + /** + * rules for update event + * + * @return \Nylas\Utilities\Validator + */ + private function updateEventRules(): V + { + return V::keySet( + V::key('id', V::stringType()->notEmpty()), + V::keyOptional('when', $this->timeRules()), + ...$this->getEventBaseRules(), + ); + } + + // ------------------------------------------------------------------------------ + /** * event base validate rules * @@ -298,54 +329,37 @@ private function getBaseRules(): array // ------------------------------------------------------------------------------ /** - * rules for update event + * get event base rules * - * @return \Nylas\Utilities\Validator + * @return array */ - private function updateEventRules(): V + private function getEventBaseRules(): array { - return V::keySet( - V::key('id', V::stringType()->notEmpty()), - V::keyOptional('when', $this->timeRules()), - V::keyOptional('busy', V::boolType()), - V::keyOptional('title', V::stringType()->notEmpty()), - V::keyOptional('location', V::stringType()->notEmpty()), - V::keyOptional('description', V::stringType()->notEmpty()), - V::keyOptional('notify_participants', V::boolType()), - V::keyOptional('participants', V::simpleArray(V::keySet( - V::key('email', V::email()), - V::key('status', V::stringType()), - V::key('name', V::stringType()), - V::key('comment', V::stringType()) - ))) + $recurrenceRule = V::keySet( + V::key('rrule', V::simpleArray()), + V::key('timezone', V::stringType()), ); - } - // ------------------------------------------------------------------------------ + $participantsRule = V::simpleArray(V::keySet( + V::key('email', V::email()), + V::keyOptional('name', V::stringType()), + V::keyOptional('status', V::in(['yes', 'no', 'maybe', 'noreply'])), + V::keyOptional('comment', V::stringType()) + )); - /** - * rules for add event - * - * @return \Nylas\Utilities\Validator - */ - private function addEventRules(): V - { - return V::keySet( - V::key('when', $this->timeRules()), + return + [ V::key('calendar_id', V::stringType()->notEmpty()), V::keyOptional('busy', V::boolType()), + V::keyOptional('read_only', V::boolType()), V::keyOptional('title', V::stringType()->notEmpty()), V::keyOptional('location', V::stringType()->notEmpty()), - V::keyOptional('recurrence', V::arrayType()), + V::keyOptional('recurrence', $recurrenceRule), V::keyOptional('description', V::stringType()->notEmpty()), + V::keyOptional('participants', $participantsRule), + V::keyOptional('conferencing', $this->conferenceRules()), V::keyOptional('notify_participants', V::boolType()), - V::keyOptional('participants', V::simpleArray(V::keySet( - V::key('email', V::email()), - V::key('status', V::stringType()), - V::key('name', V::stringType()), - V::key('comment', V::stringType()) - ))) - ); + ]; } // ------------------------------------------------------------------------------ @@ -359,7 +373,7 @@ private function timeRules(): V { return V::anyOf( - // time + // time V::keySet(V::key('time', V::timestampType())), // date @@ -380,4 +394,52 @@ private function timeRules(): V } // ------------------------------------------------------------------------------ + + /** + * get event conference rules + * + * @return \Nylas\Utilities\Validator + */ + private function conferenceRules(): V + { + $webEx = V::keySet( + V::key('provider', V::equals('WebEx')), + V::key('details', V::keySet( + V::key('password', V::stringType()), + V::key('pin', V::stringType()), + V::key('url', V::stringType()) + )) + ); + + $zoomMeeting = V::keySet( + V::key('provider', V::equals('Zoom Meeting')), + V::key('details', V::keySet( + V::key('meeting_code', V::stringType()), + V::key('password', V::stringType()), + V::key('url', V::stringType()), + )) + ); + + $goToMeeting = V::keySet( + V::key('provider', V::equals('GoToMeeting')), + V::key('details', V::keySet( + V::key('meeting_code', V::stringType()), + V::key('phone', V::simpleArray()), + V::key('url', V::stringType()), + )) + ); + + $googleMeet = V::keySet( + V::key('provider', V::equals('Google Meet')), + V::key('details', V::keySet( + V::key('phone', V::simpleArray()), + V::key('pin', V::stringType()), + V::key('url', V::stringType()), + )) + ); + + return V::oneOf($webEx, $zoomMeeting, $goToMeeting, $googleMeet); + } + + // ------------------------------------------------------------------------------ }