Skip to content

Commit 751fee6

Browse files
authored
Changes for library release v20.0.0 (#649)
2 parents cc595f0 + 8ad4841 commit 751fee6

5,299 files changed

Lines changed: 167 additions & 2210760 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

google-ads-examples/src/main/java/com/google/ads/googleads/examples/basicoperations/GetArtifactMetadata.java renamed to google-ads-examples/src/main/java/com/google/ads/googleads/examples/basicoperations/SearchForGoogleAdsFields.java

Lines changed: 52 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Google LLC
1+
// Copyright 2022 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -23,34 +23,34 @@
2323
import com.google.ads.googleads.v11.resources.GoogleAdsField;
2424
import com.google.ads.googleads.v11.services.GoogleAdsFieldServiceClient;
2525
import com.google.ads.googleads.v11.services.GoogleAdsFieldServiceClient.SearchGoogleAdsFieldsPagedResponse;
26-
import com.google.common.collect.Lists;
2726
import java.io.FileNotFoundException;
2827
import java.io.IOException;
2928
import java.util.ArrayList;
3029
import java.util.Collections;
3130
import java.util.List;
3231

3332
/**
34-
* Gets the metadata, such as whether the artifact is selectable, filterable and sortable, of an
35-
* artifact. The artifact can be either a resource (such as customer, campaign) or a field (such as
36-
* metrics.impressions, campaign.id). It'll also show the data type and artifacts that are
37-
* selectable with the artifact.
33+
* Searches for {@link GoogleAdsField}s that match a given prefix, retrieving metadata such as
34+
* whether the field is selectable, filterable, or sortable, along with the data type and the fields
35+
* that are selectable with the field. Each {@link GoogleAdsField} represents either a resource
36+
* (such as {@code customer}, {@code campaign}) or a field (such as {@code metrics.impressions},
37+
* {@code campaign.id}).
3838
*/
39-
public class GetArtifactMetadata {
39+
public class SearchForGoogleAdsFields {
4040

41-
private static class GetArtifactMetadataParams extends CodeSampleParams {
41+
private static class SearchForGoogleAdsFieldsParams extends CodeSampleParams {
4242

43-
@Parameter(names = ArgumentNames.ARTIFACT_NAME, required = true)
44-
private String artifactName;
43+
@Parameter(names = ArgumentNames.NAME_PREFIX, required = true)
44+
private String namePrefix;
4545
}
4646

4747
public static void main(String[] args) {
48-
GetArtifactMetadataParams params = new GetArtifactMetadataParams();
48+
SearchForGoogleAdsFieldsParams params = new SearchForGoogleAdsFieldsParams();
4949
if (!params.parseArguments(args)) {
5050

5151
// Either pass the required parameters for this example on the command line, or insert them
5252
// into the code here. See the parameter class definition above for descriptions.
53-
params.artifactName = "INSERT_ARTIFACT_NAME_HERE";
53+
params.namePrefix = "INSERT_NAME_PREFIX_HERE";
5454
}
5555

5656
GoogleAdsClient googleAdsClient = null;
@@ -66,7 +66,7 @@ public static void main(String[] args) {
6666
}
6767

6868
try {
69-
new GetArtifactMetadata().runExample(googleAdsClient, params.artifactName);
69+
new SearchForGoogleAdsFields().runExample(googleAdsClient, params.namePrefix);
7070
} catch (GoogleAdsException gae) {
7171
// GoogleAdsException is the base class for most exceptions thrown by an API request.
7272
// Instances of this exception have a message and a GoogleAdsFailure that contains a
@@ -87,55 +87,58 @@ public static void main(String[] args) {
8787
* Runs the example.
8888
*
8989
* @param googleAdsClient the Google Ads API client.
90-
* @param artifactName the name of artifact to get its metadata.
90+
* @param namePrefix the name prefix to use in the query.
9191
* @throws GoogleAdsException if an API request failed with one or more service errors.
9292
*/
93-
private void runExample(GoogleAdsClient googleAdsClient, String artifactName) {
93+
private void runExample(GoogleAdsClient googleAdsClient, String namePrefix) {
9494
try (GoogleAdsFieldServiceClient googleAdsFieldServiceClient =
9595
googleAdsClient.getLatestVersion().createGoogleAdsFieldServiceClient()) {
96-
// Searches for an artifact whose name is the same as the specified artifactName.
96+
// Searches for all fields whose name begins with the specified namePrefix.
9797
SearchGoogleAdsFieldsPagedResponse searchGoogleAdsFieldsPagedResponse =
9898
googleAdsFieldServiceClient.searchGoogleAdsFields(
9999
String.format(
100-
"SELECT name, category, selectable, filterable, sortable, selectable_with, "
101-
+ "data_type, is_repeated WHERE name = '%s'",
102-
artifactName));
100+
"SELECT "
101+
+ "name, "
102+
+ "category, "
103+
+ "selectable, "
104+
+ "filterable, "
105+
+ "sortable, "
106+
+ "data_type, "
107+
+ "is_repeated, "
108+
+ "selectable_with "
109+
// The double "%%" below will produce a single "%" in the string returned by
110+
// String.format. A single "%" is the wildcard token in the Google Ads Query
111+
// language.
112+
+ "WHERE name LIKE '%s%%'",
113+
namePrefix));
103114

104-
// Gets all returned artifacts and prints out their metadata.
105-
List<GoogleAdsField> googleAdsFields =
106-
Lists.newArrayList(searchGoogleAdsFieldsPagedResponse.iterateAll());
107-
for (GoogleAdsField googleAdsField : googleAdsFields) {
115+
if (searchGoogleAdsFieldsPagedResponse.getPage().getResponse().getTotalResultsCount() == 0) {
108116
System.out.printf(
109-
"An artifact named '%s' with category '%s' and data type '%s' %s selectable, %s "
110-
+ "filterable, %s sortable and %s repeated.%n%n",
111-
googleAdsField.getName(),
112-
googleAdsField.getCategory(),
113-
googleAdsField.getDataType(),
114-
getIsOrIsNot(googleAdsField.getSelectable()),
115-
getIsOrIsNot(googleAdsField.getFilterable()),
116-
getIsOrIsNot(googleAdsField.getSortable()),
117-
getIsOrIsNot(googleAdsField.getIsRepeated()));
117+
"No GoogleAdsFields found with a name that begins with '%s'.%n", namePrefix);
118+
return;
119+
}
118120

119-
// Sorts the list of artifact names that are selectable with the specified artifact.
120-
List<String> selectableArtifacts = new ArrayList(googleAdsField.getSelectableWithList());
121-
Collections.sort(selectableArtifacts);
121+
// Retrieves each matching GoogleAdsField and prints its metadata.
122+
for (GoogleAdsField googleAdsField : searchGoogleAdsFieldsPagedResponse.iterateAll()) {
123+
System.out.printf("%s:%n", googleAdsField.getName());
124+
System.out.printf(" %-16s %s%n", "category:", googleAdsField.getCategory());
125+
System.out.printf(" %-16s %s%n", "data type:", googleAdsField.getDataType());
126+
System.out.printf(" %-16s %s%n", "selectable:", googleAdsField.getSelectable());
127+
System.out.printf(" %-16s %s%n", "filterable:", googleAdsField.getFilterable());
128+
System.out.printf(" %-16s %s%n", "sortable:", googleAdsField.getSortable());
129+
System.out.printf(" %-16s %s%n", "repeated:", googleAdsField.getIsRepeated());
122130

123-
System.out.println("The artifact can be selected with the following artifacts:");
124-
for (String selectableField : selectableArtifacts) {
125-
System.out.println(selectableField);
131+
// Prints the list of fields that are selectable with the field.
132+
List<String> selectableWithFields = new ArrayList(googleAdsField.getSelectableWithList());
133+
if (!selectableWithFields.isEmpty()) {
134+
// Sorts and then prints the list.
135+
Collections.sort(selectableWithFields);
136+
System.out.printf(" %s%n", "selectable with:");
137+
for (String selectableWithField : selectableWithFields) {
138+
System.out.printf(" %s%n", selectableWithField);
139+
}
126140
}
127141
}
128-
129-
if (googleAdsFields.isEmpty()) {
130-
System.err.printf("The specified artifact '%s' doesn't exist.%n", artifactName);
131-
}
132142
}
133143
}
134-
135-
/**
136-
* Returns "is" when the specified value is true and "is not" when the specified value is false.
137-
*/
138-
private String getIsOrIsNot(boolean value) {
139-
return value ? "is" : "is not";
140-
}
141144
}

google-ads-examples/src/main/java/com/google/ads/googleads/examples/utils/ArgumentNames.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public final class ArgumentNames {
2525
public static final String ADJUSTMENT_DATE_TIME = "--adjustmentDateTime";
2626
public static final String ADJUSTMENT_TYPE = "--adjustmentType";
2727
public static final String ADVERTISER_UPLOAD_DATE_TIME = "--advertiserUploadDateTime";
28-
public static final String ARTIFACT_NAME = "--artifactName";
2928
public static final String ASSET_GROUP_ID = "--assetGroupId";
3029
public static final String ATTRIBUTE_VALUE = "--attributeValue";
3130
public static final String AUDIENCE_ID = "--audienceId";
@@ -96,6 +95,7 @@ public final class ArgumentNames {
9695
public static final String MANAGER_ID = "--managerId";
9796
public static final String MARKETING_IMAGE_ASSET_ID = "--marketingImageAssetId";
9897
public static final String MERCHANT_CENTER_ACCOUNT_ID = "--merchantCenterAccountId";
98+
public static final String NAME_PREFIX = "--namePrefix";
9999
public static final String OAUTH_CLIENT_FILE = "--oAuthClientFile";
100100
public static final String OAUTH_SCOPES = "--oAuthScopes";
101101
public static final String OFFLINE_USER_DATA_JOB_TYPE = "--offlineUserDataJobType";

google-ads-stubs-v9/build.gradle

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)