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);
}
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);
}
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);
}
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();
}
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);
}
Aggregations