google/google-api-ruby-client — pull request #52 by jeffposnick (2013-05-29 19:36:18+00:00)
Title: Added support for caching OAuth 2 credentials to disk

This is a (potentially rough) bit of code to persist OAuth 2
credentials to disk, similar to
http://google-api-python-client.googlecode.com/hg/docs/epy/oauth2client.file.Storage-class.html

It can be used in the following manner, which roughly translates to
what the Python client library code looks like.

file_storage = Google::APIClient::FileStorage.new("#{$0}-oauth2.json")
if file_storage.authorization.nil?
client_secrets = Google::APIClient::ClientSecrets.load
flow = Google::APIClient::InstalledAppFlow.new(
:client_id => client_secrets.client_id,
:client_secret => client_secrets.client_secret,
:scope => [SCOPE1, SCOPE2]
)
client.authorization = flow.authorize(file_storage)
else
client.authorization = file_storage.authorization
end