Skip to content

Commit a654d15

Browse files
authored
Add ads_assistant to metadata headers (#546)
* Add ads_assistant to metadata headers Change-Id: I7998c98776d96365abb5f5babf468fdc1816671d * Small change to header format Change-Id: I9cea682eb3ed7a0a78db106e9d727d10f4fbc719
1 parent 604d064 commit a654d15

5 files changed

Lines changed: 17 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
39.1.0
2+
-----
3+
- Added workaround for gRPC issue affecting metadata headers.
4+
15
39.0.0
26
-----
37
- Compatibility with v23.2 of the API: https://developers.google.com/google-ads/api/docs/release-notes

lib/google/ads/google_ads/interceptors/metadata_interceptor.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ def update_metadata(metadata)
5858
metadata[:"linked-customer-id"] = @linked_customer_id.to_s
5959
end
6060

61-
# The python library iterates over metadata and modifies x-goog-api-client
62-
# Here we can directly access it.
61+
# Update metadata for x-goog-api-client
6362
if metadata.key?(:"x-goog-api-client")
6463
if @ads_assistant
6564
metadata[:"x-goog-api-client"] += " gaada/#{@ads_assistant}"

lib/google/ads/google_ads/service_lookup.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,26 @@ def gax_service_params
7878
# Pass headers as initial metadata here until the upstream fix
7979
# (grpc/grpc#42073) is released.
8080
def headers
81-
h = {}
81+
headers = {}
8282
if config.login_customer_id
8383
validate_customer_id(:login_customer_id)
84-
h[:"login-customer-id"] = config.login_customer_id.to_s
84+
headers[:"login-customer-id"] = config.login_customer_id.to_s
8585
end
8686

8787
if config.linked_customer_id
8888
validate_customer_id(:linked_customer_id)
89-
h[:"linked-customer-id"] = config.linked_customer_id.to_s
89+
headers[:"linked-customer-id"] = config.linked_customer_id.to_s
9090
end
9191

9292
unless config.use_cloud_org_for_api_access
93-
h[:"developer-token"] = config.developer_token if config.developer_token
93+
headers[:"developer-token"] = config.developer_token if config.developer_token
9494
end
9595

96-
h
96+
if config.ads_assistant
97+
headers[:"x-goog-api-client"] = "gaada/#{config.ads_assistant}"
98+
end
99+
100+
headers
97101
end
98102

99103
def validate_customer_id(field)

lib/google/ads/google_ads/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module Google
2020
module Ads
2121
module GoogleAds
2222
CLIENT_LIB_NAME = 'gccl'.freeze
23-
CLIENT_LIB_VERSION = '39.0.0'.freeze
23+
CLIENT_LIB_VERSION = '39.1.0'.freeze
2424
VERSION = CLIENT_LIB_VERSION
2525
end
2626
end

test/test_service_lookup.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ def test_headers_includes_all_when_fully_configured
2929
c.login_customer_id = 1234567890
3030
c.linked_customer_id = 9876543210
3131
c.developer_token = "test-dev-token"
32+
c.ads_assistant = "v0"
3233
end
3334
lookup = create_lookup(config)
3435

3536
headers = lookup.send(:headers)
3637
assert_equal "1234567890", headers[:"login-customer-id"]
3738
assert_equal "9876543210", headers[:"linked-customer-id"]
3839
assert_equal "test-dev-token", headers[:"developer-token"]
40+
assert_equal "gaada/v0", headers[:"x-goog-api-client"]
3941
end
4042

4143
def test_headers_excludes_developer_token_when_cloud_org

0 commit comments

Comments
 (0)