From d70e75be7b8cd0dede39f8c84798e43b1a0fcabb Mon Sep 17 00:00:00 2001 From: bryantgray Date: Tue, 22 Mar 2022 10:32:07 -0400 Subject: [PATCH] Update to v10 (#35) * Update client library to 15.0.0 to allow for use of api version 10 and use v10 * Remove resource_name from every response using v10 api parameter * Fix unittests --- setup.py | 2 +- tap_google_ads/discover.py | 2 -- tap_google_ads/streams.py | 15 ++++++++++++--- tests/unittests/test_conversion_window.py | 7 ++++--- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/setup.py b/setup.py index ebdd870..c80439e 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ 'singer-python==5.12.2', 'requests==2.26.0', 'backoff==1.8.0', - 'google-ads==14.1.0', + 'google-ads==15.0.0', 'protobuf==3.17.3', ], extras_require= { diff --git a/tap_google_ads/discover.py b/tap_google_ads/discover.py index aaa6646..5a5286d 100644 --- a/tap_google_ads/discover.py +++ b/tap_google_ads/discover.py @@ -7,8 +7,6 @@ from tap_google_ads.streams import initialize_core_streams from tap_google_ads.streams import initialize_reports -API_VERSION = "v9" - LOGGER = singer.get_logger() REPORTS = [ diff --git a/tap_google_ads/streams.py b/tap_google_ads/streams.py index c7ab677..b3c596b 100644 --- a/tap_google_ads/streams.py +++ b/tap_google_ads/streams.py @@ -12,7 +12,11 @@ LOGGER = singer.get_logger() -API_VERSION = "v9" +API_VERSION = "v10" + +API_PARAMETERS = { + "omit_unselected_resource_names": "true" +} REPORTS_WITH_90_DAY_MAX = frozenset( [ @@ -72,8 +76,13 @@ def get_selected_fields(stream_mdata): return selected_fields +def build_parameters(): + param_str = ",".join(f"{k}={v}" for k, v in API_PARAMETERS.items()) + return f"PARAMETERS {param_str}" + + def create_core_stream_query(resource_name, selected_fields): - core_query = f"SELECT {','.join(selected_fields)} FROM {resource_name}" + core_query = f"SELECT {','.join(selected_fields)} FROM {resource_name} {build_parameters()}" return core_query @@ -81,7 +90,7 @@ def create_report_query(resource_name, selected_fields, query_date): format_str = "%Y-%m-%d" query_date = utils.strftime(query_date, format_str=format_str) - report_query = f"SELECT {','.join(selected_fields)} FROM {resource_name} WHERE segments.date = '{query_date}'" + report_query = f"SELECT {','.join(selected_fields)} FROM {resource_name} WHERE segments.date = '{query_date}' {build_parameters()}" return report_query diff --git a/tests/unittests/test_conversion_window.py b/tests/unittests/test_conversion_window.py index 2e732af..e1b65a9 100644 --- a/tests/unittests/test_conversion_window.py +++ b/tests/unittests/test_conversion_window.py @@ -1,3 +1,4 @@ +import re import unittest from datetime import datetime from datetime import timedelta @@ -78,7 +79,7 @@ def execute(self, conversion_window, fake_make_request): # Verify the first date queried is the conversion window date (not the bookmark) expected_first_query_date = str(end_date - timedelta(days=conversion_window))[:10] - actual_first_query_date = str(all_queries_requested[0])[-11:-1] + actual_first_query_date = re.search(r'\d\d\d\d-\d\d-\d\d', all_queries_requested[0]).group() self.assertEqual(expected_first_query_date, actual_first_query_date) # Verify the number of days queried is based off the conversion window. @@ -152,7 +153,7 @@ def execute(self, conversion_window, fake_make_request): # Verify the first date queried is the conversion window date / bookmark expected_first_query_date = str(bookmark_value)[:10] - actual_first_query_date = str(all_queries_requested[0])[-11:-1] + actual_first_query_date = re.search(r'\d\d\d\d-\d\d-\d\d', all_queries_requested[0]).group() self.assertEqual(expected_first_query_date, actual_first_query_date) # Verify the number of days queried is based off the conversion window. @@ -222,7 +223,7 @@ def execute(self, conversion_window, fake_make_request): # Verify the first date queried is the conversion window date (not the bookmark) expected_first_query_date = str(start_date)[:10] - actual_first_query_date = str(all_queries_requested[0])[-11:-1] + actual_first_query_date = re.search(r'\d\d\d\d-\d\d-\d\d', all_queries_requested[0]).group() self.assertEqual(expected_first_query_date, actual_first_query_date) # Verify the number of days queried is based off the start_date