Class: GravatarProfile
- Inherits:
-
Object
- Object
- GravatarProfile
- Defined in:
- lib/gravatar_profile.rb
Constant Summary collapse
- DefaultOptions =
{ :rating => 'PG', :secure => false, :filetype => :png, :size => 80 }
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#id ⇒ Object
Returns the value of attribute id.
Instance Method Summary collapse
- #get_profile_info(options = {}) ⇒ Object
- #gravatar_abbreviations ⇒ Object
- #gravatar_id ⇒ Object
-
#gravatar_profile_url(options = {}) ⇒ Object
Constructs the full Gravatar url.
-
#gravatar_url(options = {}) ⇒ Object
Constructs the full Gravatar url.
-
#initialize(email = '', options = {}) ⇒ GravatarProfile
constructor
A new instance of GravatarProfile.
Constructor Details
#initialize(email = '', options = {}) ⇒ GravatarProfile
24 25 26 27 28 29 |
# File 'lib/gravatar_profile.rb', line 24 def initialize(email = '', = {}) @email = email @id = gravatar_id end |
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
22 23 24 |
# File 'lib/gravatar_profile.rb', line 22 def email @email end |
#id ⇒ Object
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(={}) = GravatarProfile::DefaultOptions.merge() proxy_host = .delete(:proxy_host) proxy_port = .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_abbreviations ⇒ Object
14 15 16 17 18 19 |
# File 'lib/gravatar_profile.rb', line 14 def gravatar_abbreviations { :size => 's', :default => 'd', :rating => 'r' } end |
#gravatar_id ⇒ Object
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(={}) = GravatarProfile::DefaultOptions.merge() gravatar_hostname(.delete(:secure)) + gravatar_profilename(.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(={}) = GravatarProfile::DefaultOptions.merge() gravatar_hostname(.delete(:secure)) + gravatar_filename(.delete(:filetype)) + url_params_from_hash() end |