A Google Wave robot container in Sinatra

Since I got a Google Wave account at Google IO, I felt like I should try to do something Ruby-ish in it. I got talking to Charles Nutter, and he suggested a Sinatra template for Wave Robots. So here it is.
I stole shamelessly from Tim Morgan (http://github.com/seven1m) and Sam Ruby (http://github.com/rubys) to make this work. In the end you only have to change one code file, and I think it’s pretty nice! As in the previous blog post on AppEngine, you need to get Jruby and the AppEngine SDK:
http://dist.codehaus.org/jruby/1.3.0RC2/jruby-bin-1.3.0RC2.zip
http://code.google.com/appengine/downloads.html
Grab the Sintra template from github: http://github.com/MikeSofaer/Wave-Robot-Sinatra-Template/tree/master
cd into the war/WEB-INF directory, and edit robot.rb:
class Robot < AbstractRobot
set_name "Sinatra Bot"
add_cron :clock, 20
def DOCUMENT_CHANGED(properties, context)
wavelet = context.GetWavelets[0]
blip = context.GetBlipById(wavelet.GetRootBlipId())
blip.GetDocument.SetText('Only I get to edit the top blip!')
end
def clock(event, context)
wavelet = context.GetWavelets[0]
blip = context.GetBlipById(wavelet.GetRootBlipId())
blip.GetDocument.SetText("It's " + Time.now.to_s)
end
end
Set the app name in appengine-web.xml
appcfg update ..
You are done! The robot will set the time in the root blip, and get very snippy with you if you try to edit it.
Probably the nastiest thing I hit on the way was that jruby-rack likes to take the request body JSON and replace all the + characters with spaces, which in this case was a Very Bad Thing. Eventually I found that you can call request.env['rack.request.form_vars'] to get the original JSON back.
Enjoy!
-
Michael Sofaer
-
paul
-
Tim Inman
-
msofaer
-
Kevin Radcliffe
Hey Clint, Thanks for the comment! I’m definitely hoping to pick up a light and up the production quality soon. Unfortunately I’m using a flip right now, so no mic...
in Why I Was Wrong About Location-Based Services
- Community College (1)
- Design (2)
- Emerging Technologies (30)
- Entrepreneurship in Education (10)
- Facebook in Higher Education (47)
- In The News (22)
- Interoperability in Higher Education (4)
- Lifecycle Engagement (10)
- Privacy and Security (2)
- Product Reviews (6)
- Social Media (39)
- Social Networks in Education (38)
- Thought Leaders (18)



Facebook
Twitter
Flickr
Subscribe
YouTube
SlideShare
LinkedIn
Delicious
Diigo
Newsletters