Skip to content

Commit

Permalink
Upgrade to latest Google API library
Browse files Browse the repository at this point in the history
  • Loading branch information
inghamn committed Oct 10, 2024
1 parent a7f083f commit f442d8a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
"twig/twig": "@stable",
"twig/markdown-extra": "@stable"
},
"scripts": {
"pre-autoload-dump": "Google\\Task\\Composer::cleanup"
},
"extra": {
"google/apiclient-services": ["Calendar"]
},
"require-dev": {
"phpunit/phpunit": "~9.0"
},
Expand Down
26 changes: 13 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions src/Application/Models/GoogleGateway.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
<?php
/**
* @copyright 2017 City of Bloomington, Indiana
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
* @copyright 2017-2024 City of Bloomington, Indiana
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE
*/
namespace Application\Models;

use Google\Client;
use Google\Service\Calendar;

class GoogleGateway
{
private static function getClient()
{
static $client = null;

if (!$client) {
$client = new \Google_Client();
$client = new Client();
$client->setAuthConfig(GOOGLE_CREDENTIALS_FILE);
$client->setScopes([\Google_Service_Calendar::CALENDAR]);
$client->setScopes([Calendar::CALENDAR]);
$client->setSubject(GOOGLE_USER_EMAIL);
}
return $client;
Expand All @@ -27,7 +30,7 @@ private static function getClient()
* @param DateTime $end
* @param boolean $singleEvents
* @param int $maxResults
* @return Google_Service_Calendar_EventList
* @return EventList
*/
public static function events($calendarId, \DateTime $start=null, \DateTime $end=null, $singleEvents=true, $maxResults=null)
{
Expand All @@ -45,8 +48,8 @@ public static function events($calendarId, \DateTime $start=null, \DateTime $end
if ($start) { $opts['timeMin'] = $start->format(\DateTime::RFC3339); }
if ($end ) { $opts['timeMax'] = $end ->format(\DateTime::RFC3339); }

$service = new \Google_Service_Calendar(self::getClient());
$events = $service->events->listEvents($calendarId, $opts);
$service = new Calendar(self::getClient());
$events = $service->events->listEvents($calendarId, $opts);
return $events;
}

Expand All @@ -57,7 +60,7 @@ public static function events($calendarId, \DateTime $start=null, \DateTime $end
*/
public static function getEvent($calendarId, $eventId)
{
$service = new \Google_Service_Calendar(self::getClient());
$service = new Calendar(self::getClient());
return $service->events->get($calendarId, $eventId);
}
}

0 comments on commit f442d8a

Please sign in to comment.