Skip to content

Commit 3cdf8f9

Browse files
authored
Rename "gaada" setting to "ads_assistant" (#1063)
1 parent 4a5ed2d commit 3cdf8f9

File tree

5 files changed

+316
-231
lines changed

5 files changed

+316
-231
lines changed

google/ads/googleads/client.py

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ def __dir__(self) -> Tuple[str]:
104104

105105
return self._enums
106106

107-
def __getattr__(self, name: str) -> Union[ProtoPlusMessageType, ProtobufMessageType]:
107+
def __getattr__(
108+
self, name: str
109+
) -> Union[ProtoPlusMessageType, ProtobufMessageType]:
108110
"""Dynamically loads the given enum class instance.
109111
110112
Args:
@@ -162,10 +164,10 @@ class GoogleAdsClient:
162164

163165
@classmethod
164166
def copy_from(
165-
cls,
166-
destination: Union[ProtoPlusMessageType, ProtobufMessageType],
167-
origin: Union[ProtoPlusMessageType, ProtobufMessageType]
168-
) -> Union[ProtoPlusMessageType, ProtobufMessageType]:
167+
cls,
168+
destination: Union[ProtoPlusMessageType, ProtobufMessageType],
169+
origin: Union[ProtoPlusMessageType, ProtobufMessageType],
170+
) -> Union[ProtoPlusMessageType, ProtobufMessageType]:
169171
"""Copies protobuf and proto-plus messages into one-another.
170172
171173
This method consolidates the CopyFrom logic of protobuf and proto-plus
@@ -204,7 +206,7 @@ def _get_client_kwargs(cls, config_data: Dict[str, Any]) -> Dict[str, Any]:
204206
"use_cloud_org_for_api_access": config_data.get(
205207
"use_cloud_org_for_api_access"
206208
),
207-
"gaada": config_data.get("gaada"),
209+
"ads_assistant": config_data.get("ads_assistant"),
208210
}
209211

210212
@classmethod
@@ -267,7 +269,9 @@ def load_from_string(
267269
Raises:
268270
ValueError: If the configuration lacks a required field.
269271
"""
270-
config_data: Dict[str, Any] = config.parse_yaml_document_to_dict(yaml_str)
272+
config_data: Dict[str, Any] = config.parse_yaml_document_to_dict(
273+
yaml_str
274+
)
271275
kwargs: Dict[str, Any] = cls._get_client_kwargs(config_data)
272276
return cls(**dict(version=version, **kwargs))
273277

@@ -329,7 +333,7 @@ def __init__(
329333
http_proxy: Union[str, None] = None,
330334
use_proto_plus: bool = False,
331335
use_cloud_org_for_api_access: Union[str, None] = None,
332-
gaada: Union[str, None] = None,
336+
ads_assistant: Union[str, None] = None,
333337
):
334338
"""Initializer for the GoogleAdsClient.
335339
@@ -349,7 +353,7 @@ def __init__(
349353
of developer token to determine your Google Ads API access
350354
levels. Use this flag only if you are enrolled into a limited
351355
pilot that supports this configuration.
352-
gaada: a str specifying the Google Ads API Assistant version.
356+
ads_assistant: a str specifying the Google Ads API Assistant version.
353357
"""
354358
if logging_config:
355359
logging.config.dictConfig(logging_config)
@@ -366,7 +370,7 @@ def __init__(
366370
use_cloud_org_for_api_access
367371
)
368372
self.enums: _EnumGetter = _EnumGetter(self)
369-
self.gaada: Union[str, None] = gaada
373+
self._ads_assistant: Union[str, None] = ads_assistant
370374

371375
# If given, write the http_proxy channel option for GRPC to use
372376
if http_proxy:
@@ -403,9 +407,7 @@ def get_service(
403407
# override any version specified as an argument.
404408
version = self.version if self.version else version
405409
# api_module = self._get_api_services_by_version(version)
406-
services_path: str = (
407-
f"google.ads.googleads.{version}.services.services"
408-
)
410+
services_path: str = f"google.ads.googleads.{version}.services.services"
409411
snaked: str = util.convert_upper_case_to_snake_case(name)
410412
interceptors = interceptors or []
411413

@@ -446,14 +448,14 @@ def get_service(
446448
self.login_customer_id,
447449
self.linked_customer_id,
448450
self.use_cloud_org_for_api_access,
449-
gaada=self.gaada,
451+
ads_assistant=self._ads_assistant,
450452
),
451453
AsyncUnaryStreamMetadataInterceptor(
452454
self.developer_token,
453455
self.login_customer_id,
454456
self.linked_customer_id,
455457
self.use_cloud_org_for_api_access,
456-
gaada=self.gaada,
458+
ads_assistant=self._ads_assistant,
457459
),
458460
AsyncUnaryUnaryLoggingInterceptor(_logger, version, endpoint),
459461
AsyncUnaryStreamLoggingInterceptor(_logger, version, endpoint),
@@ -485,7 +487,7 @@ def get_service(
485487
developer_token=self.developer_token,
486488
login_customer_id=self.login_customer_id,
487489
linked_customer_id=self.linked_customer_id,
488-
use_cloud_org_for_api_access=self.use_cloud_org_for_api_access
490+
use_cloud_org_for_api_access=self.use_cloud_org_for_api_access,
489491
)
490492

491493
return service_client_class(transport=service_transport)
@@ -496,18 +498,21 @@ def get_service(
496498
options=_GRPC_CHANNEL_OPTIONS,
497499
)
498500

499-
interceptors: List[Union[grpc.UnaryUnaryClientInterceptor, grpc.UnaryStreamClientInterceptor]] = interceptors + [
501+
interceptors: List[
502+
Union[
503+
grpc.UnaryUnaryClientInterceptor,
504+
grpc.UnaryStreamClientInterceptor,
505+
]
506+
] = interceptors + [
500507
MetadataInterceptor(
501508
self.developer_token,
502509
self.login_customer_id,
503510
self.linked_customer_id,
504511
self.use_cloud_org_for_api_access,
505-
gaada=self.gaada,
512+
ads_assistant=self._ads_assistant,
506513
),
507514
LoggingInterceptor(_logger, version, endpoint),
508-
ExceptionInterceptor(
509-
version, use_proto_plus=self.use_proto_plus
510-
),
515+
ExceptionInterceptor(version, use_proto_plus=self.use_proto_plus),
511516
]
512517

513518
channel: grpc.Channel = grpc.intercept_channel(channel, *interceptors)
@@ -525,12 +530,14 @@ def get_service(
525530
developer_token=self.developer_token,
526531
login_customer_id=self.login_customer_id,
527532
linked_customer_id=self.linked_customer_id,
528-
use_cloud_org_for_api_access=self.use_cloud_org_for_api_access
533+
use_cloud_org_for_api_access=self.use_cloud_org_for_api_access,
529534
)
530535

531536
return service_client_class(transport=service_transport)
532537

533-
def get_type(self, name: str, version: str = _DEFAULT_VERSION) -> Union[ProtoPlusMessageType, ProtobufMessageType]:
538+
def get_type(
539+
self, name: str, version: str = _DEFAULT_VERSION
540+
) -> Union[ProtoPlusMessageType, ProtobufMessageType]:
534541
"""Returns the specified common, enum, error, or resource type.
535542
536543
Args:

google/ads/googleads/config.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from typing import Any, Callable, List, Tuple, TypeVar, Union
2222
import yaml
2323

24-
2524
_logger = logging.getLogger(__name__)
2625

2726

@@ -35,7 +34,7 @@
3534
"http_proxy",
3635
"use_cloud_org_for_api_access",
3736
"use_application_default_credentials",
38-
"gaada",
37+
"ads_assistant",
3938
)
4039
_CONFIG_FILE_PATH_KEY = ("configuration_file_path",)
4140
_OAUTH2_INSTALLED_APP_KEYS = ("client_id", "client_secret", "refresh_token")
@@ -96,7 +95,9 @@ def parser_wrapper(*args: Any, **kwargs: Any) -> Any:
9695
parsed_config: dict[str, Any] = convert_login_customer_id_to_str(
9796
config_dict
9897
)
99-
parsed_config: dict[str, Any] = convert_linked_customer_id_to_str(parsed_config)
98+
parsed_config: dict[str, Any] = convert_linked_customer_id_to_str(
99+
parsed_config
100+
)
100101

101102
config_keys: List[str] = parsed_config.keys()
102103

@@ -106,7 +107,9 @@ def parser_wrapper(*args: Any, **kwargs: Any) -> Any:
106107
# that needs to be returned by this method.
107108
if type(logging_config) is not dict:
108109
try:
109-
parsed_config["logging"]: dict[str, Any] = json.loads(logging_config)
110+
parsed_config["logging"]: dict[str, Any] = json.loads(
111+
logging_config
112+
)
110113
# The logger is configured here in case deprecation warnings
111114
# need to be logged further down in this method. The logger
112115
# is otherwise configured by the GoogleAdsClient class.
@@ -159,7 +162,9 @@ def parser_wrapper(*args: Any, **kwargs: Any) -> Any:
159162
# the string "False" is truthy and can easily be incorrectly
160163
# converted to the boolean True.
161164
value: Union[str, bool] = parsed_config.get("use_proto_plus", False)
162-
parsed_config["use_proto_plus"]: bool = disambiguate_string_bool(value)
165+
parsed_config["use_proto_plus"]: bool = disambiguate_string_bool(
166+
value
167+
)
163168

164169
if "use_application_default_credentials" in config_keys:
165170
# When loaded from YAML, YAML string or a dict, this value is
@@ -168,8 +173,12 @@ def parser_wrapper(*args: Any, **kwargs: Any) -> Any:
168173
# variable we need to manually change it to the bool False because
169174
# the string "False" is truthy and can easily be incorrectly
170175
# converted to the boolean True.
171-
value: Union[str, bool] = parsed_config.get("use_application_default_credentials", False)
172-
parsed_config["use_application_default_credentials"]: bool = disambiguate_string_bool(value)
176+
value: Union[str, bool] = parsed_config.get(
177+
"use_application_default_credentials", False
178+
)
179+
parsed_config["use_application_default_credentials"]: bool = (
180+
disambiguate_string_bool(value)
181+
)
173182

174183
return parsed_config
175184

@@ -380,7 +389,7 @@ def get_oauth2_required_service_account_keys() -> tuple[str, ...]:
380389

381390

382391
def convert_login_customer_id_to_str(
383-
config_data: dict[str, Any]
392+
config_data: dict[str, Any],
384393
) -> dict[str, Any]:
385394
"""Parses a config dict's login_customer_id attr value to a str.
386395
@@ -403,7 +412,7 @@ def convert_login_customer_id_to_str(
403412

404413

405414
def convert_linked_customer_id_to_str(
406-
config_data: dict[str, Any]
415+
config_data: dict[str, Any],
407416
) -> dict[str, Any]:
408417
"""Parses a config dict's linked_customer_id attr value to a str.
409418

google/ads/googleads/interceptors/metadata_interceptor.py

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@
3030
from google.protobuf.message import Message as ProtobufMessageType
3131
import grpc
3232

33-
from google.ads.googleads.interceptors import Interceptor, MetadataType, ContinuationType
34-
33+
from google.ads.googleads.interceptors import (
34+
Interceptor,
35+
MetadataType,
36+
ContinuationType,
37+
)
3538

3639
# Determine which version of the package is installed.
3740
try:
@@ -47,20 +50,21 @@
4750
else:
4851
_PB_IMPL_HEADER = ""
4952

53+
5054
class MetadataInterceptor(
5155
Interceptor,
5256
grpc.UnaryUnaryClientInterceptor,
53-
grpc.UnaryStreamClientInterceptor
57+
grpc.UnaryStreamClientInterceptor,
5458
):
5559
"""An interceptor that appends custom metadata to requests."""
5660

5761
def __init__(
5862
self,
5963
developer_token: str,
60-
login_customer_id: Optional[str]= None,
64+
login_customer_id: Optional[str] = None,
6165
linked_customer_id: Optional[str] = None,
6266
use_cloud_org_for_api_access: Optional[bool] = None,
63-
gaada: Optional[str] = None,
67+
ads_assistant: Optional[str] = None,
6468
):
6569
"""Initialization method for this class.
6670
@@ -73,7 +77,7 @@ def __init__(
7377
of developer token to determine your Google Ads API access
7478
levels. Use this flag only if you are enrolled into a limited
7579
pilot that supports this configuration
76-
gaada: a str specifying the Google Ads API Assistant version.
80+
ads_assistant: a str specifying the Google Ads API Assistant version.
7781
"""
7882
self.developer_token_meta: Tuple[str, str] = (
7983
"developer-token",
@@ -89,13 +93,15 @@ def __init__(
8993
if linked_customer_id
9094
else None
9195
)
92-
self.gaada: Optional[str] = gaada
93-
self.use_cloud_org_for_api_access: Optional[
94-
bool
95-
] = use_cloud_org_for_api_access
96+
self.ads_assistant: Optional[str] = ads_assistant
97+
self.use_cloud_org_for_api_access: Optional[bool] = (
98+
use_cloud_org_for_api_access
99+
)
96100

97101
def _update_client_call_details_metadata(
98-
self, client_call_details: grpc.ClientCallDetails, metadata: MetadataType
102+
self,
103+
client_call_details: grpc.ClientCallDetails,
104+
metadata: MetadataType,
99105
):
100106
"""Updates the client call details with additional metadata.
101107
@@ -107,12 +113,14 @@ def _update_client_call_details_metadata(
107113
An new instance of grpc.ClientCallDetails with additional metadata
108114
from the GoogleAdsClient.
109115
"""
110-
client_call_details: grpc.ClientCallDetails = self.get_client_call_details_instance(
111-
client_call_details.method,
112-
client_call_details.timeout,
113-
metadata,
114-
client_call_details.credentials,
115-
getattr(client_call_details, "wait_for_ready", None),
116+
client_call_details: grpc.ClientCallDetails = (
117+
self.get_client_call_details_instance(
118+
client_call_details.method,
119+
client_call_details.timeout,
120+
metadata,
121+
client_call_details.credentials,
122+
getattr(client_call_details, "wait_for_ready", None),
123+
)
116124
)
117125

118126
return client_call_details
@@ -158,16 +166,18 @@ def _intercept(
158166
if "x-goog-api-client" in metadatum_tuple:
159167
metadatum: List[str] = list(metadatum_tuple)
160168

161-
if self.gaada:
162-
metadatum[1] += f" gaada/{self.gaada}"
169+
if self.ads_assistant:
170+
metadatum[1] += f" gaada/{self.ads_assistant}"
163171

164172
if _PROTOBUF_VERSION:
165173
# Convert the tuple to a list so it can be modified.
166174
# Check that "pb" isn't already included in the user agent.
167175
if "pb" not in metadatum[1]:
168176
# Append the protobuf version key value pair to the end of
169177
# the string.
170-
metadatum[1] += f" pb/{_PROTOBUF_VERSION}{_PB_IMPL_HEADER}"
178+
metadatum[
179+
1
180+
] += f" pb/{_PROTOBUF_VERSION}{_PB_IMPL_HEADER}"
171181
# Convert the metadatum back to a tuple.
172182
metadatum_tuple: Tuple[str, str] = tuple(metadatum)
173183

@@ -177,9 +187,10 @@ def _intercept(
177187
# Exit the loop since we already found the user agent.
178188
break
179189

180-
181-
client_call_details: grpc.ClientCallDetails = self._update_client_call_details_metadata(
182-
client_call_details, metadata
190+
client_call_details: grpc.ClientCallDetails = (
191+
self._update_client_call_details_metadata(
192+
client_call_details, metadata
193+
)
183194
)
184195

185196
return continuation(client_call_details, request)
@@ -229,9 +240,7 @@ def intercept_unary_stream(
229240
return self._intercept(continuation, client_call_details, request)
230241

231242

232-
class _AsyncMetadataInterceptor(
233-
MetadataInterceptor
234-
):
243+
class _AsyncMetadataInterceptor(MetadataInterceptor):
235244
"""An interceptor that appends custom metadata to requests."""
236245

237246
async def _intercept(
@@ -340,20 +349,23 @@ async def intercept_unary_stream(
340349
"""
341350
return await self._intercept(continuation, client_call_details, request)
342351

352+
343353
class AsyncUnaryUnaryMetadataInterceptor(
344354
_AsyncMetadataInterceptor,
345355
grpc.aio.UnaryUnaryClientInterceptor,
346356
):
347357
"""An interceptor that appends custom metadata to Unary-Unary requests."""
348358

359+
349360
class AsyncUnaryStreamMetadataInterceptor(
350361
_AsyncMetadataInterceptor,
351362
grpc.aio.UnaryStreamClientInterceptor,
352363
):
353364
"""An interceptor that appends custom metadata to Unary-Stream requests."""
354365

366+
355367
__all__ = [
356368
"MetadataInterceptor",
357369
"AsyncUnaryUnaryMetadataInterceptor",
358370
"AsyncUnaryStreamMetadataInterceptor",
359-
]
371+
]

0 commit comments

Comments
 (0)