fixup! Cleanup, refactor and test new AvatarService

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst
2017-11-13 14:16:23 +01:00
parent 0f81b83948
commit 3bc14145ca
25 changed files with 591 additions and 169 deletions

View File

@ -39,17 +39,18 @@ class GravatarSource implements IAvatarSource {
}
/**
* @param string $email
* @return string|null
* @param string $email sender email address
* @param AvatarFactory $factory
* @return Avatar|null avatar URL if one can be found
*/
public function fetch($email) {
public function fetch($email, AvatarFactory $factory) {
$gravatar = new Gravatar(['size' => 128], true);
$avatar = $gravatar->avatar($email, ['d' => 404], true);
$avatarUrl = $gravatar->avatar($email, ['d' => 404], true);
$client = $this->clientService->newClient();
try {
$response = $client->get($avatar);
$response = $client->get($avatarUrl);
} catch (Exception $exception) {
return null;
}
@ -60,7 +61,8 @@ class GravatarSource implements IAvatarSource {
return null;
}
return $avatar;
// TODO: check whether it's really always a jpeg
return $factory->createExternal($avatarUrl, 'image/jpeg');
}
}