Skip to content

Instantly share code, notes, and snippets.

@xoebus
Created February 23, 2011 17:46
Show Gist options
  • Save xoebus/840800 to your computer and use it in GitHub Desktop.
Save xoebus/840800 to your computer and use it in GitHub Desktop.
A Gravatar Downloader
#!/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