use of com.google.api.ads.admanager.axis.v202205.Date in project googleads-java-lib by googleads.
the class RunReachReportWithAdUnitDimensions method runExample.
/**
* Runs the example.
*
* @param adManagerServices 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.
* @throws IOException if unable to write the response to a file.
* @throws InterruptedException if the thread is interrupted while waiting for the report to
* complete.
*/
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws IOException, InterruptedException {
// Get the ReportService.
ReportServiceInterface reportService = adManagerServices.get(session, ReportServiceInterface.class);
// Create report query.
ReportQuery reportQuery = new ReportQuery();
reportQuery.setDimensions(new Dimension[] { Dimension.MONTH_AND_YEAR, Dimension.COUNTRY_NAME, Dimension.AD_UNIT_ID, Dimension.AD_UNIT_NAME });
reportQuery.setColumns(new Column[] { Column.UNIQUE_REACH_FREQUENCY, Column.UNIQUE_REACH_IMPRESSIONS, Column.UNIQUE_REACH });
// Set the dynamic date range type or a custom start and end date that is
// the beginning of the week (Sunday) to the end of the week (Saturday), or
// the first of the month to the end of the month.
reportQuery.setDateRangeType(DateRangeType.LAST_MONTH);
reportQuery.setAdUnitView(ReportQueryAdUnitView.FLAT);
// Create report job.
ReportJob reportJob = new ReportJob();
reportJob.setReportQuery(reportQuery);
// Run report job.
reportJob = reportService.runReportJob(reportJob);
// Create report downloader.
ReportDownloader reportDownloader = new ReportDownloader(reportService, reportJob.getId());
// Wait for the report to be ready.
reportDownloader.waitForReportReady();
// Change to your file location.
File file = File.createTempFile("reach-report-", ".csv.gz");
System.out.printf("Downloading report to %s ...", file.toString());
// Download the report.
ReportDownloadOptions options = new ReportDownloadOptions();
options.setExportFormat(ExportFormat.CSV_DUMP);
options.setUseGzipCompression(true);
URL url = reportDownloader.getDownloadUrl(options);
Resources.asByteSource(url).copyTo(Files.asByteSink(file));
System.out.println("done.");
}
use of com.google.api.ads.admanager.axis.v202205.Date in project googleads-java-lib by googleads.
the class RunReportWithCustomFields method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param customFieldId the ID of the custom field to include in the report.
* @param customDimensionKeyId the ID of the custom key to include as a dimension in the report.
* @throws ApiException if the API request failed with one or more service errors.
* @throws RemoteException if the API request failed due to other errors.
* @throws IOException if unable to write the response to a file.
* @throws InterruptedException if the thread is interrupted while waiting for the report to
* complete.
*/
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session, long customFieldId, long customDimensionKeyId) throws IOException, InterruptedException {
// Get the ReportService.
ReportServiceInterface reportService = adManagerServices.get(session, ReportServiceInterface.class);
// Create report query.
ReportQuery reportQuery = new ReportQuery();
reportQuery.setDimensions(new Dimension[] { Dimension.DATE, Dimension.CUSTOM_DIMENSION, Dimension.LINE_ITEM_ID });
reportQuery.setColumns(new Column[] { Column.AD_SERVER_IMPRESSIONS });
// Set the dynamic date range type or a custom start and end date.
reportQuery.setDateRangeType(DateRangeType.LAST_MONTH);
// Set the custom field IDs.
reportQuery.setCustomFieldIds(new long[] { customFieldId });
// Set the custom dimension IDs.
reportQuery.setCustomDimensionKeyIds(new long[] { customDimensionKeyId });
// Create report job.
ReportJob reportJob = new ReportJob();
reportJob.setReportQuery(reportQuery);
// Run report job.
reportJob = reportService.runReportJob(reportJob);
// Create report downloader.
ReportDownloader reportDownloader = new ReportDownloader(reportService, reportJob.getId());
// Wait for the report to be ready.
reportDownloader.waitForReportReady();
// Change to your file location.
File file = File.createTempFile("custom-field-report-", ".csv.gz");
System.out.printf("Downloading report to %s ...", file.toString());
// Download the report.
ReportDownloadOptions options = new ReportDownloadOptions();
options.setExportFormat(ExportFormat.CSV_DUMP);
options.setUseGzipCompression(true);
URL url = reportDownloader.getDownloadUrl(options);
Resources.asByteSource(url).copyTo(Files.asByteSink(file));
System.out.println("done.");
}
use of com.google.api.ads.admanager.axis.v202205.Date in project googleads-java-lib by googleads.
the class GetRecentChanges method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param filePath file path where changes will be saved.
* @throws ApiException if the API request failed with one or more service errors.
* @throws RemoteException if the API request failed due to other errors.
* @throws IOException if unable to write the response to a file.
*/
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session, String filePath) throws IOException {
PublisherQueryLanguageServiceInterface pqlService = adManagerServices.get(session, PublisherQueryLanguageServiceInterface.class);
// Create statement to select recent changes. Change_History only supports ordering by
// descending ChangeDateTime. Offset is not supported. To page, use the change ID of
// the earliest change as a pagination token. A date time range is required
// when querying this table.
DateTime endDateTime = DateTime.now();
DateTime startDateTime = endDateTime.minusDays(1);
StatementBuilder statementBuilder = new StatementBuilder().select("Id, ChangeDateTime, EntityId, EntityType, Operation, UserId").from("Change_History").where("ChangeDateTime < :endDateTime AND ChangeDateTime > :startDateTime").orderBy("ChangeDateTime DESC").withBindVariableValue("startDateTime", DateTimes.toDateTime(startDateTime)).withBindVariableValue("endDateTime", DateTimes.toDateTime(endDateTime)).limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
// Retrieve a small amount of changes at a time, paging through
// until all changes have been retrieved.
ResultSet combinedResultSet = null;
ResultSet resultSet;
int i = 0;
do {
resultSet = pqlService.select(statementBuilder.toStatement());
// Combine result sets with previous ones.
combinedResultSet = combinedResultSet == null ? resultSet : Pql.combineResultSets(combinedResultSet, resultSet);
if (resultSet.getRows() != null && resultSet.getRows().length > 0) {
// Get the earliest change ID in the result set.
int numRows = resultSet.getRows().length;
Row lastRow = resultSet.getRows(numRows - 1);
String id = (String) Pql.getNativeValue(lastRow.getValues(0));
System.out.printf("%d) %d changes prior to ID %s were found.%n", i++, numRows, id);
// Use the earliest change ID in the result set to page.
statementBuilder.where("Id < :id AND ChangeDateTime < :endDateTime AND ChangeDateTime > :startDateTime").withBindVariableValue("id", id);
}
} while (resultSet.getRows() != null && resultSet.getRows().length > 0);
// Write the result set to a CSV.
CsvFiles.writeCsv(Pql.resultSetToStringArrayList(combinedResultSet), filePath);
System.out.printf("Recent changes saved to: %s%n", filePath);
}
use of com.google.api.ads.admanager.axis.v202205.Date in project googleads-java-lib by googleads.
the class RunDeliveryReportForOrder method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param orderId the ID of the order to run the report for.
* @throws ApiException if the API request failed with one or more service errors.
* @throws RemoteException if the API request failed due to other errors.
* @throws IOException if unable to write the response to a file.
* @throws InterruptedException if the thread is interrupted while waiting for the report to
* complete.
*/
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session, long orderId) throws IOException, InterruptedException {
// Get the ReportService.
ReportServiceInterface reportService = adManagerServices.get(session, ReportServiceInterface.class);
// Create report query.
ReportQuery reportQuery = new ReportQuery();
reportQuery.setDimensions(new Dimension[] { Dimension.DATE, Dimension.ORDER_ID });
reportQuery.setColumns(new Column[] { Column.AD_SERVER_IMPRESSIONS, Column.AD_SERVER_CLICKS, Column.AD_SERVER_CTR, Column.AD_SERVER_CPM_AND_CPC_REVENUE });
reportQuery.setDimensionAttributes(new DimensionAttribute[] { DimensionAttribute.ORDER_TRAFFICKER, DimensionAttribute.ORDER_START_DATE_TIME, DimensionAttribute.ORDER_END_DATE_TIME });
// Create statement to filter for an order.
StatementBuilder statementBuilder = new StatementBuilder().where("ORDER_ID = :orderId").withBindVariableValue("orderId", orderId);
// Set the filter statement.
reportQuery.setStatement(statementBuilder.toStatement());
// Set the start and end dates or choose a dynamic date range type.
reportQuery.setDateRangeType(DateRangeType.CUSTOM_DATE);
reportQuery.setStartDate(DateTimes.toDateTime("2013-05-01T00:00:00", "America/New_York").getDate());
reportQuery.setEndDate(DateTimes.toDateTime("2013-05-31T00:00:00", "America/New_York").getDate());
// Create report job.
ReportJob reportJob = new ReportJob();
reportJob.setReportQuery(reportQuery);
// Run report job.
reportJob = reportService.runReportJob(reportJob);
// Create report downloader.
ReportDownloader reportDownloader = new ReportDownloader(reportService, reportJob.getId());
// Wait for the report to be ready.
reportDownloader.waitForReportReady();
// Change to your file location.
File file = File.createTempFile("delivery-report-", ".csv.gz");
System.out.printf("Downloading report to %s ...", file.toString());
// Download the report.
ReportDownloadOptions options = new ReportDownloadOptions();
options.setExportFormat(ExportFormat.CSV_DUMP);
options.setUseGzipCompression(true);
URL url = reportDownloader.getDownloadUrl(options);
Resources.asByteSource(url).copyTo(Files.asByteSink(file));
System.out.println("done.");
}
use of com.google.api.ads.admanager.axis.v202205.Date in project jaxdb by jaxdb.
the class Compiler method createColumn.
private CreateStatement createColumn(final LinkedHashSet<CreateStatement> alterStatements, final $Table table, final $Column column, final Map<String, Map<String, String>> tableNameToEnumToOwner) {
final StringBuilder builder = new StringBuilder();
builder.append(q(column.getName$().text())).append(' ');
// FIXME: Passing null to compile*() methods will throw a NPE
if (column instanceof $Char) {
final $Char type = ($Char) column;
builder.append(getDialect().compileChar(type.getVarying$() != null && type.getVarying$().text(), type.getLength$() == null ? null : type.getLength$().text()));
} else if (column instanceof $Binary) {
final $Binary type = ($Binary) column;
builder.append(getDialect().compileBinary(type.getVarying$() != null && type.getVarying$().text(), type.getLength$() == null ? null : type.getLength$().text()));
} else if (column instanceof $Blob) {
final $Blob type = ($Blob) column;
builder.append(getDialect().compileBlob(type.getLength$() == null ? null : type.getLength$().text()));
} else if (column instanceof $Clob) {
final $Clob type = ($Clob) column;
builder.append(getDialect().compileClob(type.getLength$() == null ? null : type.getLength$().text()));
} else if (column instanceof $Integer) {
builder.append(createIntegerColumn(($Integer) column));
} else if (column instanceof $Float) {
final $Float type = ($Float) column;
builder.append(getDialect().declareFloat(type.getMin$() == null ? null : type.getMin$().text()));
} else if (column instanceof $Double) {
final $Double type = ($Double) column;
builder.append(getDialect().declareDouble(type.getMin$() == null ? null : type.getMin$().text()));
} else if (column instanceof $Decimal) {
final $Decimal type = ($Decimal) column;
builder.append(getDialect().declareDecimal(type.getPrecision$() == null ? null : type.getPrecision$().text(), type.getScale$() == null ? null : type.getScale$().text(), type.getMin$() == null ? null : type.getMin$().text()));
} else if (column instanceof $Date) {
builder.append(getDialect().declareDate());
} else if (column instanceof $Time) {
final $Time type = ($Time) column;
builder.append(getDialect().declareTime(type.getPrecision$() == null ? null : type.getPrecision$().text()));
} else if (column instanceof $Datetime) {
final $Datetime type = ($Datetime) column;
builder.append(getDialect().declareDateTime(type.getPrecision$() == null ? null : type.getPrecision$().text()));
} else if (column instanceof $Boolean) {
builder.append(getDialect().declareBoolean());
} else if (column instanceof $Enum) {
builder.append(getDialect().declareEnum(($Enum) column, tableNameToEnumToOwner));
}
final String autoIncrementFragment = column instanceof $Integer ? $autoIncrement(alterStatements, table, ($Integer) column) : null;
if (autoIncrementFragment == null || autoIncrementFragment.length() == 0) {
final String defaultFragment = $default(column);
if (defaultFragment != null && defaultFragment.length() > 0)
builder.append(" DEFAULT ").append(defaultFragment);
}
final String nullFragment = $null(table, column);
if (nullFragment != null && nullFragment.length() > 0)
builder.append(' ').append(nullFragment);
if (autoIncrementFragment != null && autoIncrementFragment.length() > 0)
builder.append(' ').append(autoIncrementFragment);
return new CreateStatement(builder.toString());
}
Aggregations