Search in sources :

Example 31 with Selector

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

the class SelectorBuilderTest method testUniqueInternalOrderByState.

/**
 * Tests that the built selectors don't share internal OrderBy state.
 */
@Test
public void testUniqueInternalOrderByState() {
    SelectorBuilder builder = new SelectorBuilder();
    Selector selectorOne = builder.orderAscBy(CampaignField.Id).build();
    Selector selectorTwo = builder.build();
    OrderBy orderTwo = selectorTwo.getOrdering(0);
    orderTwo.setField("Status");
    assertEquals("Id", selectorOne.getOrdering(0).getField());
    assertEquals("Status", selectorTwo.getOrdering(0).getField());
    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 32 with Selector

use of com.google.api.ads.adwords.jaxws.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().length);
    assertEquals("Id", selector.getFields()[0]);
    assertEquals("Name", selector.getFields()[1]);
    assertEquals("Status", selector.getFields()[2]);
    assertEquals("StartDate", selector.getFields()[3]);
    assertEquals("EndDate", selector.getFields()[4]);
    assertEquals("ServingStatus", selector.getFields()[5]);
    assertEquals("Settings", selector.getFields()[6]);
    selector = builder.fields(CampaignField.Id, CampaignField.Name, CampaignField.Status, CampaignField.StartDate, CampaignField.EndDate, CampaignField.ServingStatus, CampaignField.Settings, CampaignField.Id, CampaignField.Amount).build();
    assertEquals(8, selector.getFields().length);
    assertEquals("Id", selector.getFields()[0]);
    assertEquals("Name", selector.getFields()[1]);
    assertEquals("Status", selector.getFields()[2]);
    assertEquals("StartDate", selector.getFields()[3]);
    assertEquals("EndDate", selector.getFields()[4]);
    assertEquals("ServingStatus", selector.getFields()[5]);
    assertEquals("Settings", selector.getFields()[6]);
    assertEquals("Amount", selector.getFields()[7]);
    checkUtilitiesState(true);
}
Also used : Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector) Test(org.junit.Test)

Example 33 with Selector

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

the class SelectorBuilderTest method testUniqueInternalDateRangeState.

/**
 * Tests that the built selectors don't share internal DateRange state.
 */
@Test
public void testUniqueInternalDateRangeState() {
    SelectorBuilder builder = new SelectorBuilder();
    DateFormat dateFormat = new SimpleDateFormat(SelectorBuilderImpl.DEFAULT_DATE_FORMAT);
    DateTime startOne = new DateTime(2013, 1, 1, 0, 0, 0, 0);
    DateTime endOne = new DateTime(2013, 1, 31, 0, 0, 0, 0);
    DateTime startTwo = new DateTime(2013, 2, 1, 0, 0, 0, 0);
    DateTime endTwo = new DateTime(2013, 2, 28, 0, 0, 0, 0);
    Selector selectorOne = builder.forDateRange(startOne, endOne).build();
    Selector selectorTwo = builder.forDateRange(startTwo, endTwo).build();
    assertEquals(dateFormat.format(startOne.toDate()), selectorOne.getDateRange().getMin());
    assertEquals(dateFormat.format(endOne.toDate()), selectorOne.getDateRange().getMax());
    assertEquals(dateFormat.format(startTwo.toDate()), selectorTwo.getDateRange().getMin());
    assertEquals(dateFormat.format(endTwo.toDate()), selectorTwo.getDateRange().getMax());
    checkUtilitiesState(false);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) DateTime(org.joda.time.DateTime) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector) Test(org.junit.Test)

Example 34 with Selector

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

the class ProductPartitionTreeImpl method getAdGroupBiddingStrategyConfiguration.

/**
 * Retrieves the {@link BiddingStrategyConfiguration} of an ad group.
 *
 * @param services the AdWordsServices
 * @param session the session to use for the request
 * @param adGroupId the ad group ID
 * @return the non-null BiddingStrategyConfiguration of the ad group
 */
private static BiddingStrategyConfiguration getAdGroupBiddingStrategyConfiguration(AdWordsServicesInterface services, AdWordsSession session, Long adGroupId) throws ApiException, RemoteException {
    AdGroupServiceInterface adGroupService = services.get(session, AdGroupServiceInterface.class);
    Selector selector = new SelectorBuilder().fields(AdGroupField.Id, AdGroupField.BiddingStrategyType, AdGroupField.BiddingStrategyId, AdGroupField.BiddingStrategyName).equalsId(adGroupId).build();
    AdGroupPage adGroupPage = adGroupService.get(selector);
    if (adGroupPage.getEntries() == null || adGroupPage.getEntries().length == 0) {
        throw new IllegalArgumentException("No ad group found with ID " + adGroupId);
    }
    AdGroup adGroup = adGroupPage.getEntries(0);
    Preconditions.checkState(adGroup.getBiddingStrategyConfiguration() != null, "Unexpected state - ad group ID %s has a null BiddingStrategyConfiguration", adGroupId);
    return adGroup.getBiddingStrategyConfiguration();
}
Also used : AdGroupServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface) SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) AdGroupPage(com.google.api.ads.adwords.axis.v201809.cm.AdGroupPage) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Example 35 with Selector

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

the class AdvancedCreateCredentialFromScratch method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param reportFile the output file for the report contents.
 * @throws DetailedReportDownloadResponseException if the report request failed with a detailed
 *     error from the reporting service.
 * @throws ReportDownloadResponseException if the report request failed with a general error from
 *     the reporting service.
 * @throws ReportException if the report request failed due to a transport layer error.
 * @throws IOException if the report's contents could not be written to {@code reportFile}.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, String reportFile) throws ReportDownloadResponseException, ReportException, IOException {
    // Get the CampaignService.
    CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
    // Create selector to retrieve the first 100 campaigns.
    Selector selector = new Selector();
    selector.setFields(new String[] { "Id", "Name" });
    Paging paging = new Paging();
    paging.setStartIndex(0);
    paging.setNumberResults(100);
    // Get the first page of campaigns.
    CampaignPage page = campaignService.get(selector);
    System.out.printf("Found %d total campaigns.%n", page.getTotalNumEntries());
    // Display campaigns.
    if (page.getEntries() != null) {
        for (Campaign campaign : page.getEntries()) {
            System.out.printf("Campaign with name '%s' and ID %d was found.%n", campaign.getName(), campaign.getId());
        }
    } else {
        System.out.println("No campaigns were found.");
    }
    // Create selector.
    com.google.api.ads.adwords.lib.jaxb.v201809.Selector reportSelector = new com.google.api.ads.adwords.lib.jaxb.v201809.Selector();
    reportSelector.getFields().addAll(Arrays.asList("CampaignId", "AdGroupId", "Id", "CriteriaType", "Criteria", "Impressions", "Clicks", "Cost"));
    // Create report definition.
    ReportDefinition reportDefinition = new ReportDefinition();
    reportDefinition.setReportName("Criteria performance report #" + System.currentTimeMillis());
    reportDefinition.setDateRangeType(ReportDefinitionDateRangeType.YESTERDAY);
    reportDefinition.setReportType(ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT);
    reportDefinition.setDownloadFormat(DownloadFormat.CSV);
    reportDefinition.setSelector(reportSelector);
    ReportingConfiguration reportingConfig = new ReportingConfiguration.Builder().includeZeroImpressions(false).build();
    session.setReportingConfiguration(reportingConfig);
    ReportDownloadResponse response = new ReportDownloader(session).downloadReport(reportDefinition);
    FileOutputStream fos = new FileOutputStream(new File(reportFile));
    Streams.copy(response.getInputStream(), fos);
    fos.close();
    System.out.printf("Report successfully downloaded: %s%n", reportFile);
}
Also used : Paging(com.google.api.ads.adwords.axis.v201809.cm.Paging) CampaignPage(com.google.api.ads.adwords.axis.v201809.cm.CampaignPage) CampaignServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface) ReportDownloadResponse(com.google.api.ads.adwords.lib.utils.ReportDownloadResponse) ReportDownloader(com.google.api.ads.adwords.lib.utils.v201809.ReportDownloader) Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) FileOutputStream(java.io.FileOutputStream) File(java.io.File) ReportDefinition(com.google.api.ads.adwords.lib.jaxb.v201809.ReportDefinition) ReportingConfiguration(com.google.api.ads.adwords.lib.client.reporting.ReportingConfiguration) 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