use of com.google.api.ads.admanager.axis.v202205.Placement in project googleads-java-lib by googleads.
the class DeactivatePlacements method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param placementId the ID of the placement to deactivate.
* @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 placementId) throws RemoteException {
// Get the PlacementService.
PlacementServiceInterface placementService = adManagerServices.get(session, PlacementServiceInterface.class);
// Create a statement to select a placement.
StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", placementId);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get placements by statement.
PlacementPage page = placementService.getPlacementsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (Placement placement : page.getResults()) {
System.out.printf("%d) Placement with ID %d will be deactivated.%n", i++, placement.getId());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of placements to be deactivated: %d%n", totalResultSetSize);
if (totalResultSetSize > 0) {
// Remove limit and offset from statement.
statementBuilder.removeLimitAndOffset();
// Create action.
com.google.api.ads.admanager.axis.v202205.DeactivatePlacements action = new com.google.api.ads.admanager.axis.v202205.DeactivatePlacements();
// Perform action.
UpdateResult result = placementService.performPlacementAction(action, statementBuilder.toStatement());
if (result != null && result.getNumChanges() > 0) {
System.out.printf("Number of placements deactivated: %d%n", result.getNumChanges());
} else {
System.out.println("No placements were deactivated.");
}
}
}
use of com.google.api.ads.admanager.axis.v202205.Placement in project googleads-java-lib by googleads.
the class GetAllPlacements 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 RemoteException {
// Get the PlacementService.
PlacementServiceInterface placementService = adManagerServices.get(session, PlacementServiceInterface.class);
// Create a statement to get all placements.
StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
// Default for total result set size.
int totalResultSetSize = 0;
do {
// Get placements by statement.
PlacementPage page = placementService.getPlacementsByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (Placement placement : page.getResults()) {
System.out.printf("%d) Placement with ID %d and name '%s' was found.%n", i++, placement.getId(), placement.getName());
}
}
statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
} while (statementBuilder.getOffset() < totalResultSetSize);
System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
use of com.google.api.ads.admanager.axis.v202205.Placement in project kubernetes-client by fabric8io.
the class PlacementTest method get.
@Test
void get() {
// Given
server.expect().get().withPath("/apis/cluster.open-cluster-management.io/v1alpha1/namespaces/ns1/placements/test-get").andReturn(HttpURLConnection.HTTP_OK, createNewPlacement("test-get")).once();
// When
Placement placement = client.clusters().placements().inNamespace("ns1").withName("test-get").get();
// Then
assertThat(placement).isNotNull().hasFieldOrPropertyWithValue("metadata.name", "test-get");
}
Aggregations