feat: Support custom quota_project in request options

This commit is contained in:
Daniel Azuma authored and GitHub committed 2020-06-03 13:21:09 -07:00
1 parent ddf80e2dc9
commit 197286a8a7
3 files changed
+25 -9

No files matched your search

+12 -7
View File
@@ -52,12 +52,9 @@ module Google
#
# @return [void]
def prepare!
set_xgac
if options&.authorization.respond_to? :quota_project_id
quota_project_id = options.authorization.quota_project_id
header['X-Goog-User-Project'] = quota_project_id if quota_project_id
end
if options && options.api_format_version
set_api_client_header
set_user_project_header
if options&.api_format_version
header['X-Goog-Api-Format-Version'] = options.api_format_version.to_s
end
query[FIELDS_PARAM] = normalize_fields_param(query[FIELDS_PARAM]) if query.key?(FIELDS_PARAM)
@@ -130,7 +127,7 @@ module Google
private
def set_xgac
def set_api_client_header
old_xgac = header
.find_all { |k, v| k.downcase == 'x-goog-api-client' }
.map { |(a, b)| b }
@@ -144,6 +141,14 @@ module Google
header['X-Goog-Api-Client'] = xgac
end
def set_user_project_header
quota_project_id = options.quota_project
if !quota_project_id && options&.authorization.respond_to?(:quota_project_id)
quota_project_id = options.authorization.quota_project_id
end
header['X-Goog-User-Project'] = quota_project_id if quota_project_id
end
# Attempt to parse a JSON error message
# @param [String] body
# HTTP response body