@@ -177,10 +177,7 @@ def create_text_asset_operation(
177177 client : GoogleAdsClient , customer_id : str , temp_id : str , text : str
178178) -> MutateOperation :
179179 """Creates a mutate operation for a text asset."""
180- googleads_service = client .get_service ("GoogleAdsService" )
181- operation = client .get_type ("MutateOperation" )
182- asset = operation .asset_operation .create
183- asset .resource_name = googleads_service .asset_path (customer_id , temp_id )
180+ operation , asset = _create_base_asset_operation (client , customer_id , temp_id )
184181 asset .text_asset .text = text
185182 return operation
186183
@@ -193,10 +190,7 @@ def create_image_asset_operation(
193190 name : str ,
194191) -> MutateOperation :
195192 """Creates a mutate operation for an image asset."""
196- googleads_service = client .get_service ("GoogleAdsService" )
197- operation = client .get_type ("MutateOperation" )
198- asset = operation .asset_operation .create
199- asset .resource_name = googleads_service .asset_path (customer_id , temp_id )
193+ operation , asset = _create_base_asset_operation (client , customer_id , temp_id )
200194 asset .name = name
201195 asset .type_ = client .enums .AssetTypeEnum .IMAGE
202196 asset .image_asset .data = get_image_bytes_from_url (url )
@@ -285,6 +279,17 @@ def create_asset_group_asset_operation(
285279 return operation
286280
287281
282+ def _create_base_asset_operation (
283+ client : GoogleAdsClient , customer_id : str , temp_id : str
284+ ) -> Tuple [Any , Any ]:
285+ """Helper to create a base asset mutate operation with a temp ID."""
286+ googleads_service = client .get_service ("GoogleAdsService" )
287+ operation = client .get_type ("MutateOperation" )
288+ asset = operation .asset_operation .create
289+ asset .resource_name = googleads_service .asset_path (customer_id , temp_id )
290+ return operation , asset
291+
292+
288293if __name__ == "__main__" :
289294 parser = argparse .ArgumentParser (
290295 description = "Creates an OPTIMIZE_ASSETS experiment."
0 commit comments