Class: GravatarProfile

Inherits:
Object
  • Object
show all
Defined in:
lib/gravatar_profile.rb

Constant Summary collapse

DefaultOptions =
{
    :rating => 'PG',
    :secure => false,
    :filetype => :png,
    :size => 80
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email = '', options = {}) ⇒ GravatarProfile



24
25
26
27
28
29
# File 'lib/gravatar_profile.rb', line 24

def initialize(email = '', options = {})
  
  @email = email
  @id = gravatar_id
  
end

Instance Attribute Details

#emailObject

Returns the value of attribute email.



22
23
24
# File 'lib/gravatar_profile.rb', line 22

def email
  @email
end

#idObject

Returns the value of attribute id.



22
23
24
# File 'lib/gravatar_profile.rb', line 22

def id
  @id
end

Instance Method Details

#get_profile_info(options = {}) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/gravatar_profile.rb', line 50

def get_profile_info(options={})
  options = GravatarProfile::DefaultOptions.merge(options)
  proxy_host = options.delete(:proxy_host)
  proxy_port = options.delete(:proxy_port)
  
  url = URI.parse("http://en.gravatar.com")
  res = Net::HTTP::Proxy(proxy_host, proxy_port).start(url.host, url.port) {|http|
  http.get(gravatar_profilename(:xml))
  }
  
  if res.msg == "OK"
    profile_data = XmlSimple.xml_in(res.body)
    if profile_data["entry"]
      return profile_data["entry"].first
    end
  end
end

#gravatar_abbreviationsObject



14
15
16
17
18
19
# File 'lib/gravatar_profile.rb', line 14

def gravatar_abbreviations
{ :size => 's',
  :default => 'd',
  :rating => 'r'
}
end

#gravatar_idObject



31
32
33
# File 'lib/gravatar_profile.rb', line 31

def gravatar_id
    Digest::MD5.hexdigest(email.to_s.downcase)
end

#gravatar_profile_url(options = {}) ⇒ Object

Constructs the full Gravatar url.



44
45
46
47
48
# File 'lib/gravatar_profile.rb', line 44

def gravatar_profile_url(options={})
  options = GravatarProfile::DefaultOptions.merge(options)
  gravatar_hostname(options.delete(:secure)) +
    gravatar_profilename(options.delete(:filetype))
end

#gravatar_url(options = {}) ⇒ Object

Constructs the full Gravatar url.



36
37
38
39
40
41
# File 'lib/gravatar_profile.rb', line 36

def gravatar_url(options={})
  options = GravatarProfile::DefaultOptions.merge(options)
  gravatar_hostname(options.delete(:secure)) +
    gravatar_filename(options.delete(:filetype)) +
    url_params_from_hash(options)
end