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:----u2JzapgMfxQU5retwUCTRlY+o4CK5Z6zc5FeZighunnOUZKdbXoyK9Uaw+yu0bJvHcJAHytdxBmmgA5tIKLCgqHPTiFZ58D/F3XtNBFWywuo12VcRWQwTzhMXap0KBOHhR+Pfa7D1AFYqgchMXLMMjlS65fVGOeN016BqoJzkFvBgHWb2lk1VRP8uT7qrMnqokODJU1wVlnEewKgMg2MW4vajM6pOgIcDpktoxF9yib9OzYfO4SKZz/4rweEJGKu7e26jrRUIxrI/G2rrezAWVxBsbirFJQmeU7uWnxWIsXaKUUuH+24+k/QRYENvcF9ZkWRBvkNd/jEyvyghq0me5YfZkkw0d5aohA+eO5oFme0mrFQIenXvOsPfrWarewnRcdQn2fq/Hn5OvmT6A7yd8N/bLGNvWetubBs2WRHB7Ss9E05ItlcuPh2dFwH2HGL1zIathuDRafEGXFMZCfWlW7t+wzUZBrnMvlAsXNL8SteKxe3JwY8qGucyntyZm2NiFluqolZ1pHNUrikZUS+piPnEodWbUI3PpzkGsKPLMEnQykRdNRvMQ7cHhlxOh0j+72TsqTV13v1bM1yF/6HmYAnb0UoCMTafv2rhPNQo826RyWvfsIt/4xBeWVhyKW8a5iiVkY6x9zb9kzS/zVwCGkK05XFWyN5dMqKsKgIJIA=----ATTACHMENT:----MjE1MTY5ODUxODk2ODczIDI3OTMxMTkxNTA4ODAyMDIgOTg2NTc1NDc4OTUwMjM3Mw==