require 'stringio'
require 'google/api_client/version'
+require 'google/api_client/logging'
require 'google/api_client/errors'
require 'google/api_client/environment'
require 'google/api_client/discovery'
require 'google/api_client/media'
require 'google/api_client/service_account'
require 'google/api_client/batch'
+require 'google/api_client/railtie' if defined?(Rails)
module Google
+
##
# This class manages APIs communication.
class APIClient
+ include Google::APIClient::Logging
+
##
# Creates a new Google API client.
#
# @option options [String] :discovery_path ("/discovery/v1")
# The discovery base path. This rarely needs to be changed.
def initialize(options={})
+ logger.debug { "#{self.class} - Initializing client with options #{options}" }
+
# Normalize key to String to allow indifferent access.
options = options.inject({}) do |accu, (key, value)|
accu[key.to_sym] = value
# Most developers will want to leave this value alone and use the
# application_name option.
- application_string = (
- options[:application_name] ? (
- "#{options[:application_name]}/" +
- "#{options[:application_version] || '0.0.0'}"
- ) : ""
- )
+ if options[:application_name]
+ app_name = options[:application_name]
+ app_version = options[:application_version]
+ application_string = "#{app_name}/#{app_version || '0.0.0'}"
+ else
+ logger.warn { "#{self.class} - Please provide :application_name and :application_version when initializing the client" }
+ end
self.user_agent = options[:user_agent] || (
"#{application_string} " +
- "google-api-ruby-client/#{VERSION::STRING} " +
+ "google-api-ruby-client/#{Google::APIClient::VERSION::STRING} " +
ENV::OS_VERSION
).strip
# The writer method understands a few Symbols and will generate useful
@discovery_uris = {}
@discovery_documents = {}
@discovered_apis = {}
+
return self
end
result = request.send(connection)
if result.status == 401 && authorization.respond_to?(:refresh_token) && auto_refresh_token
begin
+ logger.debug("Attempting refresh of access token & retry of request")
authorization.fetch_access_token!
result = request.send(connection)
rescue Signet::AuthorizationError