Mar 31st 09
Building a Readernaut Widget
My friend Jorge noticed the Readernaut widget at the bottom of my sidebar and asked how I implemented it. I’m going to post the answer here in case anyone else is interested in adding this widget to their sidebar as well.
If you don’t already know about Readernaut, it’s an awesome web app that Nathan Borror built to help people keep track of their books: what you’re reading, what you want to read, what your friends are reading, and so forth. Best of all, Readernaut makes it really easy to bookmark your reading progress, and pretty soon you’ll be able to publish your progress directly to Twitter. Nathan’s probably working on it as I write this.
Anyways, here’s the Readernaut API. I’m using JSON because, well, I am very fond of it. Since JSON is nothing more than JavaScript, it’s really easy to get at the information I need with just a few lines of code.
Step 1. Include the JSON file
The first step is to create a script element that requests your JSON file from the Readernaut server and includes it in your page.
Of course, replace “your_username” with your unique Readernaut username. I’m appending the callback parameter so that I can hand off my data to a parsing function. You can name the function whatever you want. In this case, I’m using the name “parseResponse”. Put this line at the end of your page, just before the </body> tag.
Step 2. Create a container
Next, I create an empty element where I want to display my widget. This acts as a container, which I will fill with the data I’ve parsed from Readernaut.
As you can see, I created a div that will be my container and assigned it an ID of “bookshelf” so it will be easy to access and manipulate via the DOM. I’ve also included the parsing script, which I’ve named “readernaut.js” and will explain in the next step. This file contains the parseResponse function, which was specified earlier as the receiver of my JSON data. Make sure you change the src attribute to match the location of your JavaScript file.
Step 3. Parse and display the information
Now I need to create the parseResponse function, which looks like so. Remember, this function goes in the “readernaut.js” file.
I’m not going to walk you through the function line-by-line, but I’ll point out some of the things you might want to change.
Number of Books
The number of books displayed is controlled by the test condition of the for loop. This is the little part that says i<6. Change the number 6 to the number of books you want displayed in your widget. At this time, the Readernaut API only returns 10 books, so don't make the number any larger than 10.
Size of Book Cover
The Readernaut API gives you access to three book cover sizes: small, medium, and large. I'm using medium. If you want to access one of the other sizes, change "cover_medium" to either "cover_small" or "cover_large". Of course, you can always use CSS (or the image width attribute) to make the covers a little smaller or larger per your requirements.
Finally, I wanted every other image to have a class of "odd" so that I could do some stuff with floats. If you don't need this, you can simply delete the entire if statement.
The end
Anyways, that's it folks! With a little CSS, you'll have your Readernaut widget looking exactly the way you want in no time. If you have any questions, leave a comment and I'll do my best to help you out.
Oh, and one last note. The API is still a draft and warns, "This API is under development and backwards incompatible changes can (and will) happen." As such, this script isn't guaranteed to work forever. If anything changes, however, I'll be sure to post about it here.
13 Comments
Jump to comment formSpeak Your Mind
Excercise your freedom of speech, but please be kind and respectful to others. I reserve the right to delete anything considered to be spam, offensive, or off topic.

Nathan Borror on Apr 1st 09
Great post Adam :)
I’m actually working on implementing some new services that should make widget making a little easier, one of them being my interpretation of an “oEmbed style” list of objects (e.g. http://readernaut.com/services/oembed/?url=http://readernaut.com/nathan/notes/). I’m hoping to have it wrapped up soon so people can stop nagging me about widget :)
Adam Polselli on Apr 1st 09
Hey, Nathan. Hadn’t heard of oEmbed before, but I just read up on it and it sounds awesome. I look forward to it on Readernaut! :)
Ranjani on Apr 1st 09
This is actually very cool. Hopefully this will make it onto my site somewhere along with that Twitter widget I keep meaning to add but forgot about :P
Awesome job, and if I haven’t said already (but I probably have), beautiful site :)
Jarrett M. Barnett on May 28th 09
This was great! I’d thought I’d mention that you can actually feed your Readernaut progress to Twitter already using a separate service: http://www.twitterfeed.com.
From there, simply add the URL for the Readernaut feed, and your good to go!
Simply replace “jmbelite” with your Readernaut username in the URL below to access the Readernaut feed. (There are a few other variables that can be thrown into the URL as well to sort the results a bit differently, but its definitely not that flexible yet).
http://readernaut.com/feeds/rss/jmbelite/timeline/
Red26 on Oct 10th 09
This activity is ideal for students to work in pairs, but each student will have a tube of DNA at the end. ,
BadGirl100 on Oct 22nd 09
OK, Michel, show me someone who actually understands the evidence who is not concerned that we are altering the climate. ,
Barbara75 on Oct 23rd 09
Italy or the raw pork in my own house. ,
Tim Driver on Nov 4th 09
Thanks for this I am currently redeveloping my CSS site and I think this will be useful
Tim
Leanda on Mar 14th 10
Hi Adam
Thanks for this code, really useful. I’m terrible with this kind of code, would you know if it’s possible to also parse the title of the book as text along side the book cover.
I had try last night, but just couldn’t seem to get it to work.
Cheers
Leanda
personal growth on Jan 27th 11
Thanks for very informative and helpful blogs of these codes. I really need these codes. Thanks again…
Fat loss Nutrition and Fitness on Jul 12th 11
This are actually very very cool. Hopefully that have make it into my site somewhere along with that Twitter widget I keep meaning to add but forgot abou
Flat for rent Aberdeen on Jan 20th 12
Simply replace “jmbelite” with your Readernaut username in the URL below to access the Readernaut feed. (There was a few other variables that can be thrown into the URL as well to sort the results a bit differently, but its definitely not that flexible yet).
Bleaching düsseldorf on Mar 10th 12
I think this was great! I’d thought I’d mention that you can actually feed your Readernaut progress to Twitter already using a separate service: