In this article we will demonstrate a technique used to automatically add Wiki Pages to PBWiki using
the not quite released API provided by the peanut butter guys. The demonstration will involve integrating scheduled presentations at our Silicon Valley Code Camp on October 7th and 8th each with its own Wiki Page. Without the API, creating and linking the presentation to a Wiki page would have to be an ugly manual process involving the dreaded cut and pasting of URL’s.
So, to begin with, I’m an enterprise database kind of guy and to be frank, Wiki’s scare me a little. The
idea of adhoc data being deposited by anyone onto a page with no real structures just makes me nervous. My
smart friends tell me I should embrace the chaos so I’m trusting them and going for it.
That being said, the specific problem we want to address with the Wiki is to allow presenters and presentees at
our codecamp to be able to interact with each other before and after their presentations. My experience is that
discussion groups don’t work that well for this and though lotus notes may have, that doesn’t seem to be much of an
option these days (Where is Ray?). The now obvious solution is to attach a Wiki Page to each presentation on our web
site and let users and presenters have at it. The problem is that this event is free and we don’t have an army
of staffers ready to add Wiki Pages each time someone submits a new presentation.
PBWiki To The Rescue
Turns out the guys at PBWiki are just about to release an API for their software. One of the functions of this API allows us
to create a new Wiki Page simply by building a request with post data as our page. Just what we need. So, lets just go through the steps with some fancy pictures and arrows of how we built this integration. (OK, no arrows, just pictures).
First, lets take a look at how we’ve enhanced our web site. (OK, this is in beta so depending on how fast you are at reading this article, the web site might not be quite to production yet. You will need to use your imagination.)
Notice the Wiki hyperlink next to the Session Titles. When this hyperlink is pressed, an API call is generated to the PBWiki API calling the AddPage function. If the Wiki Page exists, it simply quietly fails. Then after that, a redirect is processed that takes the user directly to the new Wiki Page. First time, the Wiki page is created with all kinds of information about the session as well as any other information we might want to transfer over. Below is what the Wiki Page looks like on our CodeCamp Wiki.
So, how did we do this? First, we got an API key from PBWiki. this is a huge 15 character or so alpha string that identifies your wiki so that when you use it, pages and such will be created on your wiki. Then, we had to write some code. Basically, the way the API works is that you build a request that looks something like this to add a page.
Then, you add some post data to the request (or for small pages you can use the data parameter). Execute the request and your response is that status of the request. It’s returned in JSON format. Hopefully, you have your page now.
After that, you simply issue a redirect to the newly create page.
Now, you are probably wondering, where is the .Net API for doing this? OK, I’ll put some code below to satisfy that
wonderment. Basically, I created a very small API (1 call, AddPage), and a simple aspx page to run it. Here it is, and good
luck. Overtime, I’m sure I’ll fill out the API and add real error checking and better return type stuff. But, for now, here it is.
The Sample ASP.NET aspx Page that calls this
This is very cool stuff. It opens up a huge area of how to synchronize (or somewhat synchronize) blog data and more structured
data from things like databases (what a concept!). I’m sure as time goes on, I’ll do much more sophisticated integration with
Wiki data then is shown here. I’m totally jazzed by this.