Created
February 23, 2011 17:46
-
-
Save xoebus/840800 to your computer and use it in GitHub Desktop.
A Gravatar Downloader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'digest/md5' | |
require 'net/http' | |
class String | |
def user_hash | |
Digest::MD5.hexdigest self.downcase | |
end | |
end | |
def url email | |
"/avatar/#{email.user_hash}" | |
end | |
Net::HTTP.start("www.gravatar.com") do |http| | |
resp = http.get(url(ARGV.first)) | |
open("avatar.png", "wb") do |file| | |
file.write(resp.body) | |
end | |
end | |
puts "Downloaded! => avatar.png" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment