Search in sources :

Example 26 with Company

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

the class GetAllCompanies 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 CompanyService.
    CompanyServiceInterface companyService = adManagerServices.get(session, CompanyServiceInterface.class);
    // Create a statement to get all companies.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get companies by statement.
        CompanyPage page = companyService.getCompaniesByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Company company : page.getResults()) {
                System.out.printf("%d) Company with ID %d, name '%s', and type '%s' was found.%n", i++, company.getId(), company.getName(), company.getType());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : CompanyServiceInterface(com.google.api.ads.admanager.axis.v202111.CompanyServiceInterface) Company(com.google.api.ads.admanager.axis.v202111.Company) CompanyPage(com.google.api.ads.admanager.axis.v202111.CompanyPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)

Example 27 with Company

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

the class UpdateCompanies method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param companyId the ID of the company 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 companyId) throws RemoteException {
    // Get the CompanyService.
    CompanyServiceInterface companyService = adManagerServices.get(session, CompanyServiceInterface.class);
    // Create a statement to only select a single company by ID.
    StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", companyId);
    // Get the company.
    CompanyPage page = companyService.getCompaniesByStatement(statementBuilder.toStatement());
    Company company = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
    // Update the comment.
    company.setComment(company.getComment() + " Updated.");
    // Update the company on the server.
    Company[] companies = companyService.updateCompanies(new Company[] { company });
    for (Company updatedCompany : companies) {
        System.out.printf("Company with ID %d, name '%s', and comment '%s' was updated.%n", updatedCompany.getId(), updatedCompany.getName(), updatedCompany.getComment());
    }
}
Also used : CompanyServiceInterface(com.google.api.ads.admanager.axis.v202111.CompanyServiceInterface) Company(com.google.api.ads.admanager.axis.v202111.Company) CompanyPage(com.google.api.ads.admanager.axis.v202111.CompanyPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)

Example 28 with Company

use of com.google.api.ads.admanager.axis.v202108.Company 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());
    }
}
Also used : Order(com.google.api.ads.admanager.axis.v202108.Order) Random(java.util.Random) OrderServiceInterface(com.google.api.ads.admanager.axis.v202108.OrderServiceInterface)

Aggregations

Random (java.util.Random)10 Company (com.google.api.ads.admanager.axis.v202202.Company)7 CompanyServiceInterface (com.google.api.ads.admanager.axis.v202202.CompanyServiceInterface)7 AdManagerSession (com.google.api.ads.admanager.lib.client.AdManagerSession)6 Size (com.google.api.ads.admanager.axis.v202108.Size)5 MockHttpIntegrationTest (com.google.api.ads.common.lib.testing.MockHttpIntegrationTest)5 GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)5 Test (org.junit.Test)5 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)4 Company (com.google.api.ads.admanager.axis.v202108.Company)4 CompanyServiceInterface (com.google.api.ads.admanager.axis.v202108.CompanyServiceInterface)4 Creative (com.google.api.ads.admanager.axis.v202108.Creative)4 CreativeAsset (com.google.api.ads.admanager.axis.v202108.CreativeAsset)4 CreativeServiceInterface (com.google.api.ads.admanager.axis.v202108.CreativeServiceInterface)4 Company (com.google.api.ads.admanager.axis.v202111.Company)4 CompanyServiceInterface (com.google.api.ads.admanager.axis.v202111.CompanyServiceInterface)4 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)4 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)4 Diff (org.xmlunit.diff.Diff)4 AdManagerServices (com.google.api.ads.admanager.axis.factory.AdManagerServices)3