Skip to content

Commit

Permalink
feat(core): Munge reported client version so backends can recognize s…
Browse files Browse the repository at this point in the history
…plit clients
  • Loading branch information
dazuma authored Jan 1, 2021
1 parent 1e2aeae commit abb3c96
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions google-apis-core/lib/google/apis/core/api_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ApiCommand < HttpCommand
# Request body
def initialize(method, url, body: nil, client_version: nil)
super(method, url, body: body)
self.client_version = client_version || '0.0'
self.client_version = client_version || Core::VERSION
end

# Serialize the request body
Expand Down Expand Up @@ -151,7 +151,14 @@ def set_api_client_header
.split
.find_all { |s| s !~ %r{^gl-ruby/|^gdcl/} }
.join(' ')
xgac = "gl-ruby/#{RUBY_VERSION} gdcl/#{client_version}"
# Report 0.x.y versions that are in separate packages as 1.x.y.
# Thus, reported gdcl/0.x.y versions are monopackage clients, while
# reported gdcl/1.x.y versions are split clients.
# In the unlikely event that we want to release post-1.0 versions of
# these clients, we should start the versioning at 2.0 to avoid
# confusion.
munged_client_version = client_version.sub(/^0\./, "1.")
xgac = "gl-ruby/#{RUBY_VERSION} gdcl/#{munged_client_version}"
xgac = old_xgac.empty? ? xgac : "#{old_xgac} #{xgac}"
header.delete_if { |k, v| k.downcase == 'x-goog-api-client' }
header['X-Goog-Api-Client'] = xgac
Expand Down

0 comments on commit abb3c96

Please sign in to comment.