Skip to content

Commit 72126c3

Browse files
authored
Added ad() method to ResourceNames (#283)
1 parent fcd06ac commit 72126c3

4 files changed

Lines changed: 26 additions & 0 deletions

File tree

google-ads/src/main/java/com/google/ads/googleads/v2/utils/ResourceNames.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import com.google.ads.googleads.v2.resources.AdGroupLabelName;
3838
import com.google.ads.googleads.v2.resources.AdGroupName;
3939
import com.google.ads.googleads.v2.resources.AdGroupSimulationName;
40+
import com.google.ads.googleads.v2.resources.AdName;
4041
import com.google.ads.googleads.v2.resources.AdParameterName;
4142
import com.google.ads.googleads.v2.resources.AdScheduleViewName;
4243
import com.google.ads.googleads.v2.resources.AgeRangeViewName;
@@ -150,6 +151,11 @@ public static String accountBudgetProposal(long customerId, long accountBudgetPr
150151
String.valueOf(customerId), String.valueOf(accountBudgetProposalId));
151152
}
152153

154+
/** Returns the ad resource name for the specified components. */
155+
public static String ad(long customerId, long adId) {
156+
return AdName.format(String.valueOf(customerId), String.valueOf(adId));
157+
}
158+
153159
/** Returns the ad group resource name for the specified components. */
154160
public static String adGroup(long customerId, long adGroupId) {
155161
return AdGroupName.format(String.valueOf(customerId), String.valueOf(adGroupId));

google-ads/src/main/java/com/google/ads/googleads/v3/utils/ResourceNames.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import com.google.ads.googleads.v3.resources.AdGroupLabelName;
3838
import com.google.ads.googleads.v3.resources.AdGroupName;
3939
import com.google.ads.googleads.v3.resources.AdGroupSimulationName;
40+
import com.google.ads.googleads.v3.resources.AdName;
4041
import com.google.ads.googleads.v3.resources.AdParameterName;
4142
import com.google.ads.googleads.v3.resources.AdScheduleViewName;
4243
import com.google.ads.googleads.v3.resources.AgeRangeViewName;
@@ -156,6 +157,13 @@ public static String accountBudgetProposal(long customerId, long accountBudgetPr
156157
String.valueOf(customerId), String.valueOf(accountBudgetProposalId));
157158
}
158159

160+
/**
161+
* Returns the ad resource name for the specified components.
162+
*/
163+
public static String ad(long customerId, long adId) {
164+
return AdName.format(String.valueOf(customerId), String.valueOf(adId));
165+
}
166+
159167
/**
160168
* Returns the ad group resource name for the specified components.
161169
*/

google-ads/src/test/java/com/google/ads/googleads/v2/utils/ResourceNamesTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ public void testAccountBudgetProposal() {
4747
assertEquals(expected, ResourceNames.accountBudgetProposal(1234L, 5678L));
4848
}
4949

50+
@Test
51+
public void testAd() {
52+
String expected = "customers/1234/ads/5678";
53+
assertEquals(expected, ResourceNames.ad(1234L, 5678L));
54+
}
55+
5056
@Test
5157
public void testAdGroupAd() {
5258
String expected = "customers/1234/adGroupAds/5678~1011";

google-ads/src/test/java/com/google/ads/googleads/v3/utils/ResourceNamesTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ public void testAccountBudgetProposal() {
4747
assertEquals(expected, ResourceNames.accountBudgetProposal(1234L, 5678L));
4848
}
4949

50+
@Test
51+
public void testAd() {
52+
String expected = "customers/1234/ads/5678";
53+
assertEquals(expected, ResourceNames.ad(1234L, 5678L));
54+
}
55+
5056
@Test
5157
public void testAdGroupAd() {
5258
String expected = "customers/1234/adGroupAds/5678~1011";

0 commit comments

Comments
 (0)