Skip to content

Instantly share code, notes, and snippets.

@chanian
Created January 24, 2011 02:10
Show Gist options
  • Save chanian/792701 to your computer and use it in GitHub Desktop.
Save chanian/792701 to your computer and use it in GitHub Desktop.
A method to retrieve the digg counts of a URL
require 'rubygems'
require 'json'
require 'open-uri'
# All your diggs, are belong to me
# I'm sure there is a better way, but this is a simple unauthenticated
# pull of digg counts for a URL. No bells.. No whistles..
def getDiggs(url)
begin
response = open("http://widgets.digg.com/buttons/count?url=#{url}")
return JSON.parse(response.string.split("(")[1].split(");")[0])["diggs"]
rescue
return 0
end
end
p getDiggs("http://theoatmeal.com/comics/shopping_cart")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment