Class: GravatarService

Inherits:
Object
  • Object
show all
Defined in:
app/services/gravatar_service.rb

Instance Method Summary collapse

Instance Method Details

#execute(email, size = nil, scale = 2, username: nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/services/gravatar_service.rb', line 4

def execute(email, size = nil, scale = 2, username: nil)
  return if Gitlab::FIPS.enabled?
  return unless Gitlab::CurrentSettings.gravatar_enabled?

  identifier = email.presence || username.presence
  return unless identifier

  hash = Digest::MD5.hexdigest(identifier.strip.downcase)
  size = Groups::GroupMembersHelper::AVATAR_SIZE unless size && size > 0

  sprintf gravatar_url,
    hash: hash,
    size: size * scale,
    email: ERB::Util.url_encode(email&.strip || ''),
    username: ERB::Util.url_encode(username&.strip || '')
end

#gitlab_configObject



21
22
23
# File 'app/services/gravatar_service.rb', line 21

def gitlab_config
  Gitlab.config.gitlab
end

#gravatar_configObject



25
26
27
# File 'app/services/gravatar_service.rb', line 25

def gravatar_config
  Gitlab.config.gravatar
end

#gravatar_urlObject



29
30
31
32
33
34
35
# File 'app/services/gravatar_service.rb', line 29

def gravatar_url
  if gitlab_config.https
    gravatar_config.ssl_url
  else
    gravatar_config.plain_url
  end
end