Sprinkle of logging
This commit is contained in:
parent
1601c616fe
commit
1d7315ee9b
|
@ -37,7 +37,7 @@ module Google
|
|||
##
|
||||
# This class manages APIs communication.
|
||||
class APIClient
|
||||
include Google::Logging
|
||||
include Google::APIClient::Logging
|
||||
|
||||
##
|
||||
# Creates a new Google API client.
|
||||
|
@ -71,6 +71,8 @@ module Google
|
|||
# @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
|
||||
|
@ -88,7 +90,7 @@ module Google
|
|||
app_version = options[:application_version]
|
||||
application_string = "#{app_name}/#{app_version || '0.0.0'}"
|
||||
else
|
||||
logger.warn("Please provide :application_name and :application_version when initializing the APIClient")
|
||||
logger.warn { "#{self.class} - Please provide :application_name and :application_version when initializing the client" }
|
||||
end
|
||||
self.user_agent = options[:user_agent] || (
|
||||
"#{application_string} " +
|
||||
|
@ -105,6 +107,7 @@ module Google
|
|||
@discovery_uris = {}
|
||||
@discovery_documents = {}
|
||||
@discovered_apis = {}
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
@ -560,6 +563,7 @@ module Google
|
|||
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
|
||||
|
|
|
@ -13,18 +13,20 @@ module Google
|
|||
|
||||
self.logger = Logger.new(STDOUT)
|
||||
self.logger.level = Logger::WARN
|
||||
|
||||
##
|
||||
# Module to make accessing the logger simpler
|
||||
module Logging
|
||||
##
|
||||
# Logger for the API client
|
||||
#
|
||||
# @return [Logger] logger instance.
|
||||
def logger
|
||||
Google::APIClient.logger
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
##
|
||||
# Module to make accessing the logger simpler
|
||||
module Logging
|
||||
##
|
||||
# Logger for the API client
|
||||
#
|
||||
# @return [Logger] logger instance.
|
||||
def logger
|
||||
Google::APIClient.logger
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -19,6 +19,7 @@ require 'compat/multi_json'
|
|||
require 'addressable/uri'
|
||||
require 'stringio'
|
||||
require 'google/api_client/discovery'
|
||||
require 'google/api_client/logging'
|
||||
|
||||
module Google
|
||||
class APIClient
|
||||
|
@ -26,6 +27,8 @@ module Google
|
|||
##
|
||||
# Represents an API request.
|
||||
class Request
|
||||
include Google::APIClient::Logging
|
||||
|
||||
MULTIPART_BOUNDARY = "-----------RubyApiMultipartPost".freeze
|
||||
|
||||
# @return [Hash] Request parameters
|
||||
|
@ -151,14 +154,19 @@ module Google
|
|||
# @return [Google::APIClient::Result]
|
||||
# result of API request
|
||||
def send(connection)
|
||||
http_response = connection.app.call(self.to_env(connection))
|
||||
env = self.to_env(connection)
|
||||
logger.debug { "#{self.class} Sending API request #{env[:method]} #{env[:url].to_s} #{env[:request_headers]}" }
|
||||
http_response = connection.app.call(env)
|
||||
result = self.process_http_response(http_response)
|
||||
|
||||
logger.debug { "#{self.class} Result: #{result.status} #{result.headers}" }
|
||||
|
||||
# Resumamble slightly different than other upload protocols in that it requires at least
|
||||
# 2 requests.
|
||||
if self.upload_type == 'resumable'
|
||||
upload = result.resumable_upload
|
||||
unless upload.complete?
|
||||
logger.debug { "#{self.class} Sending upload body" }
|
||||
result = upload.send(connection)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,7 +21,7 @@ if !defined?(::Google::APIClient::VERSION)
|
|||
class APIClient
|
||||
module VERSION
|
||||
MAJOR = 0
|
||||
MINOR = 5
|
||||
MINOR = 6
|
||||
TINY = 0
|
||||
STRING = [MAJOR, MINOR, TINY].join('.')
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue