Class: Gravatar

Inherits:
Object
  • Object
show all
Defined in:
lib/gravatar-api.rb,
lib/gravatar-api/url.rb,
lib/gravatar-api/hash.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email) ⇒ Gravatar

Returns a new instance of Gravatar.



6
7
8
# File 'lib/gravatar-api.rb', line 6

def initialize(email)
	@@email = email
end

Class Method Details

.hash!(email) ⇒ Object

MD5 hash an email or string.



5
6
7
8
9
# File 'lib/gravatar-api/hash.rb', line 5

def self.hash!(email)
	email.downcase!
	hash = Digest::MD5.hexdigest(email)
	return hash
end

Instance Method Details

#hash!Object Also known as: hash

MD5 hash the given email.



12
13
14
15
16
# File 'lib/gravatar-api/hash.rb', line 12

def hash!
	@@email.downcase!
	hash = Digest::MD5.hexdigest(@@email)
	return hash
end

#url(options = { :size => 80 }) ⇒ Object Also known as: get

Get your Gravatar URL. Also a hash for size.



3
4
5
6
7
8
9
10
# File 'lib/gravatar-api/url.rb', line 3

def url(options = { :size => 80 })
	hash = Gravatar.hash!(@@email)
	if options[:size] == 80
		return "http://www.gravatar.com/avatar/#{hash}"
	else
		return "http://www.gravatar.com/avatar/#{hash}?s=#{options[:size]}"
	end
end