/** * {@inheritdoc} */ public function getUserContacts() { $contacts = []; $parameters = ['cursor' => '-1']; $response = $this->apiRequest('friends/ids.json', 'GET', $parameters); $data = new Data\Collection($response); if (!$data->exists('ids')) { throw new UnexpectedValueException('Provider API returned an unexpected response.'); } if ($data->filter('ids')->isEmpty()) { return $contacts; } // 75 id per time should be okey $contactsIds = array_chunk((array) $data->get('ids'), 75); foreach ($contactsIds as $chunk) { $parameters = ['user_id' => implode(',', $chunk)]; try { $response = $this->apiRequest('users/lookup.json', 'GET', $parameters); $data = (new Parser($response))->toCollection(); } catch (Exception $e) { continue; } foreach ($data->all() as $item) { $contacts[] = $this->fetchUserContacts($item); } } return $contacts; }
/** * {@inheritdoc} */ public function getUserProfile() { $response = $this->apiRequest('user/info'); $data = new Data\Collection($response); if (!$data->exists('response')) { throw new UnexpectedValueException('Provider API returned an unexpected response.'); } $userProfile = new User\Profile(); $userProfile->displayName = $data->filter('response')->filter('user')->get('name'); foreach ($data->filter('response')->filter('user')->filter('blogs')->all() as $blog) { if ($blog->get('primary') && $blog->exists('url')) { $userProfile->identifier = $blog->get('url'); $userProfile->profileURL = $blog->get('url'); $userProfile->webSiteURL = $blog->get('url'); $userProfile->description = strip_tags($blog->get('description')); $bloghostname = explode('://', $blog->get('url')); $bloghostname = substr($bloghostname[1], 0, -1); $this->token('primary_blog', $bloghostname); break; } } return $userProfile; }
/** * {@inheritdoc} */ protected function getUserContacts() { $contacts = []; $response = $this->apiRequest('me/contacts'); if ($data->get('errcode')) { throw new UnexpectedValueException('Provider API returned an unexpected response.'); } $data = new Data\Collection($response); foreach ($data->filter('data')->all() as $idx => $entry) { $userContact = new User\Contact(); $userContact->identifier = $entry->get('id'); $userContact->displayName = $entry->get('name'); $userContact->email = $entry->filter('emails')->get('preferred'); $contacts[] = $userContact; } return $contacts; }
/** * {@inheritdoc} */ public function getUserProfile() { $response = $this->apiRequest('user'); $data = new Data\Collection($response); if (!$data->exists('id')) { throw new UnexpectedValueException('Provider API returned an unexpected response.'); } $userProfile = new User\Profile(); $userProfile->identifier = $data->get('id'); $userProfile->profileURL = $data->get('html_url'); $userProfile->photoURL = $data->get('avatar_url'); $userProfile->description = $data->get('bio'); $userProfile->region = $data->get('location'); $userProfile->displayName = $data->get('name'); $userProfile->displayName = $userProfile->displayName ?: $data->get('username'); $userProfile->webSiteURL = $data->filter('links')->get('web'); return $userProfile; }
/** * {@inheritdoc} */ public function getUserActivity($stream) { $activities = []; $apiUrl = $stream == 'me' ? '/me/feed' : '/me/home'; $response = $this->apiRequest($apiUrl); $data = new Data\Collection($response); if (!$data->exists('data')) { throw new UnexpectedValueException('Provider API returned an unexpected response.'); } if ($data->filter('data')->isEmpty()) { return $activities; } foreach ($data->filter('data')->all() as $item) { $activities[] = $this->fetchUserActivity($item); } return $activities; }
/** * Retrieve Google plus contacts * * .. */ protected function getGplusContacts($extraParams) { $contacts = []; $url = 'https://www.googleapis.com/plus/v1/people/me/people/visible?' . http_build_query($extraParams); $response = $this->apiRequest($url); $data = new Data\Collection($response); foreach ($data->filter('items')->all() as $idx => $item) { $userContact = new User\Contact(); $userContact->identifier = $item->get('id'); $userContact->email = $item->get('email'); $userContact->displayName = $item->get('displayName'); $userContact->description = $item->get('objectType'); $userContact->photoURL = $item->filter('image')->get('url'); $userContact->profileURL = $item->get('url'); $contacts[] = $userContact; } return $contacts; }