Skip to content

Commit 6a9a9bc

Browse files
authored
Rename examples (#260)
* Rename examples * Update class and param names and google-java-format
1 parent a6c500d commit 6a9a9bc

3 files changed

Lines changed: 50 additions & 47 deletions

File tree

google-ads-examples/src/main/java/com/google/ads/googleads/examples/remarketing/RemoveFeedItemAttributeValue.java renamed to google-ads-examples/src/main/java/com/google/ads/googleads/examples/remarketing/RemoveFlightsFeedItemStringAttributeValue.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@
4040
import java.util.Map;
4141

4242
/**
43-
* Removes a FeedItemAttributeValue of a FeedItem in a flights Feed. To create a flights
44-
* feed, run the AddFlightsFeed example. This example is specific to feeds of type
45-
* DYNAMIC_FLIGHT. The attribute you are removing must be present on the feed.
43+
* Removes a FeedItemAttributeValue of a FeedItem in a flights Feed. To create a flights feed, run
44+
* the AddFlightsFeed example. This example is specific to feeds of type DYNAMIC_FLIGHT. The
45+
* attribute you are removing must be present on the feed.
4646
*/
47-
public class RemoveFeedItemAttributeValue {
47+
public class RemoveFlightsFeedItemStringAttributeValue {
4848
private static final int PAGE_SIZE = 1_000;
4949

50-
private static class RemoveFeedItemAttributeValueParams extends CodeSampleParams {
50+
private static class RemoveFlightsFeedItemStringAttributeValueParams extends CodeSampleParams {
5151

5252
@Parameter(names = ArgumentNames.CUSTOMER_ID, required = true)
5353
private long customerId;
@@ -63,7 +63,8 @@ private static class RemoveFeedItemAttributeValueParams extends CodeSampleParams
6363
}
6464

6565
public static void main(String[] args) {
66-
RemoveFeedItemAttributeValueParams params = new RemoveFeedItemAttributeValueParams();
66+
RemoveFlightsFeedItemStringAttributeValueParams params =
67+
new RemoveFlightsFeedItemStringAttributeValueParams();
6768
if (!params.parseArguments(args)) {
6869

6970
// Either pass the required parameters for this example on the command line, or insert them
@@ -87,13 +88,13 @@ public static void main(String[] args) {
8788
}
8889

8990
try {
90-
new RemoveFeedItemAttributeValue()
91+
new RemoveFlightsFeedItemStringAttributeValue()
9192
.runExample(
92-
googleAdsClient,
93-
params.customerId,
94-
params.feedId,
95-
params.feedItemId,
96-
params.flightPlaceholderField);
93+
googleAdsClient,
94+
params.customerId,
95+
params.feedId,
96+
params.feedItemId,
97+
params.flightPlaceholderField);
9798
} catch (GoogleAdsException gae) {
9899
// GoogleAdsException is the base class for most exceptions thrown by an API request.
99100
// Instances of this exception have a message and a GoogleAdsFailure that contains a
@@ -126,7 +127,7 @@ private void runExample(
126127
long feedItemId,
127128
String flightPlaceholderField) {
128129
removeAttributeFromFeedItem(
129-
googleAdsClient, customerId, feedId, feedItemId, flightPlaceholderField);
130+
googleAdsClient, customerId, feedId, feedItemId, flightPlaceholderField);
130131
}
131132

132133
/**
@@ -153,8 +154,7 @@ private void removeAttributeFromFeedItem(
153154
AddFlightsFeed.getFeed(googleAdsClient, customerId, feedResourceName);
154155

155156
// Gets the feed item resource name.
156-
String feedItemResourceName = ResourceNames.feedItem(customerId, feedId,
157-
feedItemId);
157+
String feedItemResourceName = ResourceNames.feedItem(customerId, feedId, feedItemId);
158158
// Removes the attribute from the feed item.
159159
FeedItem feedItem =
160160
removeAttributeValueFromFeedItem(
@@ -252,8 +252,8 @@ private FeedItem getFeedItem(
252252
}
253253

254254
/**
255-
* Gets the ID of the attribute. This is needed to specify which
256-
* FeedItemAttributeValue will be removed in the given FeedItem.
255+
* Gets the ID of the attribute. This is needed to specify which FeedItemAttributeValue will be
256+
* removed in the given FeedItem.
257257
*
258258
* @param feedItem the FeedItem that will be updated.
259259
* @param removedFeedItemAttributeValue the new FeedItemAttributeValue that will be removed.
@@ -275,8 +275,9 @@ private int getAttributeIndex(
275275

276276
// Throws an exception if the attribute value is not found.
277277
if (attributeIndex == null) {
278-
new IllegalArgumentException("No matching feed attribute for feed item attribute value: "
279-
+ removedFeedItemAttributeValue);
278+
new IllegalArgumentException(
279+
"No matching feed attribute for feed item attribute value: "
280+
+ removedFeedItemAttributeValue);
280281
}
281282

282283
return attributeIndex;

google-ads-examples/src/main/java/com/google/ads/googleads/examples/remarketing/UpdateFeedItemAttributeValue.java renamed to google-ads-examples/src/main/java/com/google/ads/googleads/examples/remarketing/UpdateFlightsFeedItemStringAttributeValue.java

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@
4141
import java.util.Map;
4242

4343
/**
44-
* Updates a FeedItemAttributeValue in a flights feed. To create a flights feed,
45-
* run the AddFlightsFeed example. This example is specific to feeds of type DYNAMIC_FLIGHT.
46-
* The attribute you are updating must be present on the feed. This example is
47-
* specifically for updating the StringValue of an attribute.
44+
* Updates a FeedItemAttributeValue in a flights feed. To create a flights feed, run the
45+
* AddFlightsFeed example. This example is specific to feeds of type DYNAMIC_FLIGHT. The attribute
46+
* you are updating must be present on the feed. This example is specifically for updating the
47+
* StringValue of an attribute.
4848
*/
49-
public class UpdateFeedItemAttributeValue {
49+
public class UpdateFlightsFeedItemStringAttributeValue {
5050
private static final int PAGE_SIZE = 1_000;
5151

52-
private static class UpdateFeedItemAttributeValueParams extends CodeSampleParams {
52+
private static class UpdateFlightsFeedItemStringAttributeValueParams extends CodeSampleParams {
5353

5454
@Parameter(names = ArgumentNames.CUSTOMER_ID, required = true)
5555
private long customerId;
@@ -68,7 +68,8 @@ private static class UpdateFeedItemAttributeValueParams extends CodeSampleParams
6868
}
6969

7070
public static void main(String[] args) {
71-
UpdateFeedItemAttributeValueParams params = new UpdateFeedItemAttributeValueParams();
71+
UpdateFlightsFeedItemStringAttributeValueParams params =
72+
new UpdateFlightsFeedItemStringAttributeValueParams();
7273
if (!params.parseArguments(args)) {
7374

7475
// Either pass the required parameters for this example on the command line, or insert them
@@ -93,13 +94,14 @@ public static void main(String[] args) {
9394
}
9495

9596
try {
96-
new UpdateFeedItemAttributeValue().runExample(
97-
googleAdsClient,
98-
params.customerId,
99-
params.feedId,
100-
params.feedItemId,
101-
params.flightPlaceholderField,
102-
params.attributeValue);
97+
new UpdateFlightsFeedItemStringAttributeValue()
98+
.runExample(
99+
googleAdsClient,
100+
params.customerId,
101+
params.feedId,
102+
params.feedItemId,
103+
params.flightPlaceholderField,
104+
params.attributeValue);
103105
} catch (GoogleAdsException gae) {
104106
// GoogleAdsException is the base class for most exceptions thrown by an API request.
105107
// Instances of this exception have a message and a GoogleAdsFailure that contains a
@@ -134,7 +136,7 @@ private void runExample(
134136
String flightPlaceholderField,
135137
String attributeValue) {
136138
updateFeedItem(
137-
googleAdsClient, customerId, feedId, feedItemId, flightPlaceholderField, attributeValue);
139+
googleAdsClient, customerId, feedId, feedItemId, flightPlaceholderField, attributeValue);
138140
}
139141

140142
/**
@@ -164,13 +166,13 @@ private void updateFeedItem(
164166

165167
// Gets the ID of the attribute to update. This is needed to specify which
166168
// FeedItemAttributeValue will be updated in the given FeedItem.
167-
long attributeId = feedAttributes
168-
.get(FlightPlaceholderField.valueOf(flightPlaceholderField.toUpperCase()))
169-
.getId()
170-
.getValue();
169+
long attributeId =
170+
feedAttributes
171+
.get(FlightPlaceholderField.valueOf(flightPlaceholderField.toUpperCase()))
172+
.getId()
173+
.getValue();
171174
// Gets the feed item resource name.
172-
String feedItemResourceName =
173-
ResourceNames.feedItem(customerId, feedId, feedItemId);
175+
String feedItemResourceName = ResourceNames.feedItem(customerId, feedId, feedItemId);
174176
// Retrieves the feed item and its associated attributes based on its resource name.
175177
FeedItem feedItem = getFeedItem(googleAdsClient, customerId, feedItemResourceName);
176178
// Creates the updated FeedItemAttributeValue.
@@ -247,31 +249,31 @@ private FeedItem getFeedItem(
247249
}
248250

249251
/**
250-
* Gets the ID of the attribute. This is needed to specify which
251-
* FeedItemAttributeValue will be updated in the given FeedItem.
252+
* Gets the ID of the attribute. This is needed to specify which FeedItemAttributeValue will be
253+
* updated in the given FeedItem.
252254
*
253255
* @param feedItem the FeedItem that will be updated.
254256
* @param newFeedItemAttributeValue the new FeedItemAttributeValue that will be updated.
255257
* @return int the index of the attribute.
256258
*/
257259
private int getAttributeIndex(
258-
FeedItem feedItem, FeedItemAttributeValue newFeedItemAttributeValue) {
260+
FeedItem feedItem, FeedItemAttributeValue newFeedItemAttributeValue) {
259261
Integer attributeIndex = null;
260262

261263
// Loops through attribute values to find the index of the FeedItemAttributeValue to update
262264
for (FeedItemAttributeValue feedItemAttributeValue : feedItem.getAttributeValuesList()) {
263265
attributeIndex = (attributeIndex != null) ? attributeIndex + 1 : 0;
264266
// Checks if the current feedItemAttributeValue is the one we are updating
265267
if (feedItemAttributeValue.getFeedAttributeId().getValue()
266-
== newFeedItemAttributeValue.getFeedAttributeId().getValue()) {
268+
== newFeedItemAttributeValue.getFeedAttributeId().getValue()) {
267269
break;
268270
}
269271
}
270272

271273
// Throws an exception if the attribute value is not found.
272274
if (attributeIndex == null) {
273275
new IllegalArgumentException(
274-
"No matching feed attribute for feed item attribute value: " + newFeedItemAttributeValue);
276+
"No matching feed attribute for feed item attribute value: " + newFeedItemAttributeValue);
275277
}
276278

277279
return attributeIndex;

google-ads-examples/src/main/java/com/google/ads/googleads/examples/targeting/GetGeoTargetConstantByName.java renamed to google-ads-examples/src/main/java/com/google/ads/googleads/examples/targeting/GetGeoTargetConstantsByNames.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import java.util.stream.Stream;
2929

3030
/** Gets GeoTargetConstants by given location names. */
31-
public class GetGeoTargetConstantByName {
31+
public class GetGeoTargetConstantsByNames {
3232

3333
public static void main(String[] args) {
3434
GoogleAdsClient googleAdsClient;
@@ -44,7 +44,7 @@ public static void main(String[] args) {
4444
}
4545

4646
try {
47-
new GetGeoTargetConstantByName().runExample(googleAdsClient);
47+
new GetGeoTargetConstantsByNames().runExample(googleAdsClient);
4848
} catch (GoogleAdsException gae) {
4949
// GoogleAdsException is the base class for most exceptions thrown by an API request.
5050
// Instances of this exception have a message and a GoogleAdsFailure that contains a

0 commit comments

Comments
 (0)