Thu, 12 Apr 12

Bookmark printing service for the Go Free Range Printer platform

I've spent the last couple of days creating a simple service for the Printer platform. This service allows you to print a bookmark (in the traditional sense) for the book you're reading. Although it's probably of most use to those people with their own printers, you can definitely have a play with generating your own bookmarks (and see a printed example) over on the Printer bookmarks app on Heroku.

The idea of a book-specific bookmark, on which I can record when I start and finish along with some reading notes, appeals to me. I can actually imagine that a custom bookmark printing service like this might be useful outside of this little experiment with the Printer platform.

Developing this little bookmark application (source on github) allowed me to use the Printer platform in anger, which was great as I'd only really been following James A's impressive work from the sidelines.

Building the bookmark service

The rest of this post is a fairly high level view of how I approached the development of this little service. Hopefully I'll convey how simple it is to build your own Printer service.

I started by looking at the example Printer Mail, Printer Paint and Printer Weather apps. While these services are geared toward sending content (from a person in the case of mail and paint, and from a machine in the case of weather) to another person's printer, I think the bookmark service is most useful for someone wanting to print to their own printer. This made my life a little easier as it meant I didn't need to worry about storing printer details in my app: I could rely on the user entering their printer address at the time they wanted to print the bookmark.

The first thing I did was create a simple html bookmark (see 7652ba) that I could preview using the Printer API (you can think of the Printer API as something like Google Cloud Print for receipt printers). Once happy that the preview looked OK I moved on to making the bookmark dynamic based on a supplied Amazon URL (see 3f5377). The addition of some tests allowed me to refactor the code in preparation for the simple Sinatra web interface (see a75e4a). Once able to view the bookmarks in a browser I wanted them to look a little closer to how they'd look once printed. Fortunately, I was able to borrow the template from the Printer Mail app to do just that (see 0ba536). I had the app deployed to Heroku by this time so I was "done" in the most simple of senses: I could use the publicly accessible bookmark preview (e.g. bookmark for The Da Vinci Code) to print to the Go Free Range Printer backend. After that, apart from making it easier to print (see d84b75) and preview (see 617d24) bookmarks, the remainder of the changes were mainly aesthetic. Pretty simple, huh.

For more information about the Printer platform and how to get involved, checkout any or all of the introductory blog post, the Printer wiki and the Printer platform. For more information about building these sort of content applications see Building Content Services on the wiki.