Skip to content

Commit

Permalink
Changes for release v5_0. (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenRKarl committed Sep 2, 2020
1 parent f63e318 commit 038c96f
Show file tree
Hide file tree
Showing 1,645 changed files with 224,973 additions and 4,737 deletions.
28 changes: 28 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 26,31 @@ information on using pull requests.

This project follows [Google's Open Source Community
Guidelines](https://opensource.google.com/conduct/).

## Code Style

This library conforms to [PEP 8](https://www.python.org/dev/peps/pep-0008/)
style guidelines and enforces an 80 character line width. It's recommended
that any contributor run the auto-formatter [`black`](https://github.com/psf/black),
version 19.10b0 on the non-generated codebase whenever making changes. To get
started, first install the appropriate version of `black`:

```
python -m pip install black==19.10b0
```

You can manually run the formatter on all non-generated code with the following
command:

```
python -m black -l 80 -t py37 --exclude "/(v[0-9] |\.eggs|\.git|_cache|\.nox|\.tox|\.venv|\.svn|_build|buck-out|build|dist)/" .
```

Alternatively, if you intend to contribute regularly, it might be easier to
append this script to the `.git/hooks/pre-commit` file:

```
FILES=$(git diff --cached --name-only --diff-filter=ACMR "*.py" | grep -v "google/ads/google_ads/v.*")
echo "${FILES}" | xargs python -m black -l 80 -t py37
echo "${FILES}" | xargs git add
```
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 1,8 @@
* 7.0.0
- Google Ads v5_0 release
- Updates to examples to support addition of field presence on certain
resources, changing from accessing wrapper types to accessing primitives.

* 6.0.0
- Google Ads v4_0 release
- Deprecate v1_0
Expand Down
68 changes: 42 additions & 26 deletions examples/account_management/create_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,52 29,68 @@


def main(client, manager_customer_id):
customer_service = client.get_service('CustomerService', version='v4')
customer = client.get_type('Customer', version='v4')
today = datetime.today().strftime('%Y%m%d %H:%M:%S')
customer.descriptive_name.value = ('Account created with '
'CustomerService on %s' % today)
customer_service = client.get_service("CustomerService", version="v5")
customer = client.get_type("Customer", version="v5")
today = datetime.today().strftime("%Y%m%d %H:%M:%S")
customer.descriptive_name = (
"Account created with " "CustomerService on %s" % today
)
# For a list of valid currency codes and time zones see this documentation:
# https://developers.google.com/adwords/api/docs/appendix/codes-formats
customer.currency_code.value = 'USD'
customer.time_zone.value = 'America/New_York'
customer.currency_code = "USD"
customer.time_zone = "America/New_York"
# The below values are optional. For more information about URL
# options see: https://support.google.com/google-ads/answer/6305348
customer.tracking_url_template.value = '{lpurl}?device={device}'
customer.final_url_suffix.value = ('keyword={keyword}&matchtype={matchtype}'
'&adgroupid={adgroupid}')
customer.has_partners_badge.value = False
customer.tracking_url_template = "{lpurl}?device={device}"
customer.final_url_suffix = (
"keyword={keyword}&matchtype={matchtype}" "&adgroupid={adgroupid}"
)
customer.has_partners_badge = False

try:
response = customer_service.create_customer_client(
manager_customer_id, customer)
print(('Customer created with resource name "%s" under manager account '
'with customer ID "%s"') %
(response.resource_name, manager_customer_id))
manager_customer_id, customer
)
print(
(
'Customer created with resource name "%s" under manager account '
'with customer ID "%s"'
)
% (response.resource_name, manager_customer_id)
)
except google.ads.google_ads.errors.GoogleAdsException as ex:
print('Request with ID "%s" failed with status "%s" and includes the '
'following errors:' % (ex.request_id, ex.error.code().name))
print(
'Request with ID "%s" failed with status "%s" and includes the '
"following errors:" % (ex.request_id, ex.error.code().name)
)
for error in ex.failure.errors:
print('\tError with message "%s".' % error.message)
if error.location:
for field_path_element in error.location.field_path_elements:
print('\t\tOn field: %s' % field_path_element.field_name)
print("\t\tOn field: %s" % field_path_element.field_name)
sys.exit(1)


if __name__ == '__main__':
if __name__ == "__main__":
# GoogleAdsClient will read the google-ads.yaml configuration file in the
# home directory if none is specified.
google_ads_client = (google.ads.google_ads.client.GoogleAdsClient
.load_from_storage())
google_ads_client = (
google.ads.google_ads.client.GoogleAdsClient.load_from_storage()
)

parser = argparse.ArgumentParser(
description=('Creates a new client under the given manager.'))
description=("Creates a new client under the given manager.")
)
# The following argument(s) should be provided to run the example.
parser.add_argument('-m', '--manager_customer_id', type=str,
required=True, help='A Google Ads customer ID for the '
'manager account under which the new customer will '
'be created.')
parser.add_argument(
"-m",
"--manager_customer_id",
type=str,
required=True,
help="A Google Ads customer ID for the "
"manager account under which the new customer will "
"be created.",
)
args = parser.parse_args()

main(google_ads_client, args.manager_customer_id)
170 changes: 96 additions & 74 deletions examples/account_management/get_account_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,91 28,113 @@


def resource_name_for_resource_type(resource_type, row):
"""Return the resource name for the resource type.
"""Return the resource name for the resource type.
Each returned row contains all possible changed fields. This function
returns the resource name of the changed field based on the
resource type. The changed field's parent is also populated but is not used.
Args:
resource_type: the string equivalent of the resource type
row: a single row returned from the service
Returns:
The resource name of the field that changed.
"""
resource_name = '' # default for UNSPECIFIED or UNKNOWN
if resource_type == 'AD_GROUP':
resource_name = row.change_status.ad_group.value
elif resource_type == 'AD_GROUP_AD':
resource_name = row.change_status.ad_group_ad.value
elif resource_type == 'AD_GROUP_CRITERION':
resource_name = row.change_status.ad_group_criterion.value
elif resource_type == 'CAMPAIGN':
resource_name = row.change_status.campaign.value
elif resource_type == 'CAMPAIGN_CRITERION':
resource_name = row.change_status.campaign_criterion.value
return resource_name
resource_name = "" # default for UNSPECIFIED or UNKNOWN
if resource_type == "AD_GROUP":
resource_name = row.change_status.ad_group
elif resource_type == "AD_GROUP_AD":
resource_name = row.change_status.ad_group_ad
elif resource_type == "AD_GROUP_CRITERION":
resource_name = row.change_status.ad_group_criterion
elif resource_type == "CAMPAIGN":
resource_name = row.change_status.campaign
elif resource_type == "CAMPAIGN_CRITERION":
resource_name = row.change_status.campaign_criterion
return resource_name


def main(client, customer_id):
ads_service = client.get_service('GoogleAdsService', version='v4')
query = ('SELECT change_status.resource_name, '
'change_status.last_change_date_time, '
'change_status.resource_type, '
'change_status.campaign, '
'change_status.ad_group, '
'change_status.resource_status, '
'change_status.ad_group_ad, '
'change_status.ad_group_criterion, '
'change_status.campaign_criterion '
'FROM change_status '
'WHERE change_status.last_change_date_time DURING LAST_7_DAYS '
'ORDER BY change_status.last_change_date_time')

response = ads_service.search(customer_id, query=query,
page_size=ADS_PAGE_SIZE)

resource_type_enum = (client.get_type(
'ChangeStatusResourceTypeEnum', version='v4').ChangeStatusResourceType)
change_status_operation_enum = (client.get_type(
'ChangeStatusOperationEnum', version='v4').ChangeStatusOperation)

try:
for row in response:
resource_type = (resource_type_enum.Name(row.change_status
.resource_type))
resource_status = (change_status_operation_enum
.Name(row.change_status.resource_status))
print ('On "%s", change status "%s" shows a resource type of "%s" '
'with resource name "%s" was "%s".'
% (row.change_status.last_change_date_time.value,
row.change_status.resource_name,
resource_type,
resource_name_for_resource_type(resource_type, row),
resource_status))
except google.ads.google_ads.errors.GoogleAdsException as ex:
print('Request with ID "%s" failed with status "%s" and includes the '
'following errors:' % (ex.request_id, ex.error.code().name))
for error in ex.failure.errors:
print('\tError with message "%s".' % error.message)
if error.location:
for field_path_element in error.location.field_path_elements:
print('\t\tOn field: %s' % field_path_element.field_name)
sys.exit(1)


if __name__ == '__main__':
# GoogleAdsClient will read a google-ads.yaml configuration file in the
# home directory if none is specified.
google_ads_client = (google.ads.google_ads.client.GoogleAdsClient
.load_from_storage())

parser = argparse.ArgumentParser(
description=('Displays account changes that occurred in the last 7 days.'))
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=str,
required=True, help='The Google Ads customer ID.')
args = parser.parse_args()

main(google_ads_client, args.customer_id)
ads_service = client.get_service("GoogleAdsService", version="v5")
query = (
"SELECT change_status.resource_name, "
"change_status.last_change_date_time, "
"change_status.resource_type, "
"change_status.campaign, "
"change_status.ad_group, "
"change_status.resource_status, "
"change_status.ad_group_ad, "
"change_status.ad_group_criterion, "
"change_status.campaign_criterion "
"FROM change_status "
"WHERE change_status.last_change_date_time DURING LAST_7_DAYS "
"ORDER BY change_status.last_change_date_time"
)

response = ads_service.search(
customer_id, query=query, page_size=ADS_PAGE_SIZE
)

resource_type_enum = client.get_type(
"ChangeStatusResourceTypeEnum", version="v5"
).ChangeStatusResourceType
change_status_operation_enum = client.get_type(
"ChangeStatusOperationEnum", version="v5"
).ChangeStatusOperation

try:
for row in response:
resource_type = resource_type_enum.Name(
row.change_status.resource_type
)
resource_status = change_status_operation_enum.Name(
row.change_status.resource_status
)
print(
'On "%s", change status "%s" shows a resource type of "%s" '
'with resource name "%s" was "%s".'
% (
row.change_status.last_change_date_time.value,
row.change_status.resource_name,
resource_type,
resource_name_for_resource_type(resource_type, row),
resource_status,
)
)
except google.ads.google_ads.errors.GoogleAdsException as ex:
print(
'Request with ID "%s" failed with status "%s" and includes the '
"following errors:" % (ex.request_id, ex.error.code().name)
)
for error in ex.failure.errors:
print('\tError with message "%s".' % error.message)
if error.location:
for field_path_element in error.location.field_path_elements:
print("\t\tOn field: %s" % field_path_element.field_name)
sys.exit(1)


if __name__ == "__main__":
# GoogleAdsClient will read a google-ads.yaml configuration file in the
# home directory if none is specified.
google_ads_client = (
google.ads.google_ads.client.GoogleAdsClient.load_from_storage()
)

parser = argparse.ArgumentParser(
description=(
"Displays account changes that occurred in the last 7 days."
)
)
# The following argument(s) should be provided to run the example.
parser.add_argument(
"-c",
"--customer_id",
type=str,
required=True,
help="The Google Ads customer ID.",
)
args = parser.parse_args()

main(google_ads_client, args.customer_id)
Loading

0 comments on commit 038c96f

Please sign in to comment.