-
Notifications
You must be signed in to change notification settings - Fork 2
/
GoogleCalendarClient.php
executable file
·51 lines (40 loc) · 1.21 KB
/
GoogleCalendarClient.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
require __DIR__ . '/vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
/**
* Class GoogleCalendarClient makes API calls to Google API
*/
class GoogleCalendarClient
{
protected $service;
/**
* GoogleCalendarClient constructor
*/
public function __construct()
{
$apiKey = getenv( 'GOOGLE_API_KEY' );
$client = new Google_Client();
$client->setAccessType( 'offline' );
$client->useApplicationDefaultCredentials();
$client->setDeveloperKey( $apiKey );
$client->setScopes( [ 'https://www.googleapis.com/auth/calendar' ] );
$this->service = new Google_Service_Calendar( $client );
}
/**
* Creates an event
*
* @param array $eventDetails event details e.g summary, start, end, attendees, e.t.c
*
* @return array $user of a user
*/
public function createEvent( $eventDetails )
{
$event = new Google_Service_Calendar_Event( $eventDetails );
$optionalArguments = [ 'sendNotifications' => true ];
$calendarId = 'primary';
$event = $this->service->events
->insert( $calendarId, $event, $optionalArguments );
return $event;
}
}