Monday, September 8, 2008

Diggr released

I finally got around to a small side project I have wanted to work on: a new ruby wrapper for the Digg API. There's one existing library out there that I know of, but I didn't like the syntax all that much. So, like any good developer, I've reinvented the wheel! My library is called diggr and it strives to be simple and consistent with the Digg API endpoints listed here. Rather than boring you with a detailed description, I'll just show some code snippets below. For more information on diggr check out:

- Docs
- Source

Here are a few simple examples:

require 'rubygems'
require 'diggr'

diggr = Diggr::API.new

# retrieve a single user by user name and print the number of profile views
user = diggr.user("johndoe").fetch
puts user.profileviews

# iterator over the most recent 10 stories (default return size) and print their titles
diggr.stories.each do |story|
puts story.title
end

# print the title of the 3 most recent hot stories
diggr.stories.hot.options(:count => 3).each do |story|
puts story.title
end

# build an array of stories whos title contains "foo"
diggr.stories.inject([]) do |array,story|
array << story if story.title =~ /foo/
array
end

# print the title of the 2nd and 3rd most recent stories
diggr.stories.options(:count => 2, :offset => 2).each do |story|
puts story.title
end

3 comments:

Sanjay Bisht said...

Hi,

I was trying to gem install diggr, but it keep saying "Failed to build gem native extension".
I'm new to RoR, so unable to get to the solution. Can you help me with that please.

Thanks

drew olson said...

Sanjay -

Are you attempting to build other gems along with diggr? diggr does not have any native extensions nor does any of it dependencies. Not exactly sure why you would be running into this error. Are you doing the following to install it:

sudo gem install diggr

Sanjay Bisht said...

Hey Drew,

No I'm not trying to build any other gem. I'm just trying to install diggr. I'm running windows vista, and simply doing a gem install diggr. As per the requirements, I have json-1.1.3, rails-2.2.1 and it's dependencies.
Not quite sure why this is happening. Any suggestions ??