From d5b0f29c4a3a9d7da849d91a16f70bd494831da7 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 13 Jun 2014 17:11:46 +0300 Subject: [PATCH] Move gravatar url compose to separate service Signed-off-by: Dmitriy Zaporozhets --- app/services/gravatar_service.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 app/services/gravatar_service.rb diff --git a/app/services/gravatar_service.rb b/app/services/gravatar_service.rb new file mode 100644 index 00000000000..a69c7c78377 --- /dev/null +++ b/app/services/gravatar_service.rb @@ -0,0 +1,28 @@ +class GravatarService + def execute(email, size = nil) + if gravatar_config.enabled && email.present? + size = 40 if size.nil? || size <= 0 + + sprintf gravatar_url, + hash: Digest::MD5.hexdigest(email.strip.downcase), + size: size, + email: email.strip + end + end + + def gitlab_config + Gitlab.config.gitlab + end + + def gravatar_config + Gitlab.config.gravatar + end + + def gravatar_url + if gitlab_config.https + gravatar_config.ssl_url + else + gravatar_config.plain_url + end + end +end