3636
3737
3838class GoogleAdsHook (BaseHook ):
39- """
40- Hook for the Google Ads API.
39+ """Interact with Google Ads API.
4140
4241 This hook requires two connections:
4342
44- - gcp_conn_id - provides service account details (like any other GCP connection)
45- - google_ads_conn_id - which contains information from Google Ads config.yaml file
46- in the ``extras``. Example of the ``extras``:
43+ - gcp_conn_id - provides service account details (like any other GCP connection)
44+ - google_ads_conn_id - which contains information from Google Ads config.yaml file
45+ in the ``extras``. Example of the ``extras``:
4746
4847 .. code-block:: json
4948
@@ -69,8 +68,6 @@ class GoogleAdsHook(BaseHook):
6968 :param gcp_conn_id: The connection ID with the service account details.
7069 :param google_ads_conn_id: The connection ID with the details of Google Ads config.yaml file.
7170 :param api_version: The Google Ads API version to use.
72-
73- :return: list of Google Ads Row object(s)
7471 """
7572
7673 default_api_version = "v14"
@@ -90,10 +87,10 @@ def __init__(
9087 def search (
9188 self , client_ids : list [str ], query : str , page_size : int = 10000 , ** kwargs
9289 ) -> list [GoogleAdsRow ]:
93- """
94- Pulls data from the Google Ads API and returns it as native protobuf
95- message instances (those seen in versions prior to 10.0.0 of the
96- google-ads library).
90+ """Pull data from the Google Ads API.
91+
92+ Native protobuf message instances are returned (those seen in versions
93+ prior to 10.0.0 of the google-ads library).
9794
9895 This method is for backwards compatibility with older versions of the
9996 google_ads_hook.
@@ -105,7 +102,7 @@ def search(
105102 :param client_ids: Google Ads client ID(s) to query the API for.
106103 :param query: Google Ads Query Language query.
107104 :param page_size: Number of results to return per page. Max 10000.
108- :return: Google Ads API response, converted to Google Ads Row objects
105+ :return: Google Ads API response, converted to Google Ads Row objects.
109106 """
110107 data_proto_plus = self ._search (client_ids , query , page_size , ** kwargs )
111108 data_native_pb = [row ._pb for row in data_proto_plus ]
@@ -115,9 +112,10 @@ def search(
115112 def search_proto_plus (
116113 self , client_ids : list [str ], query : str , page_size : int = 10000 , ** kwargs
117114 ) -> list [GoogleAdsRow ]:
118- """
119- Pulls data from the Google Ads API and returns it as proto-plus-python
120- message instances that behave more like conventional python objects.
115+ """Pull data from the Google Ads API.
116+
117+ Instances of proto-plus-python message are returned, which behave more
118+ like conventional Python objects.
121119
122120 :param client_ids: Google Ads client ID(s) to query the API for.
123121 :param query: Google Ads Query Language query.
@@ -127,12 +125,14 @@ def search_proto_plus(
127125 return self ._search (client_ids , query , page_size , ** kwargs )
128126
129127 def list_accessible_customers (self ) -> list [str ]:
130- """
131- Returns resource names of customers directly accessible by the user authenticating the call.
132- The resulting list of customers is based on your OAuth credentials. The request returns a list
133- of all accounts that you are able to act upon directly given your current credentials. This will
134- not necessarily include all accounts within the account hierarchy; rather, it will only include
135- accounts where your authenticated user has been added with admin or other rights in the account.
128+ """List resource names of customers.
129+
130+ The resulting list of customers is based on your OAuth credentials. The
131+ request returns a list of all accounts that you are able to act upon
132+ directly given your current credentials. This will not necessarily
133+ include all accounts within the account hierarchy; rather, it will only
134+ include accounts where your authenticated user has been added with admin
135+ or other rights in the account.
136136
137137 ..seealso::
138138 https://developers.google.com/google-ads/api/reference/rpc
@@ -152,7 +152,7 @@ def list_accessible_customers(self) -> list[str]:
152152
153153 @cached_property
154154 def _get_service (self ) -> GoogleAdsServiceClient :
155- """Connects and authenticates with the Google Ads API using a service account."""
155+ """Connect and authenticate with the Google Ads API using a service account."""
156156 client = self ._get_client
157157 return client .get_service ("GoogleAdsService" , version = self .api_version )
158158
@@ -170,7 +170,7 @@ def _get_client(self) -> GoogleAdsClient:
170170
171171 @cached_property
172172 def _get_customer_service (self ) -> CustomerServiceClient :
173- """Connects and authenticates with the Google Ads API using a service account."""
173+ """Connect and authenticate with the Google Ads API using a service account."""
174174 with NamedTemporaryFile ("w" , suffix = ".json" ) as secrets_temp :
175175 self ._get_config ()
176176 self ._update_config_with_secret (secrets_temp )
@@ -182,9 +182,10 @@ def _get_customer_service(self) -> CustomerServiceClient:
182182 raise
183183
184184 def _get_config (self ) -> None :
185- """
186- Gets google ads connection from meta db and sets google_ads_config attribute with returned config
187- file.
185+ """Set up Google Ads config from Connection.
186+
187+ This pulls the connections from db, and uses it to set up
188+ ``google_ads_config``.
188189 """
189190 conn = self .get_connection (self .google_ads_conn_id )
190191 if "google_ads_client" not in conn .extra_dejson :
@@ -193,10 +194,11 @@ def _get_config(self) -> None:
193194 self .google_ads_config = conn .extra_dejson ["google_ads_client" ]
194195
195196 def _update_config_with_secret (self , secrets_temp : IO [str ]) -> None :
196- """
197- Gets Google Cloud secret from connection and saves the contents to the temp file
198- Updates google ads config with file path of the temp file containing the secret
199- Note, the secret must be passed as a file path for Google Ads API.
197+ """Set up Google Cloud config secret from Connection.
198+
199+ This pulls the connection, saves the contents to a temp file, and point
200+ the config to the path containing the secret. Note that the secret must
201+ be passed as a file path for Google Ads API.
200202 """
201203 extras = self .get_connection (self .gcp_conn_id ).extra_dejson
202204 secret = get_field (extras , "keyfile_dict" )
@@ -210,8 +212,7 @@ def _update_config_with_secret(self, secrets_temp: IO[str]) -> None:
210212 def _search (
211213 self , client_ids : list [str ], query : str , page_size : int = 10000 , ** kwargs
212214 ) -> list [GoogleAdsRow ]:
213- """
214- Pulls data from the Google Ads API.
215+ """Pull data from the Google Ads API.
215216
216217 :param client_ids: Google Ads client ID(s) to query the API for.
217218 :param query: Google Ads Query Language query.
@@ -231,11 +232,9 @@ def _search(
231232 return self ._extract_rows (iterators )
232233
233234 def _extract_rows (self , iterators : list [GRPCIterator ]) -> list [GoogleAdsRow ]:
234- """
235- Convert Google Page Iterator (GRPCIterator) objects to Google Ads Rows.
235+ """Convert Google Page Iterator (GRPCIterator) objects to Google Ads Rows.
236236
237237 :param iterators: List of Google Page Iterator (GRPCIterator) objects
238-
239238 :return: API response for all clients in the form of Google Ads Row object(s)
240239 """
241240 try :
0 commit comments