15
15
* @see https://docs.nylas.com/reference#event-limitations
16
16
*
17
17
* @author lanlin
18
- * @change 2020/09/30
18
+ * @change 2021/07/15
19
19
*/
20
20
class Event
21
21
{
@@ -268,6 +268,37 @@ public function deleteEvent(array $params): array
268
268
269
269
// ------------------------------------------------------------------------------
270
270
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
+
271
302
/**
272
303
* event base validate rules
273
304
*
@@ -298,54 +329,37 @@ private function getBaseRules(): array
298
329
// ------------------------------------------------------------------------------
299
330
300
331
/**
301
- * rules for update event
332
+ * get event base rules
302
333
*
303
- * @return \Nylas\Utilities\Validator
334
+ * @return array
304
335
*/
305
- private function updateEventRules (): V
336
+ private function getEventBaseRules (): array
306
337
{
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 ()),
321
341
);
322
- }
323
342
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
+ ));
325
349
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
+ [
335
352
V::key ('calendar_id ' , V::stringType ()->notEmpty ()),
336
353
V::keyOptional ('busy ' , V::boolType ()),
354
+ V::keyOptional ('read_only ' , V::boolType ()),
337
355
V::keyOptional ('title ' , V::stringType ()->notEmpty ()),
338
356
V::keyOptional ('location ' , V::stringType ()->notEmpty ()),
339
- V::keyOptional ('recurrence ' , V:: arrayType () ),
357
+ V::keyOptional ('recurrence ' , $ recurrenceRule ),
340
358
V::keyOptional ('description ' , V::stringType ()->notEmpty ()),
359
+ V::keyOptional ('participants ' , $ participantsRule ),
360
+ V::keyOptional ('conferencing ' , $ this ->conferenceRules ()),
341
361
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
+ ];
349
363
}
350
364
351
365
// ------------------------------------------------------------------------------
@@ -359,7 +373,7 @@ private function timeRules(): V
359
373
{
360
374
return V::anyOf (
361
375
362
- // time
376
+ // time
363
377
V::keySet (V::key ('time ' , V::timestampType ())),
364
378
365
379
// date
@@ -380,4 +394,52 @@ private function timeRules(): V
380
394
}
381
395
382
396
// ------------------------------------------------------------------------------
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
+ // ------------------------------------------------------------------------------
383
445
}
0 commit comments