Using Ruby to work with the Google Spreadsheets API
April 13th, 2008 | Published in Google Code
I've recently started to explore using Ruby as an all-purpose tool for scripting and programming small tasks. Seeing requests for Ruby code samples inspired me to write this article, which will hopefully help other developers get started using Ruby to access the Google Data API services.
The article explores the Spreadsheets API from within irb, Ruby's interactive shell. We explore performing basic GET, POST and PUT requests and finish by writing a sample method to perform batch updates.
All of the sample code has also been added to a Google Code Project which contains a class that can be used to perform various operations such as authentication, as shown here:
def authenticate(email, password)
http = Net::HTTP.new('www.google.com', 443)
http.use_ssl = true
path = '/accounts/ClientLogin'
data = "accountType=HOSTED_OR_GOOGLE&Email=#{email}" \
"&Passwd=#{password}&service=wise"
@headers = { 'Content-Type' => CONTENT_TYPE_FORM }
resp, data = http.post(path, data, headers)
cl_string = data[/Auth=(.*)/, 1]
@headers["Authorization"] = "GoogleLogin auth=#{cl_string}"
end
Find out more by reading the article: Using Ruby with the Google Data APIs.
If you want to share your experiences using Ruby with the Google Data APIs or express your opinions on the article, please join the discussion on the Documents List and Spreadsheets API group wiki page.