Search in sources :

Example 46 with Selector

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

the class SelectorBuilderTest method testFieldsRemove.

/**
 * Tests the removal of fields.
 */
@Test
public void testFieldsRemove() {
    SelectorBuilder builder = new SelectorBuilder();
    builder = builder.fields("Id", "Name", "Status", "StartDate", "EndDate", "ServingStatus", "Settings");
    Selector selector = builder.build();
    assertEquals(7, selector.getFields().size());
    assertEquals("Id", selector.getFields().get(0));
    assertEquals("Name", selector.getFields().get(1));
    assertEquals("Status", selector.getFields().get(2));
    assertEquals("StartDate", selector.getFields().get(3));
    assertEquals("EndDate", selector.getFields().get(4));
    assertEquals("ServingStatus", selector.getFields().get(5));
    assertEquals("Settings", selector.getFields().get(6));
    checkUtilitiesState(false);
}
Also used : Selector(com.google.api.ads.adwords.jaxws.v201809.cm.Selector) Test(org.junit.Test)

Example 47 with Selector

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

the class SelectorBuilderTest method testFieldsBuild.

/**
 * Tests the adding of a new field.
 */
@Test
public void testFieldsBuild() {
    SelectorBuilder builder = new SelectorBuilder();
    builder = builder.fields("Id", "Name", "Status", "StartDate", "EndDate", "ServingStatus", "Settings");
    Selector selector = builder.build();
    assertEquals(7, selector.getFields().size());
    assertEquals("Id", selector.getFields().get(0));
    assertEquals("Name", selector.getFields().get(1));
    assertEquals("Status", selector.getFields().get(2));
    assertEquals("StartDate", selector.getFields().get(3));
    assertEquals("EndDate", selector.getFields().get(4));
    assertEquals("ServingStatus", selector.getFields().get(5));
    assertEquals("Settings", selector.getFields().get(6));
    selector = builder.fields("Id", "Name", "Status", "StartDate", "EndDate", "ServingStatus", "Settings", "Id", "AverageCpc").build();
    assertEquals(8, selector.getFields().size());
    assertEquals("Id", selector.getFields().get(0));
    assertEquals("Name", selector.getFields().get(1));
    assertEquals("Status", selector.getFields().get(2));
    assertEquals("StartDate", selector.getFields().get(3));
    assertEquals("EndDate", selector.getFields().get(4));
    assertEquals("ServingStatus", selector.getFields().get(5));
    assertEquals("Settings", selector.getFields().get(6));
    assertEquals("AverageCpc", selector.getFields().get(7));
    checkUtilitiesState(false);
}
Also used : Selector(com.google.api.ads.adwords.jaxws.v201809.cm.Selector) Test(org.junit.Test)

Example 48 with Selector

use of com.google.api.ads.adwords.axis.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().size());
    OrderBy orderBy = selector.getOrdering().get(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().size());
    orderBy = selector.getOrdering().get(0);
    assertEquals("AdvertisingChannelType", orderBy.getField());
    assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());
    orderBy = selector.getOrdering().get(1);
    assertEquals("Amount", orderBy.getField());
    assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());
    orderBy = selector.getOrdering().get(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().size());
    orderBy = selector.getOrdering().get(0);
    assertEquals("Amount", orderBy.getField());
    assertEquals(SortOrder.ASCENDING, orderBy.getSortOrder());
    checkUtilitiesState(true);
}
Also used : OrderBy(com.google.api.ads.adwords.jaxws.v201809.cm.OrderBy) Selector(com.google.api.ads.adwords.jaxws.v201809.cm.Selector) Test(org.junit.Test)

Example 49 with Selector

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

the class SelectorBuilderImpl method build.

@Override
public Selector build() {
    Selector selectorCopy = new Selector();
    Set<OrderBy> orderingCopy = this.copyOrderingSet();
    Set<Predicate> predicatesCopy = this.copyPredicatesSet();
    selectorCopy.getFields().addAll(Sets.newLinkedHashSet(this.fields));
    selectorCopy.getOrdering().addAll(orderingCopy);
    selectorCopy.getPredicates().addAll(predicatesCopy);
    if (this.dateRange != null) {
        DateRange newDateRange = new DateRange();
        newDateRange.setMin(this.dateRange.getMin());
        newDateRange.setMax(this.dateRange.getMax());
        selectorCopy.setDateRange(newDateRange);
    }
    if (this.paging != null) {
        Paging newPaging = new Paging();
        newPaging.setStartIndex(this.paging.getStartIndex());
        newPaging.setNumberResults(this.paging.getNumberResults());
        selectorCopy.setPaging(newPaging);
    }
    return selectorCopy;
}
Also used : OrderBy(com.google.api.ads.adwords.jaxws.v201809.cm.OrderBy) DateRange(com.google.api.ads.adwords.jaxws.v201809.cm.DateRange) Paging(com.google.api.ads.adwords.jaxws.v201809.cm.Paging) Selector(com.google.api.ads.adwords.jaxws.v201809.cm.Selector) Predicate(com.google.api.ads.adwords.jaxws.v201809.cm.Predicate)

Example 50 with Selector

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

the class GetResponsiveSearchAds method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group to use to find expanded text ads.
 * @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) throws RemoteException {
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
    int offset = 0;
    boolean morePages = true;
    // Create selector to get all of the ads for the ad group.
    SelectorBuilder builder = new SelectorBuilder();
    Selector selector = builder.fields(AdGroupAdField.Id, AdGroupAdField.Status, AdGroupAdField.ResponsiveSearchAdHeadlines, AdGroupAdField.ResponsiveSearchAdDescriptions).orderAscBy(AdGroupAdField.Id).offset(offset).limit(PAGE_SIZE).equals(AdGroupAdField.AdGroupId, adGroupId.toString()).in(AdGroupAdField.Status, "ENABLED", "PAUSED").equals("AdType", AdType.RESPONSIVE_SEARCH_AD.getValue()).build();
    int totalEntries = 0;
    while (morePages) {
        // Get all ads.
        AdGroupAdPage page = adGroupAdService.get(selector);
        // Display ads.
        if (page.getEntries() != null && page.getEntries().length > 0) {
            totalEntries = page.getTotalNumEntries();
            for (AdGroupAd adGroupAd : page.getEntries()) {
                ResponsiveSearchAd responsiveSearchAd = (ResponsiveSearchAd) adGroupAd.getAd();
                System.out.printf("Responsive search ad with ID %d, status '%s' was found.%n", adGroupAd.getAd().getId(), adGroupAd.getStatus());
                System.out.println("Headlines:");
                for (AssetLink headline : responsiveSearchAd.getHeadlines()) {
                    ServedAssetFieldType pinning = headline.getPinnedField();
                    System.out.printf("    %s%n", ((TextAsset) headline.getAsset()).getAssetText());
                    if (pinning != null) {
                        System.out.printf("    (pinned to %s)%n", pinning);
                    }
                }
                System.out.println("Descriptions:");
                for (AssetLink description : responsiveSearchAd.getDescriptions()) {
                    ServedAssetFieldType pinning = description.getPinnedField();
                    System.out.printf("    %s%n", ((TextAsset) description.getAsset()).getAssetText());
                    if (pinning != null) {
                        System.out.printf("    (pinned to %s)%n", pinning);
                    }
                }
            }
        }
        offset += PAGE_SIZE;
        selector = builder.increaseOffsetBy(PAGE_SIZE).build();
        morePages = offset < page.getTotalNumEntries();
    }
    System.out.printf("Ad group ID %d has %d responsive search ads.%n", adGroupId, totalEntries);
}
Also used : AdGroupAdPage(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdPage) SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) AdGroupAd(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd) ServedAssetFieldType(com.google.api.ads.adwords.axis.v201809.cm.ServedAssetFieldType) AdGroupAdServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface) ResponsiveSearchAd(com.google.api.ads.adwords.axis.v201809.cm.ResponsiveSearchAd) AssetLink(com.google.api.ads.adwords.axis.v201809.cm.AssetLink) 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)27 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)22 Selector (com.google.api.ads.adwords.jaxws.v201809.cm.Selector)14 ArrayList (java.util.ArrayList)9 SimpleDateFormat (java.text.SimpleDateFormat)7 DateFormat (java.text.DateFormat)6 DateTime (org.joda.time.DateTime)6 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)5 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.jaxws.v201809.cm.OrderBy)4 Predicate (com.google.api.ads.adwords.jaxws.v201809.cm.Predicate)4 ConfigurationLoadException (com.google.api.ads.common.lib.conf.ConfigurationLoadException)4 OAuthException (com.google.api.ads.common.lib.exception.OAuthException)4 ValidationException (com.google.api.ads.common.lib.exception.ValidationException)4 RemoteException (java.rmi.RemoteException)4 AdWordsServices (com.google.api.ads.adwords.axis.factory.AdWordsServices)3 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)3 AdGroupAdPage (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdPage)3