class EasyGravatar::Gravatar
Attributes
md5[R]
Public Class Methods
new(email)
click to toggle source
# File lib/easy_gravatar/gravatar.rb, line 10 def initialize(email) if email && email.length > 0 @valid_email = true else email = '' end @md5 = Digest::MD5.hexdigest(email.downcase) end
Public Instance Methods
avatar(width = 80)
click to toggle source
# File lib/easy_gravatar/gravatar.rb, line 29 def avatar(width = 80) "#{get_value(:thumbnailUrl)}?w=#{width}" end
full_name()
click to toggle source
# File lib/easy_gravatar/gravatar.rb, line 25 def full_name get_value :formattedName end
get_value(key, subkey = nil)
click to toggle source
# File lib/easy_gravatar/gravatar.rb, line 33 def get_value(key, subkey = nil) return '' unless @valid_email return '' unless hash[key] return '' if subkey and !hash[key][subkey] return hash[key][subkey] if subkey hash[key] end
hash()
click to toggle source
# File lib/easy_gravatar/gravatar.rb, line 20 def hash return {} unless @valid_email @hash ||= EasyGravatar::JsonParser.for(get_hash).parse end
Private Instance Methods
get_hash()
click to toggle source
# File lib/easy_gravatar/gravatar.rb, line 45 def get_hash Net::HTTP.get(URI.parse(profile_url)) end
profile_url(url = "https://www.gravatar.com/
click to toggle source
# File lib/easy_gravatar/gravatar.rb, line 49 def profile_url(url = "https://www.gravatar.com/#{@md5}.json") response = Net::HTTP.get_response(URI.parse(url)) case response when Net::HTTPSuccess then url when Net::HTTPRedirection then new_url = response['location'] profile_url(new_url) end end