Created
January 24, 2011 02:10
-
-
Save chanian/792701 to your computer and use it in GitHub Desktop.
A method to retrieve the digg counts of a URL
This file contains 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
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