Versions of ruby deal with shadowing in different ways. Best to avoid it when possible.
Addresses the following warnings:
lib/google/api_client/auth/key_utils.rb:34: warning: shadowing outer local variable - passphrase
lib/google/api_client/auth/key_utils.rb:52: warning: shadowing outer local variable - passphrase
Initialize the variables to avoid the warning.
Addresses the following warnings:
lib/google/api_client/auth/storage.rb:51: warning: instance variable @authorization not initialized
lib/google/api_client/batch.rb:128: warning: instance variable @global_callback not initialized
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.
adding refresh_authorization
write_credentials now using the authorizations methods not the instance variables, Using the instance variables can cause problems.
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