Skip to content

Commit

Permalink
Support for use_cloud_org_for_api_access (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfrg authored Nov 14, 2023
1 parent 426333c commit 50d0c9d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
6 changes: 6 additions & 0 deletions google_ads_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/google/ads/google_ads/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 7 additions & 3 deletions lib/google/ads/google_ads/service_lookup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions test/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 50d0c9d

Please sign in to comment.