diff --git a/README.md b/README.md index 90cdc14..cadb99e 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ $event->addAttendee([ 'comment' => 'Lorum ipsum', ]); $event->addAttendee(['email' => 'anotherEmail@gmail.com']); +$event->addMeetLink(); // optionally add a google meet link to the event $event->save(); diff --git a/src/Event.php b/src/Event.php index 2009080..95a71e7 100644 --- a/src/Event.php +++ b/src/Event.php @@ -5,6 +5,9 @@ use Carbon\Carbon; use Carbon\CarbonInterface; use DateTime; +use Google_Service_Calendar_ConferenceData; +use Google_Service_Calendar_ConferenceSolutionKey; +use Google_Service_Calendar_CreateConferenceRequest; use Google_Service_Calendar_Event; use Google_Service_Calendar_EventAttendee; use Google_Service_Calendar_EventDateTime; @@ -24,6 +27,9 @@ class Event /** @var array */ protected $attendees; + /** @var boolean */ + protected $hasMeetLink = false; + public function __construct() { $this->attendees = []; @@ -178,6 +184,10 @@ public function save(string $method = null, $optParams = []): self $googleCalendar = $this->getGoogleCalendar($this->calendarId); + if ($this->hasMeetLink) { + $optParams['conferenceDataVersion'] = 1; + } + $googleEvent = $googleCalendar->$method($this, $optParams); return static::createFromGoogleCalendarEvent($googleEvent, $googleCalendar->getCalendarId()); @@ -217,6 +227,22 @@ public function addAttendee(array $attendee) $this->googleEvent->setAttendees($this->attendees); } + public function addMeetLink() + { + $conferenceData = new Google_Service_Calendar_ConferenceData([ + 'createRequest' => new Google_Service_Calendar_CreateConferenceRequest([ + 'requestId' => Str::random(10), + 'conferenceSolutionKey' => new Google_Service_Calendar_ConferenceSolutionKey([ + 'type' => 'hangoutsMeet', + ]), + ]), + ]); + + $this->googleEvent->setConferenceData($conferenceData); + + $this->hasMeetLink = true; + } + public function getSortDate(): string { if ($this->startDate) { diff --git a/tests/Integration/EventTest.php b/tests/Integration/EventTest.php index fc9fb62..2b97323 100644 --- a/tests/Integration/EventTest.php +++ b/tests/Integration/EventTest.php @@ -143,6 +143,15 @@ public function it_can_set_multiple_attendees() $this->assertEquals($attendees[1]['email'], $this->event->googleEvent->getAttendees()[1]->getEmail()); } + /** @test */ + public function it_can_set_a_meet_link() + { + $this->event->addMeetLink(); + + $this->assertNotNull($this->event->googleEvent->getConferenceData()); + $this->assertEquals('hangoutsMeet', $this->event->googleEvent->getConferenceData()->getCreateRequest()->getConferenceSolutionKey()->getType()); + } + /** @test */ public function it_can_determine_if_an_event_is_an_all_day_event() {