Showing posts with label http. Show all posts
Showing posts with label http. Show all posts

Tuesday, March 3, 2009

REST Client

Recently I've wanted to access some content from Google Reader. Previously for this I've used both Net::HTTP and Open-URI, both of which work fine. This time, however, I needed to authenticate and grab content from a user account. Open-URI doesn't support the POST method and Net::HTTP seemed like a bit too much work. Enter REST Client:

require 'rest_client'

authresponse=RestClient.post('https://www.google.com/accounts/ClientLogin', :service=>'reader',:Email=>email,:Passwd=>password,:source=>'mreader',:continue=>'http://www.google.com')
if authresponse=~/SID=(.*)/
sid=$1
end

xml=RestClient.get("http://www.google.com/reader/atom/user/-/state/com.google/reading-list", {:Cookie=>"SID=#{sid}"})

As you can see REST Client makes the REST methods GET and POST (also DELETE and PUT) really easy.