/** {@inheritDoc} */ public function getEventApi(AbstractCalendar $calendar) { if (!$calendar instanceof Calendar) { throw new InvalidArgumentException('Wrong calendar provided, expected a google calendar'); } if (!isset($this->eventApis[$calendar->getId()])) { $this->eventApis[$calendar->getId()] = new EventApi($this->guzzle, $this, $calendar); } return $this->eventApis[$calendar->getId()]; }
/** {@inheritDoc} */ public function getPermissions(AbstractCalendar $calendar, AbstractCriterion $criterion = null) { $query = new Collection([new Collection([new Field('items', [new Field('id'), new Field('scope'), new Field('role')])], 'fields')]); if (null !== $criterion) { $query = $query->merge($criterion); } $response = $this->guzzle->get(sprintf('calendars/%s/acl', $calendar->getId()), ['query' => $query->build()]); if (200 > $response->getStatusCode() || 300 <= $response->getStatusCode()) { throw new ApiErrorException($response); } $result = $response->json(); $list = new ArrayCollection(); foreach ($result['items'] as $item) { // only user scope are supported if ('user' !== $item['scope']['type']) { continue; } $user = in_array($item['scope']['value'], $this->adapter->getUser()->getEmail(true)) ? $this->adapter->getUser() : User::hydrate(['email' => $item['scope']['value']]); $list[$item['id']] = UserPermission::hydrate($calendar, $user, $item['role']); } $calendar->setPermissions($list); return $list; }