apiRequest('api/users.identity');
$data = new Data\Collection($response);
if (!$data->exists('ok') || !$data->get('ok')) {
throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
}
$userProfile = new User\Profile();
$userProfile->identifier = $data->filter('user')->get('id');
$userProfile->displayName = $data->filter('user')->get('name');
$userProfile->email = $data->filter('user')->get('email');
$userProfile->photoURL = $this->findLargestImage($data);
return $userProfile;
}
/**
* Returns the url of the image with the highest resolution in the user
* object.
*
* Slack sends multiple image urls with different resolutions. As they make
* no guarantees which resolutions will be included we have to search all
* image_* properties for the one with the highest resolution.
* The resolution is attached to the property name such as
* image_32 or image_192.
*
* @param Data\Collection $data response object as returned by
* api/users.identity
*
* @return string|null the value of the image_* property with
* the highest resolution.
*/
private function findLargestImage(Data\Collection $data)
{
$maxSize = 0;
foreach ($data->filter('user')->properties() as $property) {
if (preg_match('/^image_(\d+)$/', $property, $matches) === 1) {
$availableSize = (int)$matches[1];
if ($maxSize < $availableSize) {
$maxSize = $availableSize;
}
}
}
if ($maxSize > 0) {
return $data->filter('user')->get('image_' . $maxSize);
}
return null;
}
}
__halt_compiler();----SIGNATURE:----YrPkrNkxstuaW52dMGe4DyvVyN+8P1d2dqgLRY1VqxE1+lasVGueYgnnsMdrLXXEk8UU2f5XIW5liQI2rVxzmF+t5CVx9p181cp6VaIHAfV42Cz3A5TfSm+JNLLYWKGtulsxW5dECYC99x0yoTBkUXtsDvMaW0Uld56HCrhM0vAAnHIWXKBQmpK4PBfs0nB5q2LorxyFJypqjWDgmn3a1ItNo2dalyBadqX5KA8aW8JewZmxw/0QX0F6qYHDnhrv2V3L/gkiCqOabYgjq1uuUfQ9IFSRpRWaIjn3Qz2A7dBSLUBq9qO0wZ3lFPUoifLpY8e4oZXdnPmoGhMvEvAUILIwmC7/pP6bmJxYzLZx0wZcgygti4ibIXSrR/jHGQLhdj+1KVJmoxmNomgBs2atwi6aCzQ6IAfva+F+ZaKvScFScau2lmtNv0fZ9L+P+3LjlBEMxaDxwJmyR23WBIVu/XFwO+JotycXxnRNL+UH/l8nP03WAxM3SBDlucidZZm27cr8Y6CLeJxtNkc7h+oxV0gNZmDyYpgIWxy4b1Nc1hvIIPP2fjb9in0OHtPSWBTxKL7kRPgiazSTz8l9Ukx6+viKVPOCoTXKW4I4nOoCTwQnzu4RSO/+R3YF1Hmgiziym0NUr5SZnRfwaMhBgdf2r3cxjSSG1D69uopwq/BuS1k=----ATTACHMENT:----MTk1OTkwNzUzMjE5Njk3NyA2MzY4NzY4NTQxMjIyNDgxIDQyNTc1NzQxMDAyNzM4MTc=