Search in sources :

Example 21 with Statement

use of com.google.api.ads.admanager.axis.v202202.Statement in project googleads-java-lib by googleads.

the class RequestBuyerAcceptance method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param proposalId the proposal ID to send.
 * @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 proposalId) throws RemoteException {
    // Get the ProposalService.
    ProposalServiceInterface proposalService = adManagerServices.get(session, ProposalServiceInterface.class);
    // Create a statement to only select a single proposal by ID.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", proposalId);
    // Retrieve a small amount of proposals at a time, paging through until all
    // proposals have been retrieved.
    int totalResultSetSize = 0;
    do {
        ProposalPage page = proposalService.getProposalsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            // Print out some information for each proposal.
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Proposal proposal : page.getResults()) {
                System.out.printf("%d) Proposal with ID %d and name '%s' will be sent to Marketplace for buyer " + "acceptance.%n", i++, proposal.getId(), proposal.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of proposals to be sent to Marketplace for buyer acceptance: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        com.google.api.ads.admanager.axis.v202202.RequestBuyerAcceptance action = new com.google.api.ads.admanager.axis.v202202.RequestBuyerAcceptance();
        // Perform action.
        UpdateResult result = proposalService.performProposalAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of proposals that were sent to Marketplace for buyer acceptance: %d%n", result.getNumChanges());
        } else {
            System.out.println("No proposals were sent to Marketplace for buyer acceptance.");
        }
    }
}
Also used : ProposalServiceInterface(com.google.api.ads.admanager.axis.v202202.ProposalServiceInterface) ProposalPage(com.google.api.ads.admanager.axis.v202202.ProposalPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) Proposal(com.google.api.ads.admanager.axis.v202202.Proposal) UpdateResult(com.google.api.ads.admanager.axis.v202202.UpdateResult)

Example 22 with Statement

use of com.google.api.ads.admanager.axis.v202202.Statement in project googleads-java-lib by googleads.

the class GetAllOrders 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 OrderService.
    OrderServiceInterface orderService = adManagerServices.get(session, OrderServiceInterface.class);
    // Create a statement to select all orders.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // 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 and name '%s' was found.%n", i++, order.getId(), order.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : Order(com.google.api.ads.admanager.axis.v202202.Order) OrderPage(com.google.api.ads.admanager.axis.v202202.OrderPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) OrderServiceInterface(com.google.api.ads.admanager.axis.v202202.OrderServiceInterface)

Example 23 with Statement

use of com.google.api.ads.admanager.axis.v202202.Statement in project googleads-java-lib by googleads.

the class GetAllLineItems 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 LineItemService.
    LineItemServiceInterface lineItemService = adManagerServices.get(session, LineItemServiceInterface.class);
    // Create a statement to select all line items.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get line items by statement.
        LineItemPage page = lineItemService.getLineItemsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (LineItem lineItem : page.getResults()) {
                System.out.printf("%d) Line item with ID %d and name '%s' was found.%n", i++, lineItem.getId(), lineItem.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : LineItemServiceInterface(com.google.api.ads.admanager.axis.v202202.LineItemServiceInterface) LineItemPage(com.google.api.ads.admanager.axis.v202202.LineItemPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) LineItem(com.google.api.ads.admanager.axis.v202202.LineItem)

Example 24 with Statement

use of com.google.api.ads.admanager.axis.v202202.Statement in project googleads-java-lib by googleads.

the class UpdateLineItems method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param lineItemId the ID of the line item 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 lineItemId) throws RemoteException {
    // Get the LineItemService.
    LineItemServiceInterface lineItemService = adManagerServices.get(session, LineItemServiceInterface.class);
    // Create a statement to only select a single line item by ID.
    StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", lineItemId);
    // Get the line item.
    LineItemPage page = lineItemService.getLineItemsByStatement(statementBuilder.toStatement());
    LineItem lineItem = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
    // Update the line item's priority to High if possible.
    if (lineItem.getLineItemType().equals(LineItemType.STANDARD)) {
        lineItem.setPriority(6);
        // Update the line item on the server.
        LineItem[] lineItems = lineItemService.updateLineItems(new LineItem[] { lineItem });
        for (LineItem updatedLineItem : lineItems) {
            System.out.printf("Line item with ID %d and name '%s' was updated.%n", updatedLineItem.getId(), updatedLineItem.getName());
        }
    } else {
        System.out.println("No line items were updated.");
    }
}
Also used : LineItemServiceInterface(com.google.api.ads.admanager.axis.v202202.LineItemServiceInterface) LineItemPage(com.google.api.ads.admanager.axis.v202202.LineItemPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) LineItem(com.google.api.ads.admanager.axis.v202202.LineItem)

Example 25 with Statement

use of com.google.api.ads.admanager.axis.v202202.Statement in project googleads-java-lib by googleads.

the class GetAllNativeStyles 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 {
    NativeStyleServiceInterface nativeStyleService = adManagerServices.get(session, NativeStyleServiceInterface.class);
    // Create a statement to select native styles.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Retrieve a small amount of native styles at a time, paging through
    // until all native styles have been retrieved.
    int totalResultSetSize = 0;
    do {
        NativeStylePage page = nativeStyleService.getNativeStylesByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            // Print out some information for each native style.
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (NativeStyle nativeStyle : page.getResults()) {
                System.out.printf("%d) Native style with ID %d and name '%s' was found.%n", i++, nativeStyle.getId(), nativeStyle.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : NativeStyleServiceInterface(com.google.api.ads.admanager.axis.v202202.NativeStyleServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) NativeStylePage(com.google.api.ads.admanager.axis.v202202.NativeStylePage) NativeStyle(com.google.api.ads.admanager.axis.v202202.NativeStyle)

Aggregations

StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)119 Test (org.junit.Test)61 UpdateResult (com.google.api.ads.admanager.axis.v202202.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 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202202.CustomTargetingServiceInterface)8 InventoryServiceInterface (com.google.api.ads.admanager.axis.v202202.InventoryServiceInterface)8 AdUnit (com.google.api.ads.admanager.axis.v202202.AdUnit)7 AdUnitPage (com.google.api.ads.admanager.axis.v202202.AdUnitPage)7 LineItem (com.google.api.ads.admanager.axis.v202202.LineItem)6 LineItemPage (com.google.api.ads.admanager.axis.v202202.LineItemPage)6 LineItemServiceInterface (com.google.api.ads.admanager.axis.v202202.LineItemServiceInterface)6 LineItemCreativeAssociationServiceInterface (com.google.api.ads.admanager.axis.v202202.LineItemCreativeAssociationServiceInterface)5 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202202.PublisherQueryLanguageServiceInterface)5 ResultSet (com.google.api.ads.admanager.axis.v202202.ResultSet)5 CustomTargetingValue (com.google.api.ads.admanager.axis.v202202.CustomTargetingValue)4 CustomTargetingValuePage (com.google.api.ads.admanager.axis.v202202.CustomTargetingValuePage)4 String_ValueMapEntry (com.google.api.ads.admanager.axis.v202202.String_ValueMapEntry)4