zaterdag 4 juli 2009

Google Wave & Sakai: Exchanging data

Over the last weeks I have been able to spend some time on my Google Wave endeavor. In my last blog I wrote about embedding GW in a Sakai environment which was a simple example of how this could be done. However, I wanted to do more. So I took a deep dive into sometimes turbulent waters of coding. Remember I didn't code for quite some time but GW makes me want to code again. I wanted to see if I could exchange data between GW and Sakai. That would make it much cooler.
So I started to code my first Python lines, learned bout JSON, took a close look at the entity broker of Sakai, wandered through Google's App Engine and did some serious reading on the GW API's.
The fact that GW doesn't have a SDK (yet) with which you can develop on your own computer. Every time I had new or adjusted code I had to upload it to App Engine.

This is what I did. I have written a robot of approx 80 lines of (Python) code which runs on App Engine. First it authenticates, second it retrieves site information and third it adds a poll to a Sakai site.

Code authentication:

"""define login url for Sakai"""
host = "http://qa1-nl.sakaiproject.org"
loginurl = "/portal/xlogin"
url = host+loginurl

form_data = urllib.urlencode({'eid':'','pw':''})
f = opener.open(url, form_data)
data = f.read()
f.close()


This is just Python code and it authenticates me on a Sakai server which runs 2.5.3. btw.

Now I wanted to retrieve site information out of Sakai. RESTful & JSON are my big friends here.


"""Get sit info"""
jsonsiteurl="/direct/site.json"
url = host + jsonsiteurl
f = opener.open(url)
data = f.read()
f.close()

result = simplejson.loads(data)
mylist = result.get('site_collection')

for outerlist in mylist:
for innerlist in outerlist:
blip.GetDocument().AppendText(simplejson.dumps(outerlist.get(innerlist)))


It uses the url "/direct/site.json". Since I'm already logged on it shows the sites I'm enrolled in. I load my data into 'result' and treat it as a JSON message. I want to get all the data that has the key 'site_collection' and let go through a 'for' loop. Last line I print the results. This last line is the first GW code that we encounter. For purposes of this short explanation it is important to know that this appends text to content which already exists in the blip.

Now that we have retrieve some data I wanted to post some data from GW into Sakai. I added a new Poll to my site.


pollurl = "/direct/poll/new"
url = host + pollurl

form_data = urllib.urlencode({
"text": "What do you think of Google Wave?",
"owner": "fbc345bd-8ef0-4060-90fd-4fb2fa028961",
"siteId": "5ab7c822-ccd6-4568-ab8b-deeb3b63630c",
"pollText": "What do you think of Google Wave?"})
f = opener.open(url,form_data)
f.close()


I use JSON again by posting to '/direct/poll/new' with the data for the poll.

What I wanted to check with this robot is how difficult it would be to post and get data between Google Wave and Sakai. It is pretty easy with the use of JSON messages. I don't have to know anything how Sakai handles its stuff internally. All I have to do is to call the url which handles the stuff for me.
So I have my first robot which I called 'Saky' (seems to be the naming convention of GW robots) for the moment and I can upload it to my app-engine.

So what's next? From now on I want to focus on Sakai K2. I think Sling is a wonderful technological solution and it makes me wonder how we could integrate this new kernel with Google Wave. To be continued....

I want to thank Alan Berg for helping me with some Python stuff. I want thank Chuck Severance for writing a book about the App Engine. It really helps! And I want to thank Aaron Zeckoski for thinking along why my handling of JSON messages got messed up which turned out to be a local problem on my Mac.

2 reacties:

上課 zei

great ...........................................................

停止 zei

不勞而獲的事情,並沒有價值........................................

Een reactie plaatsen