Skip to content

Commit

Permalink
source-google-ads: update to v15
Browse files Browse the repository at this point in the history
  • Loading branch information
jgraettinger committed Jan 31, 2024
1 parent a14a44b commit deb7eb8
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 70 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ jobs:
- connector: source-airtable
connector_type: capture
python: true
- connector: source-google-ads
connector_type: capture
python: true

steps:
- uses: actions/checkout@v2
Expand Down
38 changes: 16 additions & 22 deletions source-google-ads/__main__.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,32 @@
from flow_sdk import shim_airbyte_cdk
from source_google_ads import SourceGoogleAds


def wrap_with_braces(body: str, count: int):
opening = '{'*count
closing = '}'*count
opening = "{" * count
closing = "}" * count
return f"{opening}{body}{closing}"


def urlencode_field(field: str):
return f"{wrap_with_braces('#urlencode',2)}{wrap_with_braces(field,3)}{wrap_with_braces('/urlencode',2)}"


shim_airbyte_cdk.CaptureShim(
delegate=SourceGoogleAds(),
oauth2={
"provider": "asana",
"provider": "google",
"accessTokenBody": r"{\"grant_type\": \"authorization_code\", \"client_id\": \"{{{ 'client_id' }}}\", \"client_secret\": \"{{{ client_secret }}}\", \"redirect_uri\": \"{{{ redirect_uri }}}\", \"code\": \"{{{ code }}}\"}",
"authUrlTemplate": (
f"https://app.asana.com/-/oauth_authorize?"
f"client_id={wrap_with_braces('client_id',3)}&"
f"https://accounts.google.com/o/oauth2/auth?"
f"access_type=offline&"
f"prompt=consent&"
f"client_id={urlencode_field('client_id')}&"
f"redirect_uri={urlencode_field('redirect_uri')}&"
f"response_type=code&"
f"state={urlencode_field('state')}&"
f"scope=default"

),
"accessTokenUrlTemplate": (
f"https://app.asana.com/-/oauth_token?"
f"grant_type=authorization_code&"
f"client_id={wrap_with_braces('client_id',3)}&"
f"client_secret={wrap_with_braces('client_secret',3)}&"
f"redirect_uri={urlencode_field('redirect_uri')}&"
f"code={urlencode_field('code')}"
f"scope=https://www.googleapis.com/auth/adwords&state={urlencode_field('state')}"
),
"accessTokenResponseMap": {
"access_token": "/access_token",
"refresh_token": "/refresh_token"
}
}
).main()
"accessTokenResponseMap": {"refresh_token": "/refresh_token"},
"accessTokenUrlTemplate": "https://oauth2.googleapis.com/token",
},
).main()
59 changes: 29 additions & 30 deletions source-google-ads/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion source-google-ads/source_google_ads/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# pin protobuf==3.20.0 as other versions may cause problems on different architectures
# (see https://github.com/airbytehq/airbyte/issues/13580)
MAIN_REQUIREMENTS = ["airbyte-cdk>=0.2.2", "google-ads==20.0.0", "protobuf", "pendulum"]
MAIN_REQUIREMENTS = ["airbyte-cdk>=0.2.2", "google-ads>=23.0.0", "protobuf", "pendulum"]

TEST_REQUIREMENTS = ["pytest~=6.1", "pytest-mock", "freezegun", "requests-mock"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from airbyte_cdk.models import FailureType
from airbyte_cdk.utils import AirbyteTracedException
from google.ads.googleads.client import GoogleAdsClient
from google.ads.googleads.v13.services.types.google_ads_service import GoogleAdsRow, SearchGoogleAdsResponse
from google.ads.googleads.v15.services.types.google_ads_service import GoogleAdsRow, SearchGoogleAdsResponse
from google.api_core.exceptions import ServerError, TooManyRequests
from google.auth import exceptions
from proto.marshal.collections import Repeated, RepeatedComposite
Expand All @@ -36,7 +36,7 @@
"geographic_report": "geographic_view",
"keyword_report": "keyword_view",
}
API_VERSION = "v13"
API_VERSION = "v15"
logger = logging.getLogger("airbyte")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,6 @@
"campaign.shopping_setting.merchant_id": {
"type": ["null", "integer"]
},
"campaign.shopping_setting.sales_country": {
"type": ["null", "string"]
},
"campaign.start_date": {
"type": ["null", "string"]
},
Expand Down Expand Up @@ -274,7 +271,7 @@
"format": "date"
},
"segments.hour": {
"type": ["null", "number"]
"type": ["null", "integer"]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@
"campaign.status": {
"type": ["null", "string"]
},
"segments.product_bidding_category_level1": {
"segments.product_category_level1": {
"type": ["null", "string"]
},
"segments.product_bidding_category_level2": {
"segments.product_category_level2": {
"type": ["null", "string"]
},
"segments.product_bidding_category_level3": {
"segments.product_category_level3": {
"type": ["null", "string"]
},
"segments.product_bidding_category_level4": {
"segments.product_category_level4": {
"type": ["null", "string"]
},
"segments.product_bidding_category_level5": {
"segments.product_category_level5": {
"type": ["null", "string"]
},
"segments.product_channel": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from airbyte_cdk.sources.streams import Stream
from airbyte_cdk.utils import AirbyteTracedException
from google.ads.googleads.errors import GoogleAdsException
from google.ads.googleads.v13.errors.types.authorization_error import AuthorizationErrorEnum
from google.ads.googleads.v15.errors.types.authorization_error import AuthorizationErrorEnum
from pendulum import parse, today

from .custom_query_stream import CustomQuery, IncrementalCustomQuery
Expand Down Expand Up @@ -51,7 +51,7 @@ def _validate_and_transform(config: Mapping[str, Any]):
try:
query["query"] = GAQL.parse(query["query"])
except ValueError:
message = f"The custom GAQL query {query['table_name']} failed. Validate your GAQL query with the Google Ads query validator. https://developers.google.com/google-ads/api/fields/v13/query_validator"
message = f"The custom GAQL query {query['table_name']} failed. Validate your GAQL query with the Google Ads query validator. https://developers.google.com/google-ads/api/fields/v15/query_validator"
raise AirbyteTracedException(message=message, failure_type=FailureType.config_error)
return config

Expand Down
Loading

0 comments on commit deb7eb8

Please sign in to comment.