Skip to content

Commit

Permalink
Add ability to attach a google meet link to calendar event (#270)
Browse files Browse the repository at this point in the history
* add ability to attach google meet link to event

* Update readme to document adding google meet link

* fix import order

* test for adding meet link

* test for adding meet link
  • Loading branch information
JoshTrebilco authored Apr 20, 2023
1 parent 37322a2 commit f13aa90
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ $event->addAttendee([
'comment' => 'Lorum ipsum',
]);
$event->addAttendee(['email' => '[email protected]']);
$event->addMeetLink(); // optionally add a google meet link to the event

$event->save();

Expand Down
26 changes: 26 additions & 0 deletions src/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,6 +27,9 @@ class Event
/** @var array */
protected $attendees;

/** @var boolean */
protected $hasMeetLink = false;

public function __construct()
{
$this->attendees = [];
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions tests/Integration/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit f13aa90

Please sign in to comment.