use of com.google.api.ads.adwords.axis.v201809.cm.BidLandscapeLandscapePoint in project googleads-java-lib by googleads.
the class ServiceQueryTest method testHasNextWithSpecifiedAdGroupBidLandscapePage.
/**
* Tests using {@link ServiceQuery#hasNext(AdGroupBidLandscapePage)} to check if there is still a
* next page.
*/
@Test
public void testHasNextWithSpecifiedAdGroupBidLandscapePage() {
// First iteration. There are no previous pages.
AdGroupBidLandscapePage page = null;
assertTrue(serviceQuery.hasNext(page));
// Make ad group bid landscape page contain 400 bid landscape points (200 per ad group bid
// landscape point).
int numBidLandscapePoints = 200;
BidLandscapeLandscapePoint bidLandscapeLandscapePoint = new BidLandscapeLandscapePoint();
List<BidLandscapeLandscapePoint> bidLandscapeLandscapePoints = new ArrayList<>();
bidLandscapeLandscapePoints.addAll(Collections.nCopies(numBidLandscapePoints, bidLandscapeLandscapePoint));
AdGroupBidLandscape bidLandscape = mock(AdGroupBidLandscape.class);
when(bidLandscape.getLandscapePoints()).thenReturn(bidLandscapeLandscapePoints.toArray(new BidLandscapeLandscapePoint[0]));
page = mock(AdGroupBidLandscapePage.class);
when(page.getEntries()).thenReturn(new AdGroupBidLandscape[] { bidLandscape, bidLandscape });
serviceQuery = new ServiceQuery.Builder().fields("Id", "Name").limit(0, 100).build();
// 2 * 200 landscape points are greater than the page size that is 100.
assertTrue(serviceQuery.hasNext(page));
serviceQuery = new ServiceQuery.Builder().fields("Id", "Name").limit(0, 500).build();
// 2 * 200 landscape points are less than the page size that is 500.
assertFalse(serviceQuery.hasNext(page));
}
use of com.google.api.ads.adwords.axis.v201809.cm.BidLandscapeLandscapePoint in project googleads-java-lib by googleads.
the class GetKeywordBidSimulations method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param adGroupId the ID of the ad group.
* @param criterionId the ID of the criterion.
* @throws ApiException if the API request failed with one or more service errors.
* @throws RemoteException if the API request failed due to other errors.
*/
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long adGroupId, Long criterionId) throws RemoteException {
// Get the DataService.
DataServiceInterface dataService = adWordsServices.get(session, DataServiceInterface.class);
// Create a query to select all keyword bid simulations for the ad group.
ServiceQuery query = new ServiceQuery.Builder().fields(DataField.AdGroupId, DataField.CriterionId, DataField.StartDate, DataField.EndDate, DataField.Bid, DataField.BiddableConversions, DataField.BiddableConversionsValue, DataField.LocalClicks, DataField.LocalCost, DataField.LocalImpressions).where(DataField.AdGroupId).equalTo(adGroupId).where(DataField.CriterionId).equalTo(criterionId).limit(0, PAGE_SIZE).build();
// Display bid landscapes.
CriterionBidLandscapePage page = null;
do {
query.nextPage(page);
// Retrieve keyword bid simulations one page at a time, continuing to request pages until all
// of them have been retrieved.
page = dataService.queryCriterionBidLandscape(query.toString());
if (page.getEntries() != null) {
for (CriterionBidLandscape criterionBidLandscape : page.getEntries()) {
System.out.printf("Criterion bid landscape with ad group ID %d, criterion ID %d, " + "start date %s, end date %s, with landscape points:%n", criterionBidLandscape.getAdGroupId(), criterionBidLandscape.getCriterionId(), criterionBidLandscape.getStartDate(), criterionBidLandscape.getEndDate());
for (BidLandscapeLandscapePoint bidLanscapePoint : criterionBidLandscape.getLandscapePoints()) {
System.out.printf("\t{bid: %d clicks: %d cost: %d impressions: %d, biddable conversions: %.2f, " + "biddable conversions value: %.2f}%n", bidLanscapePoint.getBid().getMicroAmount(), bidLanscapePoint.getClicks(), bidLanscapePoint.getCost().getMicroAmount(), bidLanscapePoint.getImpressions(), bidLanscapePoint.getBiddableConversions(), bidLanscapePoint.getBiddableConversionsValue());
}
System.out.println(" was found.");
}
}
} while (query.hasNext(page));
}
use of com.google.api.ads.adwords.axis.v201809.cm.BidLandscapeLandscapePoint in project googleads-java-lib by googleads.
the class GetCampaignCriterionBidModifierSimulations method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param campaignId the ID of the campaign.
* @throws ApiException if the API request failed with one or more service errors.
* @throws RemoteException if the API request failed due to other errors.
*/
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long campaignId) throws RemoteException {
// Get the DataService.
DataServiceInterface dataService = adWordsServices.get(session, DataServiceInterface.class);
// Create selector.
Selector selector = new SelectorBuilder().fields(DataField.BidModifier, DataField.CampaignId, DataField.CriterionId, DataField.StartDate, DataField.EndDate, DataField.LocalClicks, DataField.LocalCost, DataField.LocalImpressions, DataField.TotalLocalClicks, DataField.TotalLocalCost, DataField.TotalLocalImpressions, DataField.RequiredBudget).equals(DataField.CampaignId, campaignId.toString()).limit(PAGE_SIZE).build();
// Display bid landscapes.
int landscapePointsInPreviousPage = 0;
int startIndex = 0;
do {
// Offset the start index by the number of landscape points in the last retrieved page,
// NOT the number of entries (bid landscapes) in the page.
startIndex += landscapePointsInPreviousPage;
selector.getPaging().setStartIndex(startIndex);
// Reset the count of landscape points in preparation for processing the next page.
landscapePointsInPreviousPage = 0;
// Request the next page of bid landscapes.
CriterionBidLandscapePage page = dataService.getCampaignCriterionBidLandscape(selector);
if (page.getEntries() != null) {
for (CriterionBidLandscape criterionBidLandscape : page.getEntries()) {
System.out.printf("Found campaign-level criterion bid modifier landscape for" + " criterion with ID %d, start date '%s', end date '%s', and" + " landscape points:%n", criterionBidLandscape.getCriterionId(), criterionBidLandscape.getStartDate(), criterionBidLandscape.getEndDate());
for (BidLandscapeLandscapePoint bidLandscapePoint : criterionBidLandscape.getLandscapePoints()) {
landscapePointsInPreviousPage++;
System.out.printf(" {bid modifier: %.2f => clicks: %d, cost: %d, impressions: %d, " + "total clicks: %d, total cost: %d, total impressions: %d, and " + "required budget: %d%n", bidLandscapePoint.getBidModifier(), bidLandscapePoint.getClicks(), bidLandscapePoint.getCost().getMicroAmount(), bidLandscapePoint.getImpressions(), bidLandscapePoint.getTotalLocalClicks(), bidLandscapePoint.getTotalLocalCost().getMicroAmount(), bidLandscapePoint.getTotalLocalImpressions(), bidLandscapePoint.getRequiredBudget().getMicroAmount());
}
}
}
} while (landscapePointsInPreviousPage >= PAGE_SIZE);
}
use of com.google.api.ads.adwords.axis.v201809.cm.BidLandscapeLandscapePoint in project googleads-java-lib by googleads.
the class ServiceQueryTest method testNextPageWithSpecifiedCriterionBidLandscapePage.
/**
* Tests using {@link ServiceQuery#nextPage(CriterionBidLandscapePage)} ] to get a next page of
* the result by specifying the previous criterion bid landscape page.
*/
@Test
public void testNextPageWithSpecifiedCriterionBidLandscapePage() {
// Make criterion bid landscape page contain 400 bid landscape points (200 per criterion bid
// landscape point).
int numBidLandscapePoints = 200;
BidLandscapeLandscapePoint bidLandscapeLandscapePoint = new BidLandscapeLandscapePoint();
List<BidLandscapeLandscapePoint> bidLandscapeLandscapePoints = new ArrayList<>();
bidLandscapeLandscapePoints.addAll(Collections.nCopies(numBidLandscapePoints, bidLandscapeLandscapePoint));
CriterionBidLandscape bidLandscape = mock(CriterionBidLandscape.class);
when(bidLandscape.getLandscapePoints()).thenReturn(bidLandscapeLandscapePoints);
CriterionBidLandscapePage page = mock(CriterionBidLandscapePage.class);
when(page.getEntries()).thenReturn(ImmutableList.of(bidLandscape, bidLandscape));
expectedAwql = "SELECT Id, Name WHERE Status = \"ENABLED\" ORDER BY Name DESC LIMIT 400,100";
serviceQuery.nextPage(page);
assertEquals(expectedAwql, serviceQuery.toString());
}
use of com.google.api.ads.adwords.axis.v201809.cm.BidLandscapeLandscapePoint in project googleads-java-lib by googleads.
the class ServiceQueryTest method testNextPageWithSpecifiedAdGroupBidLandscapePage.
/**
* Tests using {@link ServiceQuery#nextPage(AdGroupBidLandscapePage)} ] to get a next page of the
* result by specifying the previous ad group bid landscape page.
*/
@Test
public void testNextPageWithSpecifiedAdGroupBidLandscapePage() {
// Make ad group bid landscape page contain 400 bid landscape points (200 per ad group bid
// landscape point).
int numBidLandscapePoints = 200;
BidLandscapeLandscapePoint bidLandscapeLandscapePoint = new BidLandscapeLandscapePoint();
List<BidLandscapeLandscapePoint> bidLandscapeLandscapePoints = new ArrayList<>();
bidLandscapeLandscapePoints.addAll(Collections.nCopies(numBidLandscapePoints, bidLandscapeLandscapePoint));
AdGroupBidLandscape bidLandscape = mock(AdGroupBidLandscape.class);
when(bidLandscape.getLandscapePoints()).thenReturn(bidLandscapeLandscapePoints.toArray(new BidLandscapeLandscapePoint[0]));
AdGroupBidLandscapePage page = mock(AdGroupBidLandscapePage.class);
when(page.getEntries()).thenReturn(new AdGroupBidLandscape[] { bidLandscape, bidLandscape });
expectedAwql = "SELECT Id, Name WHERE Status = \"ENABLED\" ORDER BY Name DESC LIMIT 400,100";
serviceQuery.nextPage(page);
assertEquals(expectedAwql, serviceQuery.toString());
}
Aggregations