diff --git a/google_ads_config.rb b/google_ads_config.rb index 50c6f7ab..2aa53123 100644 --- a/google_ads_config.rb +++ b/google_ads_config.rb @@ -26,6 +26,12 @@ c.client_secret = 'INSERT_CLIENT_SECRET_HERE' c.refresh_token = 'INSERT_REFRESH_TOKEN_HERE' + # Whether to use the Google Cloud Organization of your Google Cloud + # project instead of developer token to determine your Google Ads API access levels. + # Use this flag only if you are enrolled into a limited pilot that supports + # this configuration. + # c.use_cloud_org_for_api_access = false + # You can also authenticate using a service account. If "keyfile" is # specified below, then service account authentication will be assumed and # the above authentication fields ignored. Read more about service account diff --git a/lib/google/ads/google_ads/config.rb b/lib/google/ads/google_ads/config.rb index c78024a2..36686120 100644 --- a/lib/google/ads/google_ads/config.rb +++ b/lib/google/ads/google_ads/config.rb @@ -32,6 +32,7 @@ class Config attr_accessor :developer_token attr_accessor :login_customer_id attr_accessor :linked_customer_id + attr_accessor :use_cloud_org_for_api_access attr_accessor :log_level attr_accessor :log_target @@ -55,6 +56,7 @@ def initialize(&block) @developer_token = nil @login_customer_id = nil @linked_customer_id = nil + @use_cloud_org_for_api_access = false @log_level = nil @log_target = nil diff --git a/lib/google/ads/google_ads/service_lookup.rb b/lib/google/ads/google_ads/service_lookup.rb index 85829a90..095d703f 100644 --- a/lib/google/ads/google_ads/service_lookup.rb +++ b/lib/google/ads/google_ads/service_lookup.rb @@ -62,9 +62,13 @@ def gax_service_params end def headers - headers = { - :"developer-token" => config.developer_token - } + headers = {} + + # If config.use_cloud_org_for_api_access is not True, add the developer + # token to the request's metadata + if !config.use_cloud_org_for_api_access + headers[:"developer-token"] = config.developer_token + end if config.login_customer_id validate_customer_id(:login_customer_id) diff --git a/test/test_config.rb b/test/test_config.rb index eebc7df6..f8dd28c2 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -61,4 +61,26 @@ def test_configure() assert_equal(client_secret_value, config.client_secret) assert_equal(developer_token_value, config.developer_token) end + + def test_use_cloud_org_for_api_access() + config = Google::Ads::GoogleAds::Config.new + + refresh_token_value = '1234' + client_id_value = 'abcd' + client_secret_value = '!@#$' + use_cloud_org_for_api_access = true + + config.configure do |c| + c.refresh_token = refresh_token_value + c.client_id = client_id_value + c.client_secret = client_secret_value + c.use_cloud_org_for_api_access = true + end + + assert_equal(refresh_token_value, config.refresh_token) + assert_equal(client_id_value, config.client_id) + assert_equal(client_secret_value, config.client_secret) + assert_equal(nil, config.developer_token) + assert_equal(true, config.use_cloud_org_for_api_access) + end end