lib/googleauth/signet.rb in googleauth-0.7.1 vs lib/googleauth/signet.rb in googleauth-0.8.0
- old
+ new
@@ -36,10 +36,16 @@
# Signet::OAuth2::Client creates an OAuth2 client
#
# This reopens Client to add #apply and #apply! methods which update a
# hash with the fetched authentication token.
class Client
+ def configure_connection(options)
+ @connection_info =
+ options[:connection_builder] || options[:default_connection]
+ self
+ end
+
# Updates a_hash updated with the authentication token
def apply!(a_hash, opts = {})
# fetch the access token there is currently not one, or if the client
# has expired
fetch_access_token!(opts) if access_token.nil? || expires_within?(60)
@@ -64,18 +70,32 @@
@refresh_listeners << block
end
alias orig_fetch_access_token! fetch_access_token!
def fetch_access_token!(options = {})
+ unless options[:connection]
+ connection = build_default_connection
+ options = options.merge(connection: connection) if connection
+ end
info = orig_fetch_access_token!(options)
notify_refresh_listeners
info
end
def notify_refresh_listeners
listeners = @refresh_listeners || []
listeners.each do |block|
block.call(self)
+ end
+ end
+
+ def build_default_connection
+ if !defined?(@connection_info)
+ nil
+ elsif @connection_info.respond_to? :call
+ @connection_info.call
+ else
+ @connection_info
end
end
def retry_with_error(max_retry_count = 5)
retry_count = 0