Module: SimpleGravatar

Defined in:
lib/simple_gravatar.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  default: nil,
  forcedefault: false,
  rating: :g,
  secure: false,
  size: 48
}

Instance Method Summary collapse

Instance Method Details

#gravatar_url(email, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/simple_gravatar.rb', line 10

def gravatar_url(email, options = {})
  options = DEFAULT_OPTIONS.merge options
  secure = options[:secure]
  options.delete(:secure)

  unless options[:forcedefault]
    options.delete(:forcedefault)
  end

  gravatar_id = Digest::MD5.hexdigest email.downcase

  params = options.collect { |k, v| "#{k}=#{v}" }.join('&')

  url = if secure
    "https://secure.gravatar.com/avatar"
  else
    "http://gravatar.com/avatar"
  end

  "#{url}/#{gravatar_id}.png?#{params}"
end