use of com.google.api.ads.admanager.axis.v202205.Statement in project googleads-java-lib by googleads.
the class GetImageCreatives 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 {
CreativeServiceInterface creativeService = adManagerServices.get(session, CreativeServiceInterface.class);
// Create a statement to select creatives.
StatementBuilder statementBuilder = new StatementBuilder().where("creativeType = :creativeType").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("creativeType", "ImageCreative");
// Retrieve a small amount of creatives at a time, paging through
// until all creatives have been retrieved.
int totalResultSetSize = 0;
do {
CreativePage page = creativeService.getCreativesByStatement(statementBuilder.toStatement());
if (page.getResults() != null) {
// Print out some information for each creative.
totalResultSetSize = page.getTotalResultSetSize();
int i = page.getStartIndex();
for (Creative creative : page.getResults()) {
System.out.printf("%d) Creative with ID %d and name '%s' was found.%n", i++, creative.getId(), creative.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.Statement in project googleads-java-lib by googleads.
the class UpdateCreatives method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param creativeId the ID of the creative to update.
* @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 creativeId) throws RemoteException {
// Get the CreativeService.
CreativeServiceInterface creativeService = adManagerServices.get(session, CreativeServiceInterface.class);
// Create a statement to only select a single creative by ID.
StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", creativeId);
// Get the creative.
CreativePage page = creativeService.getCreativesByStatement(statementBuilder.toStatement());
Creative creative = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
// Only update the destination URL if it has one.
if (creative instanceof HasDestinationUrlCreative) {
HasDestinationUrlCreative hasDestinationUrlCreative = (HasDestinationUrlCreative) creative;
// Update the destination URL of the creative.
hasDestinationUrlCreative.setDestinationUrl("http://news.google.com");
// Update the creative on the server.
Creative[] creatives = creativeService.updateCreatives(new Creative[] { creative });
for (Creative updatedCreative : creatives) {
System.out.printf("Creative with ID %d and name '%s' was updated.%n", updatedCreative.getId(), updatedCreative.getName());
}
} else {
System.out.println("No creatives were updated.");
}
}
use of com.google.api.ads.admanager.axis.v202205.Statement in project googleads-java-lib by googleads.
the class StatementBuilderTest method testFrom_stripsFrom.
@Test
public void testFrom_stripsFrom() {
StatementBuilder statementBuilder = new StatementBuilder();
Statement statement = statementBuilder.from("FROM line_item").toStatement();
assertEquals("FROM line_item", statement.getQuery());
}
use of com.google.api.ads.admanager.axis.v202205.Statement in project googleads-java-lib by googleads.
the class StatementBuilderTest method testWhere.
@Test
public void testWhere() {
StatementBuilder statementBuilder = new StatementBuilder();
Statement statement = statementBuilder.where("id = 12345").toStatement();
assertEquals("WHERE id = 12345", statement.getQuery());
}
use of com.google.api.ads.admanager.axis.v202205.Statement in project googleads-java-lib by googleads.
the class StatementBuilderTest method testBindVariables_text.
@Test
public void testBindVariables_text() {
StatementBuilder statementBuilder = new StatementBuilder();
Statement statement = statementBuilder.where("text = :text").withBindVariableValue("text", "foo").toStatement();
String_ValueMapEntry entry = statement.getValues(0);
assertEquals("text", entry.getKey());
assertEquals(TextValue.class, entry.getValue().getClass());
assertEquals("foo", ((TextValue) entry.getValue()).getValue());
}
Aggregations