Skip to content

Commit d195fae

Browse files
committed
nylas event conference
1 parent 94cbaf4 commit d195fae

File tree

1 file changed

+100
-38
lines changed

1 file changed

+100
-38
lines changed

src/Events/Event.php

+100-38
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* @see https://docs.nylas.com/reference#event-limitations
1616
*
1717
* @author lanlin
18-
* @change 2020/09/30
18+
* @change 2021/07/15
1919
*/
2020
class Event
2121
{
@@ -268,6 +268,37 @@ public function deleteEvent(array $params): array
268268

269269
// ------------------------------------------------------------------------------
270270

271+
/**
272+
* rules for add event
273+
*
274+
* @return \Nylas\Utilities\Validator
275+
*/
276+
private function addEventRules(): V
277+
{
278+
return V::keySet(
279+
V::key('when', $this->timeRules()),
280+
...$this->getEventBaseRules(),
281+
);
282+
}
283+
284+
// ------------------------------------------------------------------------------
285+
286+
/**
287+
* rules for update event
288+
*
289+
* @return \Nylas\Utilities\Validator
290+
*/
291+
private function updateEventRules(): V
292+
{
293+
return V::keySet(
294+
V::key('id', V::stringType()->notEmpty()),
295+
V::keyOptional('when', $this->timeRules()),
296+
...$this->getEventBaseRules(),
297+
);
298+
}
299+
300+
// ------------------------------------------------------------------------------
301+
271302
/**
272303
* event base validate rules
273304
*
@@ -298,54 +329,37 @@ private function getBaseRules(): array
298329
// ------------------------------------------------------------------------------
299330

300331
/**
301-
* rules for update event
332+
* get event base rules
302333
*
303-
* @return \Nylas\Utilities\Validator
334+
* @return array
304335
*/
305-
private function updateEventRules(): V
336+
private function getEventBaseRules(): array
306337
{
307-
return V::keySet(
308-
V::key('id', V::stringType()->notEmpty()),
309-
V::keyOptional('when', $this->timeRules()),
310-
V::keyOptional('busy', V::boolType()),
311-
V::keyOptional('title', V::stringType()->notEmpty()),
312-
V::keyOptional('location', V::stringType()->notEmpty()),
313-
V::keyOptional('description', V::stringType()->notEmpty()),
314-
V::keyOptional('notify_participants', V::boolType()),
315-
V::keyOptional('participants', V::simpleArray(V::keySet(
316-
V::key('email', V::email()),
317-
V::key('status', V::stringType()),
318-
V::key('name', V::stringType()),
319-
V::key('comment', V::stringType())
320-
)))
338+
$recurrenceRule = V::keySet(
339+
V::key('rrule', V::simpleArray()),
340+
V::key('timezone', V::stringType()),
321341
);
322-
}
323342

324-
// ------------------------------------------------------------------------------
343+
$participantsRule = V::simpleArray(V::keySet(
344+
V::key('email', V::email()),
345+
V::keyOptional('name', V::stringType()),
346+
V::keyOptional('status', V::in(['yes', 'no', 'maybe', 'noreply'])),
347+
V::keyOptional('comment', V::stringType())
348+
));
325349

326-
/**
327-
* rules for add event
328-
*
329-
* @return \Nylas\Utilities\Validator
330-
*/
331-
private function addEventRules(): V
332-
{
333-
return V::keySet(
334-
V::key('when', $this->timeRules()),
350+
return
351+
[
335352
V::key('calendar_id', V::stringType()->notEmpty()),
336353
V::keyOptional('busy', V::boolType()),
354+
V::keyOptional('read_only', V::boolType()),
337355
V::keyOptional('title', V::stringType()->notEmpty()),
338356
V::keyOptional('location', V::stringType()->notEmpty()),
339-
V::keyOptional('recurrence', V::arrayType()),
357+
V::keyOptional('recurrence', $recurrenceRule),
340358
V::keyOptional('description', V::stringType()->notEmpty()),
359+
V::keyOptional('participants', $participantsRule),
360+
V::keyOptional('conferencing', $this->conferenceRules()),
341361
V::keyOptional('notify_participants', V::boolType()),
342-
V::keyOptional('participants', V::simpleArray(V::keySet(
343-
V::key('email', V::email()),
344-
V::key('status', V::stringType()),
345-
V::key('name', V::stringType()),
346-
V::key('comment', V::stringType())
347-
)))
348-
);
362+
];
349363
}
350364

351365
// ------------------------------------------------------------------------------
@@ -359,7 +373,7 @@ private function timeRules(): V
359373
{
360374
return V::anyOf(
361375

362-
// time
376+
// time
363377
V::keySet(V::key('time', V::timestampType())),
364378

365379
// date
@@ -380,4 +394,52 @@ private function timeRules(): V
380394
}
381395

382396
// ------------------------------------------------------------------------------
397+
398+
/**
399+
* get event conference rules
400+
*
401+
* @return \Nylas\Utilities\Validator
402+
*/
403+
private function conferenceRules(): V
404+
{
405+
$webEx = V::keySet(
406+
V::key('provider', V::equals('WebEx')),
407+
V::key('details', V::keySet(
408+
V::key('password', V::stringType()),
409+
V::key('pin', V::stringType()),
410+
V::key('url', V::stringType())
411+
))
412+
);
413+
414+
$zoomMeeting = V::keySet(
415+
V::key('provider', V::equals('Zoom Meeting')),
416+
V::key('details', V::keySet(
417+
V::key('meeting_code', V::stringType()),
418+
V::key('password', V::stringType()),
419+
V::key('url', V::stringType()),
420+
))
421+
);
422+
423+
$goToMeeting = V::keySet(
424+
V::key('provider', V::equals('GoToMeeting')),
425+
V::key('details', V::keySet(
426+
V::key('meeting_code', V::stringType()),
427+
V::key('phone', V::simpleArray()),
428+
V::key('url', V::stringType()),
429+
))
430+
);
431+
432+
$googleMeet = V::keySet(
433+
V::key('provider', V::equals('Google Meet')),
434+
V::key('details', V::keySet(
435+
V::key('phone', V::simpleArray()),
436+
V::key('pin', V::stringType()),
437+
V::key('url', V::stringType()),
438+
))
439+
);
440+
441+
return V::oneOf($webEx, $zoomMeeting, $goToMeeting, $googleMeet);
442+
}
443+
444+
// ------------------------------------------------------------------------------
383445
}

0 commit comments

Comments
 (0)