From df9a5b50e754bef6517c1e965048415cd1b64c0a Mon Sep 17 00:00:00 2001 From: danielpdwalker Date: Mon, 5 Dec 2022 11:16:50 +0000 Subject: [PATCH 1/3] Updated tap to use V12 of Google Ads api. Removed CustomerStream as endpoint is deprecated --- tap_googleads/client.py | 2 +- tap_googleads/streams.py | 21 ++------------------- tap_googleads/tap.py | 2 -- 3 files changed, 3 insertions(+), 22 deletions(-) diff --git a/tap_googleads/client.py b/tap_googleads/client.py index 99b9721..305d8e8 100644 --- a/tap_googleads/client.py +++ b/tap_googleads/client.py @@ -24,7 +24,7 @@ class GoogleAdsStream(RESTStream): """GoogleAds stream class.""" - url_base = "https://googleads.googleapis.com/v9" + url_base = "https://googleads.googleapis.com/v12" records_jsonpath = "$[*]" # Or override `parse_response`. next_page_token_jsonpath = "$.nextPageToken" # Or override `get_next_page_token`. diff --git a/tap_googleads/streams.py b/tap_googleads/streams.py index 357f2e1..f5fbd68 100644 --- a/tap_googleads/streams.py +++ b/tap_googleads/streams.py @@ -14,19 +14,6 @@ # - Copy-paste as many times as needed to create multiple stream types. -class CustomerStream(GoogleAdsStream): - """Define custom stream.""" - - @property - def path(self): - return "/customers/" + self.config["customer_id"] - - name = "stream_customers" - primary_keys = ["id"] - replication_key = None - schema_filepath = SCHEMAS_DIR / "customer.json" - - class AccessibleCustomers(GoogleAdsStream): """Accessible Customers""" @@ -34,8 +21,6 @@ class AccessibleCustomers(GoogleAdsStream): name = "stream_accessible_customers" primary_keys = ["resource_names"] replication_key = None - # TODO add an assert for one record - # schema_filepath = SCHEMAS_DIR / "customer.json" schema = th.PropertiesList( th.Property("resourceNames", th.ArrayType(th.StringType)) ).to_dict() @@ -55,13 +40,12 @@ class CustomerHierarchyStream(GoogleAdsStream): """ - # TODO add a seperate stream to get the Customer information and return i rest_method = "POST" @property def path(self): # Paramas - path = "/customers/{client_id}" + path = f"/customers/{self.config.get('customer_id')}" path = path + "/googleAds:search" path = path + "?pageSize=10000" path = path + f"&query={self.gaql}" @@ -117,7 +101,6 @@ def get_records(self, context: Optional[dict]) -> Iterable[Dict[str, Any]]: One item per (possibly processed) record in the API. """ - context["client_id"] = self.config.get("customer_id") for row in self.request_records(context): row = self.post_process(row, context) # Don't search Manager accounts as we can't query them for everything @@ -166,7 +149,7 @@ def gaql(self): @property def path(self): # Paramas - path = "/customers/{client_id}" + path = f"/customers/{self.config.get('customer_id')}" path = path + "/googleAds:search" path = path + "?pageSize=10000" path = path + f"&query={self.gaql}" diff --git a/tap_googleads/tap.py b/tap_googleads/tap.py index 29f6ad5..9a78714 100644 --- a/tap_googleads/tap.py +++ b/tap_googleads/tap.py @@ -6,7 +6,6 @@ from singer_sdk import typing as th # JSON schema typing helpers from tap_googleads.streams import ( - CustomerStream, CampaignsStream, AdGroupsStream, AdGroupsPerformance, @@ -20,7 +19,6 @@ ) STREAM_TYPES = [ - CustomerStream, CampaignsStream, AdGroupsStream, AdGroupsPerformance, From 0a0f70cec682531f69d54a8b381722bb1b067d8a Mon Sep 17 00:00:00 2001 From: danielpdwalker Date: Mon, 5 Dec 2022 11:17:19 +0000 Subject: [PATCH 2/3] Updates unittests with new total of stream expected and v12 instead of v9 in urls --- tap_googleads/tests/test_base_credentials.py | 4 ++-- tap_googleads/tests/test_proxy_oauth.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tap_googleads/tests/test_base_credentials.py b/tap_googleads/tests/test_base_credentials.py index 1e99656..86139a1 100644 --- a/tap_googleads/tests/test_base_credentials.py +++ b/tap_googleads/tests/test_base_credentials.py @@ -33,7 +33,7 @@ def test_base_credentials_discovery(self): catalog = TapGoogleAds(self.mock_config).discover_streams() # expect valid catalog to be discovered - self.assertEqual(len(catalog), 11, "Total streams from default catalog") + self.assertEqual(len(catalog), 10, "Total streams from default catalog") @responses.activate def test_googleads_sync_accessible_customers(self): @@ -53,7 +53,7 @@ def test_googleads_sync_accessible_customers(self): responses.add( responses.GET, - "https://googleads.googleapis.com/v9/customers:listAccessibleCustomers", + "https://googleads.googleapis.com/v12/customers:listAccessibleCustomers", json=test_utils.accessible_customer_return_data, status=200, ) diff --git a/tap_googleads/tests/test_proxy_oauth.py b/tap_googleads/tests/test_proxy_oauth.py index 28b6d71..480bc66 100644 --- a/tap_googleads/tests/test_proxy_oauth.py +++ b/tap_googleads/tests/test_proxy_oauth.py @@ -32,7 +32,7 @@ def test_proxy_oauth_discovery(self): catalog = TapGoogleAds(self.mock_config).discover_streams() # Assert the correct number of default streams found - self.assertEqual(len(catalog), 11, "Total streams from default catalog") + self.assertEqual(len(catalog), 10, "Total streams from default catalog") @responses.activate def test_proxy_oauth_refresh(self): @@ -51,7 +51,7 @@ def test_proxy_oauth_refresh(self): responses.add( responses.GET, - "https://googleads.googleapis.com/v9/customers:listAccessibleCustomers", + "https://googleads.googleapis.com/v12/customers:listAccessibleCustomers", json=test_utils.accessible_customer_return_data, status=200, ) From 4aa9ac79f5d1751d57cccd63a8bead6e4a60778e Mon Sep 17 00:00:00 2001 From: danielpdwalker Date: Mon, 5 Dec 2022 11:17:41 +0000 Subject: [PATCH 3/3] Bumped version to 0.3.2 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a9e6b50..5e20ce5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "tap-googleads" -version = "0.3.1" +version = "0.3.2" description = "`tap-googleads` is a Singer tap for GoogleAds, built with the Meltano SDK for Singer Taps." authors = ["AutoIDM", "Matatika"] keywords = [