Starting and stopping WEBrick only controls whether the event loop is
running, it does not start and stop listening on TCP sockets.
Our WEBrick server is starting to listen when it is initialised,
so we should ensure that we shut it down when we are done with it.
Note that shutdown is idempotent.
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