Skip to content

Commit

Permalink
Update to v10 (AutoIDM#35)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bryantgray authored Mar 22, 2022
1 parent 35da41b commit d70e75b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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= {
Expand Down
2 changes: 0 additions & 2 deletions tap_google_ads/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
15 changes: 12 additions & 3 deletions tap_google_ads/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
Expand Down Expand Up @@ -72,16 +76,21 @@ 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


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

Expand Down
7 changes: 4 additions & 3 deletions tests/unittests/test_conversion_window.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import unittest
from datetime import datetime
from datetime import timedelta
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d70e75b

Please sign in to comment.