예제 #1
0
 /** {@inheritDoc} */
 public function getList(AbstractCriterion $criterion = null)
 {
     $nextPageToken = null;
     $query = new Collection([]);
     $list = new ArrayCollection();
     if (null !== $this->calendar->getSyncToken()) {
         $query->addCriterion(new Collection([new Field($this->calendar->getSyncToken())], 'nextSyncToken'));
     }
     $fields = [new Field('nextSyncToken'), new Field('nextPageToken'), new Field('items', $this->fields)];
     $query->addCriterion(new Collection([new Field(null, $fields)], 'fields'));
     if (null !== $criterion) {
         $query = $query->merge($criterion);
     }
     try {
         $showDeleted = (bool) $query->getCriterion('showDeleted');
     } catch (CriterionNotFoundException $e) {
         $showDeleted = false;
     }
     $query = $query->build();
     do {
         $current = $query;
         if (null !== $nextPageToken) {
             $current['nextPageToken'] = $nextPageToken;
         }
         $response = $this->guzzle->get(sprintf('calendars/%s/events', $this->calendar->getId()), ['query' => $current]);
         if (200 > $response->getStatusCode() || 300 <= $response->getStatusCode()) {
             throw new ApiErrorException($response);
         }
         $result = $response->json();
         foreach ($result['items'] as $item) {
             // ignore the short cancelled recurring events
             if (!$showDeleted && isset($item['status']) && AbstractEvent::STATUS_CANCELLED === $item['status']) {
                 continue;
             }
             $list[$item['id']] = BasicEvent::hydrate($this->calendar, $item);
         }
         $nextPageToken = isset($result['nextPageToken']) ? $result['nextPageToken'] : null;
     } while (null !== $nextPageToken);
     $this->calendar->setSyncToken($result['nextSyncToken']);
     return $list;
 }
예제 #2
0
 /**
  * Get the current user ; fetches its information if it was not fetched yet
  *
  * @return User
  */
 public function getUser()
 {
     if (null == $this->user) {
         $fields = [new Field('id'), new Field('name'), new Field('emails')];
         $criterion = new Collection([new Collection($fields, 'fields')]);
         $response = $this->guzzle->get('../../plus/v1/people/me', ['query' => $criterion->build()]);
         if (200 > $response->getStatusCode() || 300 <= $response->getStatusCode()) {
             throw new ApiErrorException($response);
         }
         $emails = [];
         $result = $response->json();
         foreach ($result['emails'] as $email) {
             if ('account' !== $email['type']) {
                 continue;
             }
             $emails[] = $email['value'];
         }
         $name = sprintf('%s %s', $result['name']['givenName'], $result['name']['familyName']);
         $this->user = new User($name, $emails, $result['id']);
     }
     return $this->user;
 }