Skip to content

Commit

Permalink
Merge pull request #7 from Matatika/v12-api-upgrade
Browse files Browse the repository at this point in the history
Update tap to use Google Ads API v12
  • Loading branch information
DanielPDWalker authored Dec 5, 2022
2 parents 1753bf6 + 4aa9ac7 commit 2726fbe
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 27 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion tap_googleads/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
21 changes: 2 additions & 19 deletions tap_googleads/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,13 @@
# - 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"""

path = "/customers:listAccessibleCustomers"
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()
Expand All @@ -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}"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}"
Expand Down
2 changes: 0 additions & 2 deletions tap_googleads/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from singer_sdk import typing as th # JSON schema typing helpers

from tap_googleads.streams import (
CustomerStream,
CampaignsStream,
AdGroupsStream,
AdGroupsPerformance,
Expand All @@ -20,7 +19,6 @@
)

STREAM_TYPES = [
CustomerStream,
CampaignsStream,
AdGroupsStream,
AdGroupsPerformance,
Expand Down
4 changes: 2 additions & 2 deletions tap_googleads/tests/test_base_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
)
Expand Down
4 changes: 2 additions & 2 deletions tap_googleads/tests/test_proxy_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
)
Expand Down

0 comments on commit 2726fbe

Please sign in to comment.