Skip to content

Commit

Permalink
nylas event conference
Browse files Browse the repository at this point in the history
  • Loading branch information
lanlin committed Jul 15, 2021
1 parent 94cbaf4 commit d195fae
Showing 1 changed file with 100 additions and 38 deletions.
138 changes: 100 additions & 38 deletions src/Events/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @see https://docs.nylas.com/reference#event-limitations
*
* @author lanlin
* @change 2020/09/30
* @change 2021/07/15
*/
class Event
{
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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())
)))
);
];
}

// ------------------------------------------------------------------------------
Expand All @@ -359,7 +373,7 @@ private function timeRules(): V
{
return V::anyOf(

// time
// time
V::keySet(V::key('time', V::timestampType())),

// date
Expand All @@ -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);
}

// ------------------------------------------------------------------------------
}

0 comments on commit d195fae

Please sign in to comment.