use of com.google.api.ads.admanager.axis.v202205.Order 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.Order in project googleads-java-lib by googleads.
the class ApproveOrders method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param orderId the ID of the order to approve.
* @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, long orderId) throws RemoteException {
// Get the OrderService.
OrderServiceInterface orderService = adManagerServices.get(session, OrderServiceInterface.class);
// Create a statement to select an order.
StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", orderId);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get orders by statement.
OrderPage page = orderService.getOrdersByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (Order order : page.getResults()) {
System.out.printf("%d) Order with ID %d will be approved.%n", i++, order.getId());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of orders to be approved: %d%n", totalResultSetSize);
if (totalResultSetSize > 0) {
// Remove limit and offset from statement.
statementBuilder.removeLimitAndOffset();
// Create action.
com.google.api.ads.admanager.axis.v202205.ApproveOrders action = new com.google.api.ads.admanager.axis.v202205.ApproveOrders();
// Perform action.
UpdateResult result = orderService.performOrderAction(action, statementBuilder.toStatement());
if (result != null && result.getNumChanges() > 0) {
System.out.printf("Number of orders approved: %d%n", result.getNumChanges());
} else {
System.out.println("No orders were approved.");
}
}
}
use of com.google.api.ads.admanager.axis.v202205.Order in project googleads-java-lib by googleads.
the class CreateOrders method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param advertiserId the ID of the advertiser (company) that all creatives will be assigned to.
* @param traffickerId the ID of the trafficker (user) associated with this order.
* @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, long advertiserId, long traffickerId) throws RemoteException {
// Get the OrderService.
OrderServiceInterface orderService = adManagerServices.get(session, OrderServiceInterface.class);
// Create an order.
Order order = new Order();
order.setName("Order #" + new Random().nextInt(Integer.MAX_VALUE));
order.setAdvertiserId(advertiserId);
order.setTraffickerId(traffickerId);
// Create the order on the server.
Order[] orders = orderService.createOrders(new Order[] { order });
for (Order createdOrder : orders) {
System.out.printf("An order with ID %d and name '%s' was created.%n", createdOrder.getId(), createdOrder.getName());
}
}
use of com.google.api.ads.admanager.axis.v202205.Order in project testnorge by navikt.
the class OrderController method updateBestilling.
@PutMapping("/{uuid}/items/{id}")
public ResponseEntity<HttpStatus> updateBestilling(@PathVariable("uuid") String uuid, @PathVariable("id") Long id, @RequestBody OrderDTO dto) {
log.info("Oppdaterer bestilling med uuid: {} og id: {}", uuid, id);
service.update(new Order(dto, uuid), id);
URI uri = ServletUriComponentsBuilder.fromCurrentRequest().path("/items/{id}").buildAndExpand(id).toUri();
return ResponseEntity.created(uri).build();
}
use of com.google.api.ads.admanager.axis.v202205.Order in project testnorge by navikt.
the class OrderControllerV2 method opprett.
@PostMapping
public ResponseEntity<OrderDTO> opprett(@RequestBody OrderDTO dto) {
var order = service.save(new Order(dto));
URI uri = ServletUriComponentsBuilder.fromCurrentRequest().path("/items/{id}").buildAndExpand(order.getId()).toUri();
return ResponseEntity.created(uri).body(order.toDTO());
}
Aggregations