Module: Gravity::InstanceMethods
- Defined in:
- lib/gravity.rb
Instance Method Summary collapse
- #get(url) ⇒ Object
- #gravatar_hash(email) ⇒ Object
- #gravatar_image(options = {}) ⇒ Object
- #gravatar_profile(options = {}) ⇒ Object
- #gravatar_url(secure) ⇒ Object
Instance Method Details
#get(url) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/gravity.rb', line 62 def get(url) uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) if uri.scheme == 'https' http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end request = Net::HTTP::Get.new(uri.request_uri) response = http.request(request) if response.kind_of?(Net::HTTPRedirection) get response['location'] else response.body end end |
#gravatar_hash(email) ⇒ Object
26 27 28 |
# File 'lib/gravity.rb', line 26 def gravatar_hash(email) Digest::MD5.hexdigest email.to_s.strip.downcase end |
#gravatar_image(options = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/gravity.rb', line 34 def gravatar_image( = {}) = self.class..merge email = self.send .delete(:email) secure = .delete :secure url = gravatar_url(secure) + 'avatar/' + gravatar_hash(email) if .has_key?(:default) [:default] = CGI::encode [:default] if [:default].match(/^http/) end if !.empty? url += '?' + .map{|o, v| "#{o}=#{v.to_s}"}.join('&') end url end |
#gravatar_profile(options = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/gravity.rb', line 51 def gravatar_profile( = {}) = self.class..merge email = self.send .delete(:email) secure = .delete :secure url = gravatar_url(secure) + gravatar_hash(email) + '.json' json_profile = JSON.parse get(url) json_profile['entry'].first end |
#gravatar_url(secure) ⇒ Object
30 31 32 |
# File 'lib/gravity.rb', line 30 def gravatar_url(secure) 'http' + (secure ? 's://secure.' : '://') + 'gravatar.com/' end |