use of com.google.api.ads.admanager.axis.v202205.DateTime in project googleads-java-lib by googleads.
the class PqlTest method testCreateValue_dateTimeSet.
@Test
public void testCreateValue_dateTimeSet() {
Set<DateTime> dateTimeSet = new LinkedHashSet<DateTime>();
dateTimeSet.add(dateTime1);
Value value1 = ((SetValue) Pql.createValue(dateTimeSet)).getValues(0);
assertEquals("2012-12-02T12:45:00+08:00", DateTimes.toStringWithTimeZone(((DateTimeValue) value1).getValue()));
}
use of com.google.api.ads.admanager.axis.v202205.DateTime in project clinical_quality_language by cqframework.
the class DateTimeInvocation method getOperands.
@Override
public Iterable<Expression> getOperands() {
DateTime dt = (DateTime) expression;
List<Expression> opList = Arrays.asList(dt.getYear(), dt.getMonth(), dt.getDay(), dt.getHour(), dt.getMinute(), dt.getSecond(), dt.getMillisecond(), dt.getTimezoneOffset());
// If the last expression is null, we should trim this down
int i;
for (i = 7; i > 0 && opList.get(i) == null; i--) ;
return opList.subList(0, i + 1);
}
use of com.google.api.ads.admanager.axis.v202205.DateTime in project googleads-java-lib by googleads.
the class GetTrafficData method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param advertiserId the ID of the advertiser (company) to forecast for. Setting an advertiser
* will cause the forecast to apply the appropriate unified blocking rules.
* @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(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
// Get the ForecastService.
ForecastServiceInterface forecastService = adManagerServices.get(session, ForecastServiceInterface.class);
// Get the NetworkService.
NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
// Get the root ad unit ID used to target the whole site.
String rootAdUnitId = networkService.getCurrentNetwork().getEffectiveRootAdUnitId();
// Create inventory targeting.
InventoryTargeting inventoryTargeting = new InventoryTargeting();
// Create ad unit targeting for the root ad unit.
AdUnitTargeting adUnitTargeting = new AdUnitTargeting();
adUnitTargeting.setAdUnitId(rootAdUnitId);
adUnitTargeting.setIncludeDescendants(true);
inventoryTargeting.setTargetedAdUnits(new AdUnitTargeting[] { adUnitTargeting });
// Create targeting.
Targeting targeting = new Targeting();
targeting.setInventoryTargeting(inventoryTargeting);
// Create the date range. Include the previous and next 7 days.
Interval interval = new Interval(Instant.now().plus(Duration.standardDays(-7)), Instant.now().plus(Duration.standardDays(7)));
DateRange dateRange = new DateRange();
dateRange.setStartDate(DateTimes.toDateTime(interval.getStart()).getDate());
dateRange.setEndDate(DateTimes.toDateTime(interval.getEnd()).getDate());
// Request the traffic data.
TrafficDataRequest trafficDataRequest = new TrafficDataRequest();
trafficDataRequest.setRequestedDateRange(dateRange);
trafficDataRequest.setTargeting(targeting);
TrafficDataResponse trafficData = forecastService.getTrafficData(trafficDataRequest);
// Read the historical traffic data.
TimeSeries historicalTimeSeries = trafficData.getHistoricalTimeSeries();
if (historicalTimeSeries != null) {
Date historicalStartDate = historicalTimeSeries.getTimeSeriesDateRange().getStartDate();
DateTime historicalStart = new DateTime(historicalStartDate.getYear(), historicalStartDate.getMonth(), historicalStartDate.getDay(), 0, 0, 0);
for (int i = 0; i < historicalTimeSeries.getValues().length; i++) {
System.out.printf("%s: %d historical ad opportunities%n", historicalStart.plus(Duration.standardDays(i)).toString(DateTimeFormat.longDate()), historicalTimeSeries.getValues()[i]);
}
}
// Read the forecasted traffic data.
TimeSeries forecastedTimeSeries = trafficData.getForecastedTimeSeries();
if (forecastedTimeSeries != null) {
Date forecastedStartDate = forecastedTimeSeries.getTimeSeriesDateRange().getStartDate();
DateTime forecastedStart = new DateTime(forecastedStartDate.getYear(), forecastedStartDate.getMonth(), forecastedStartDate.getDay(), 0, 0, 0);
for (int i = 0; i < forecastedTimeSeries.getValues().length; i++) {
System.out.printf("%s: %d forecasted ad opportunities%n", forecastedStart.plus(Duration.standardDays(i)).toString(DateTimeFormat.longDate()), forecastedTimeSeries.getValues()[i]);
}
}
}
use of com.google.api.ads.admanager.axis.v202205.DateTime in project googleads-java-lib by googleads.
the class GetMcmEarnings 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.
*/
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws IOException {
// Get the PublisherQueryLanguageService.
PublisherQueryLanguageServiceInterface pqlService = adManagerServices.get(session, PublisherQueryLanguageServiceInterface.class);
DateTime lastMonth = DateTime.now().minusMonths(1).withDayOfMonth(1);
// Create statement to select earnings data from the prior month.
StatementBuilder statementBuilder = new StatementBuilder().select("Month, ChildName, ChildNetworkCode, TotalEarningsCurrencyCode," + " TotalEarningsMicros, ParentPaymentCurrencyCode, ParentPaymentMicros," + " ChildPaymentCurrencyCode, ChildPaymentMicros, DeductionsMicros").from("mcm_earnings").where("Month = :month").orderBy("ChildNetworkCode").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("month", DateTimes.toDateTime(lastMonth).getDate());
// Default for result sets.
ResultSet combinedResultSet = null;
ResultSet resultSet;
int i = 0;
do {
// Get all earnings information.
resultSet = pqlService.select(statementBuilder.toStatement());
// Combine result sets with previous ones.
combinedResultSet = combinedResultSet == null ? resultSet : Pql.combineResultSets(combinedResultSet, resultSet);
System.out.printf("%d) %d rows beginning at offset %d were found.%n", i++, resultSet.getRows() == null ? 0 : resultSet.getRows().length, statementBuilder.getOffset());
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (resultSet.getRows() != null && resultSet.getRows().length > 0);
// Change to your file location.
String filePath = File.createTempFile("EarningsReport-", ".csv").toString();
// Write the result set to a CSV.
CsvFiles.writeCsv(Pql.resultSetToStringArrayList(combinedResultSet), filePath);
System.out.printf("Earnings information saved to: %s%n", filePath);
}
use of com.google.api.ads.admanager.axis.v202205.DateTime 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);
}
Aggregations