Main Content

Ruby to access web services

Archive - Originally posted on "The Horse's Mouth" - 2008-11-16 17:03:30 - Graham Ellis

If you want to use a Ruby program to access an RSS feed (or some other XML or HTML data), you can start with the standard Net::HTTP module ... full (working, tested) example here. That example "just" uses a Get method to get an RSS feed of the latest posts to the First Great Western Coffee Shop Forum - but you could easily tune it for other automated browsing.

If you take a look at the documentation for the class, you'll see it's straightforward to access data via the POST method too ... although it does require some background knowledge which we would love to teach you (if you don't know it ;-) ) on our Ruby Programming Course




I've been teaching Ruby over this weekend ... you may have guessed that, having seen the flurry of extra examples and tips posted, and I'm going to add in links to a final few examples here:

Ruby data formatting with the % operator / printf / sprintf

Ruby and $_, the -n option, topicalisation, etc)

Yield in Ruby or how to have two pieces of code passing data back and forth like generators in Python