Search in sources :

Example 16 with Selector

use of com.google.api.ads.adwords.jaxws.v201809.cm.Selector in project googleads-java-lib by googleads.

the class SelectorBuilderTest method testPagingAndLimits.

/**
 * Tests the offset, limit and paging logic of the builder.
 */
@Test
public void testPagingAndLimits() {
    SelectorBuilder builder = new SelectorBuilder();
    builder = builder.offset(10);
    Selector selector = builder.build();
    assertNotNull(selector.getPaging());
    assertNotNull(selector.getPaging().getStartIndex());
    assertNull(selector.getPaging().getNumberResults());
    assertEquals(10, selector.getPaging().getStartIndex().intValue());
    selector = builder.offset(10).limit(20).build();
    assertNotNull(selector.getPaging());
    assertNotNull(selector.getPaging().getStartIndex());
    assertNotNull(selector.getPaging().getNumberResults());
    assertEquals(10, selector.getPaging().getStartIndex().intValue());
    assertEquals(20, selector.getPaging().getNumberResults().intValue());
    selector = builder.offset(10).limit(20).increaseOffsetBy(5).build();
    assertNotNull(selector.getPaging());
    assertNotNull(selector.getPaging().getStartIndex());
    assertNotNull(selector.getPaging().getNumberResults());
    assertEquals(15, selector.getPaging().getStartIndex().intValue());
    assertEquals(20, selector.getPaging().getNumberResults().intValue());
    selector = builder.offset(10).limit(20).increaseOffsetBy(5).removeLimitAndOffset().build();
    assertNull(selector.getPaging());
    selector = builder.offset(10).limit(20).increaseOffsetBy(5).removeLimitAndOffset().offset(55).limit(4).build();
    assertNotNull(selector.getPaging());
    assertNotNull(selector.getPaging().getStartIndex());
    assertNotNull(selector.getPaging().getNumberResults());
    assertEquals(55, selector.getPaging().getStartIndex().intValue());
    assertEquals(4, selector.getPaging().getNumberResults().intValue());
    checkUtilitiesState(false);
}
Also used : Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector) Test(org.junit.Test)

Example 17 with Selector

use of com.google.api.ads.adwords.jaxws.v201809.cm.Selector in project googleads-java-lib by googleads.

the class SelectorBuilderTest method testOrderByBuild.

/**
 * Tests the order by criteria
 */
@Test
public void testOrderByBuild() {
    SelectorBuilder builder = new SelectorBuilder();
    builder = builder.orderAscBy(CampaignField.AdvertisingChannelType);
    Selector selector = builder.build();
    assertNotNull(selector.getOrdering());
    assertEquals(1, selector.getOrdering().length);
    OrderBy orderBy = selector.getOrdering()[0];
    assertEquals("AdvertisingChannelType", orderBy.getField());
    assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());
    builder.orderAscBy(CampaignField.Amount).orderDescBy(CampaignField.AdvertisingChannelType);
    selector = builder.build();
    assertNotNull(selector.getOrdering());
    assertEquals(3, selector.getOrdering().length);
    orderBy = selector.getOrdering()[0];
    assertEquals("AdvertisingChannelType", orderBy.getField());
    assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());
    orderBy = selector.getOrdering()[1];
    assertEquals("Amount", orderBy.getField());
    assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());
    orderBy = selector.getOrdering()[2];
    assertEquals("AdvertisingChannelType", orderBy.getField());
    assertEquals(SortOrder.DESCENDING, orderBy.getSortOrder());
    // Removing the OrderBy for AdvertisingChannelType
    selector = builder.removeOrderBy("AdvertisingChannelType").build();
    assertNotNull(selector.getOrdering());
    assertEquals(1, selector.getOrdering().length);
    orderBy = selector.getOrdering()[0];
    assertEquals("Amount", orderBy.getField());
    assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());
    checkUtilitiesState(true);
}
Also used : OrderBy(com.google.api.ads.adwords.axis.v201809.cm.OrderBy) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector) Test(org.junit.Test)

Example 18 with Selector

use of com.google.api.ads.adwords.jaxws.v201809.cm.Selector 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);
}
Also used : SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) CriterionBidLandscapePage(com.google.api.ads.adwords.axis.v201809.cm.CriterionBidLandscapePage) CriterionBidLandscape(com.google.api.ads.adwords.axis.v201809.cm.CriterionBidLandscape) DataServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.DataServiceInterface) BidLandscapeLandscapePoint(com.google.api.ads.adwords.axis.v201809.cm.BidLandscapeLandscapePoint) BidLandscapeLandscapePoint(com.google.api.ads.adwords.axis.v201809.cm.BidLandscapeLandscapePoint) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Example 19 with Selector

use of com.google.api.ads.adwords.jaxws.v201809.cm.Selector in project googleads-java-lib by googleads.

the class GetProductCategoryTaxonomy method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @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) throws RemoteException {
    // Get the constant data service.
    ConstantDataServiceInterface constantDataService = adWordsServices.get(session, ConstantDataServiceInterface.class);
    Selector selector = new SelectorBuilder().equals(ConstantDataField.Country, "US").build();
    ProductBiddingCategoryData[] results = constantDataService.getProductBiddingCategoryData(selector);
    // List of top level category nodes.
    List<CategoryNode> rootCategories = new ArrayList<>();
    // Map of category ID to category node for all categories found in the results.
    Map<Long, CategoryNode> biddingCategories = Maps.newHashMap();
    for (ProductBiddingCategoryData productBiddingCategoryData : results) {
        Long id = productBiddingCategoryData.getDimensionValue().getValue();
        String name = productBiddingCategoryData.getDisplayValue(0).getValue();
        CategoryNode node = biddingCategories.get(id);
        if (node == null) {
            node = new CategoryNode(id, name);
            biddingCategories.put(id, node);
        } else if (node.name == null) {
            // Ensure that the name attribute for the node is set. Name will be null for nodes added
            // to biddingCategories as a result of being a parentNode below.
            node.name = name;
        }
        if (productBiddingCategoryData.getParentDimensionValue() != null && productBiddingCategoryData.getParentDimensionValue().getValue() != null) {
            Long parentId = productBiddingCategoryData.getParentDimensionValue().getValue();
            CategoryNode parentNode = biddingCategories.get(parentId);
            if (parentNode == null) {
                parentNode = new CategoryNode(parentId);
                biddingCategories.put(parentId, parentNode);
            }
            parentNode.children.add(node);
        } else {
            rootCategories.add(node);
        }
    }
    displayCategories(rootCategories, "");
}
Also used : SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) ArrayList(java.util.ArrayList) ConstantDataServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.ConstantDataServiceInterface) ProductBiddingCategoryData(com.google.api.ads.adwords.axis.v201809.cm.ProductBiddingCategoryData) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Example 20 with Selector

use of com.google.api.ads.adwords.jaxws.v201809.cm.Selector in project googleads-java-lib by googleads.

the class LookupLocation method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param locationNames the location names to use for the lookup.
 * @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, String[] locationNames) throws RemoteException {
    // Get the LocationCriterionService.
    LocationCriterionServiceInterface locationCriterionService = adWordsServices.get(session, LocationCriterionServiceInterface.class);
    Selector selector = new SelectorBuilder().fields("Id", "LocationName", "CanonicalName", "DisplayType", "ParentLocations", "Reach", "TargetingStatus").in("LocationName", locationNames).equals("Locale", "en").build();
    // Make the get request.
    LocationCriterion[] locationCriteria = locationCriterionService.get(selector);
    // Display the resulting location criteria.
    for (LocationCriterion locationCriterion : locationCriteria) {
        String parentString = getParentLocationString(locationCriterion.getLocation().getParentLocations());
        System.out.printf("The search term '%s' returned the location '%s (%d)' of type '%s' " + "with parent locations '%s' and reach %d (%s).%n", locationCriterion.getSearchTerm(), locationCriterion.getLocation().getLocationName(), locationCriterion.getLocation().getId(), locationCriterion.getLocation().getDisplayType(), parentString, locationCriterion.getReach(), locationCriterion.getLocation().getTargetingStatus());
    }
}
Also used : SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) LocationCriterion(com.google.api.ads.adwords.axis.v201809.cm.LocationCriterion) LocationCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.LocationCriterionServiceInterface) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Aggregations

Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)36 Test (org.junit.Test)26 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)21 Selector (com.google.api.ads.adwords.jaxws.v201809.cm.Selector)14 SimpleDateFormat (java.text.SimpleDateFormat)7 DateFormat (java.text.DateFormat)6 DateTime (org.joda.time.DateTime)6 CampaignPage (com.google.api.ads.adwords.axis.v201809.cm.CampaignPage)5 CampaignServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface)5 OrderBy (com.google.api.ads.adwords.axis.v201809.cm.OrderBy)4 Predicate (com.google.api.ads.adwords.axis.v201809.cm.Predicate)4 OrderBy (com.google.api.ads.adwords.jaxws.v201809.cm.OrderBy)4 Predicate (com.google.api.ads.adwords.jaxws.v201809.cm.Predicate)4 ArrayList (java.util.ArrayList)4 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)3 AdGroupAdPage (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdPage)3 AdGroupAdServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface)3 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)3 Campaign (com.google.api.ads.adwords.axis.v201809.cm.Campaign)3 Parameter (com.beust.jcommander.Parameter)2