Search in sources :

Example 71 with Statement

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);
}
Also used : Creative(com.google.api.ads.admanager.axis.v202205.Creative) CreativeServiceInterface(com.google.api.ads.admanager.axis.v202205.CreativeServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder) CreativePage(com.google.api.ads.admanager.axis.v202205.CreativePage)

Example 72 with Statement

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.");
    }
}
Also used : HasDestinationUrlCreative(com.google.api.ads.admanager.axis.v202205.HasDestinationUrlCreative) HasDestinationUrlCreative(com.google.api.ads.admanager.axis.v202205.HasDestinationUrlCreative) Creative(com.google.api.ads.admanager.axis.v202205.Creative) CreativeServiceInterface(com.google.api.ads.admanager.axis.v202205.CreativeServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder) CreativePage(com.google.api.ads.admanager.axis.v202205.CreativePage)

Example 73 with Statement

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());
}
Also used : Statement(com.google.api.ads.admanager.axis.v202111.Statement) Test(org.junit.Test)

Example 74 with Statement

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());
}
Also used : Statement(com.google.api.ads.admanager.axis.v202111.Statement) Test(org.junit.Test)

Example 75 with Statement

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());
}
Also used : String_ValueMapEntry(com.google.api.ads.admanager.axis.v202111.String_ValueMapEntry) Statement(com.google.api.ads.admanager.axis.v202111.Statement) Test(org.junit.Test)

Aggregations

StatementBuilder (com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder)119 Test (org.junit.Test)77 UpdateResult (com.google.api.ads.admanager.axis.v202205.UpdateResult)18 Statement (com.google.api.ads.admanager.axis.v202105.Statement)16 Statement (com.google.api.ads.admanager.axis.v202108.Statement)16 Statement (com.google.api.ads.admanager.axis.v202111.Statement)16 Statement (com.google.api.ads.admanager.axis.v202202.Statement)16 Statement (com.google.api.ads.admanager.axis.v202205.Statement)16 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202205.CustomTargetingServiceInterface)8 InventoryServiceInterface (com.google.api.ads.admanager.axis.v202205.InventoryServiceInterface)8 AdUnit (com.google.api.ads.admanager.axis.v202205.AdUnit)7 AdUnitPage (com.google.api.ads.admanager.axis.v202205.AdUnitPage)7 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202205.PublisherQueryLanguageServiceInterface)7 ResultSet (com.google.api.ads.admanager.axis.v202205.ResultSet)7 Statement (org.neo4j.driver.v1.Statement)5 String_ValueMapEntry (com.google.api.ads.admanager.axis.v202105.String_ValueMapEntry)4 String_ValueMapEntry (com.google.api.ads.admanager.axis.v202108.String_ValueMapEntry)4 String_ValueMapEntry (com.google.api.ads.admanager.axis.v202111.String_ValueMapEntry)4 String_ValueMapEntry (com.google.api.ads.admanager.axis.v202202.String_ValueMapEntry)4 CustomFieldServiceInterface (com.google.api.ads.admanager.axis.v202205.CustomFieldServiceInterface)4