Search in sources :

Example 1 with ChildPublisher

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

the class CreateSites method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param childNetworkCode the child network code of the site.
 * @param url the URL of the site.
 * @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, String childNetworkCode, String url) throws RemoteException {
    // Get the SiteService.
    SiteServiceInterface siteService = adManagerServices.get(session, SiteServiceInterface.class);
    // Get the NetworkService.
    NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
    // Validate that the site can be created.
    Network currentNetwork = networkService.getCurrentNetwork();
    ChildPublisher childNetwork = null;
    for (ChildPublisher child : currentNetwork.getChildPublishers()) {
        if (childNetworkCode.equals(child.getChildNetworkCode())) {
            childNetwork = child;
            break;
        }
    }
    if (childNetwork == null) {
        throw new IllegalStateException(String.format("Child network %s not found on the current network (%s). Cannot create site.", childNetworkCode, currentNetwork.getNetworkCode()));
    }
    if (!DelegationType.MANAGE_INVENTORY.equals(childNetwork.getApprovedDelegationType())) {
        throw new IllegalStateException(String.format("Child network %s has not approved the current network (%s) to manage its inventory." + " Cannot create site.", childNetworkCode, currentNetwork.getNetworkCode()));
    }
    // Create a site.
    Site site = new Site();
    site.setChildNetworkCode(childNetworkCode);
    site.setUrl(url);
    // Create the site on the server.
    Site[] sites = siteService.createSites(new Site[] { site });
    for (Site createdSite : sites) {
        System.out.printf("A site with ID %d and URL '%s' was created.%n", createdSite.getId(), createdSite.getUrl());
    }
}
Also used : Site(com.google.api.ads.admanager.axis.v202111.Site) NetworkServiceInterface(com.google.api.ads.admanager.axis.v202111.NetworkServiceInterface) SiteServiceInterface(com.google.api.ads.admanager.axis.v202111.SiteServiceInterface) ChildPublisher(com.google.api.ads.admanager.axis.v202111.ChildPublisher) Network(com.google.api.ads.admanager.axis.v202111.Network)

Example 2 with ChildPublisher

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

the class CreateSites method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param childNetworkCode the child network code of the site.
 * @param url the URL of the site.
 * @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, String childNetworkCode, String url) throws RemoteException {
    // Get the SiteService.
    SiteServiceInterface siteService = adManagerServices.get(session, SiteServiceInterface.class);
    // Get the NetworkService.
    NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
    // Validate that the site can be created.
    Network currentNetwork = networkService.getCurrentNetwork();
    ChildPublisher childNetwork = null;
    for (ChildPublisher child : currentNetwork.getChildPublishers()) {
        if (childNetworkCode.equals(child.getChildNetworkCode())) {
            childNetwork = child;
            break;
        }
    }
    if (childNetwork == null) {
        throw new IllegalStateException(String.format("Child network %s not found on the current network (%s). Cannot create site.", childNetworkCode, currentNetwork.getNetworkCode()));
    }
    if (!DelegationType.MANAGE_INVENTORY.equals(childNetwork.getApprovedDelegationType())) {
        throw new IllegalStateException(String.format("Child network %s has not approved the current network (%s) to manage its inventory." + " Cannot create site.", childNetworkCode, currentNetwork.getNetworkCode()));
    }
    // Create a site.
    Site site = new Site();
    site.setChildNetworkCode(childNetworkCode);
    site.setUrl(url);
    // Create the site on the server.
    Site[] sites = siteService.createSites(new Site[] { site });
    for (Site createdSite : sites) {
        System.out.printf("A site with ID %d and URL '%s' was created.%n", createdSite.getId(), createdSite.getUrl());
    }
}
Also used : Site(com.google.api.ads.admanager.axis.v202108.Site) NetworkServiceInterface(com.google.api.ads.admanager.axis.v202108.NetworkServiceInterface) SiteServiceInterface(com.google.api.ads.admanager.axis.v202108.SiteServiceInterface) ChildPublisher(com.google.api.ads.admanager.axis.v202108.ChildPublisher) Network(com.google.api.ads.admanager.axis.v202108.Network)

Example 3 with ChildPublisher

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

the class CreateSites method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param childNetworkCode the child network code of the site.
 * @param url the URL of the site.
 * @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, String childNetworkCode, String url) throws RemoteException {
    // Get the SiteService.
    SiteServiceInterface siteService = adManagerServices.get(session, SiteServiceInterface.class);
    // Get the NetworkService.
    NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
    // Validate that the site can be created.
    Network currentNetwork = networkService.getCurrentNetwork();
    ChildPublisher childNetwork = null;
    for (ChildPublisher child : currentNetwork.getChildPublishers()) {
        if (childNetworkCode.equals(child.getChildNetworkCode())) {
            childNetwork = child;
            break;
        }
    }
    if (childNetwork == null) {
        throw new IllegalStateException(String.format("Child network %s not found on the current network (%s). Cannot create site.", childNetworkCode, currentNetwork.getNetworkCode()));
    }
    if (!DelegationType.MANAGE_INVENTORY.equals(childNetwork.getApprovedDelegationType())) {
        throw new IllegalStateException(String.format("Child network %s has not approved the current network (%s) to manage its inventory." + " Cannot create site.", childNetworkCode, currentNetwork.getNetworkCode()));
    }
    // Create a site.
    Site site = new Site();
    site.setChildNetworkCode(childNetworkCode);
    site.setUrl(url);
    // Create the site on the server.
    Site[] sites = siteService.createSites(new Site[] { site });
    for (Site createdSite : sites) {
        System.out.printf("A site with ID %d and URL '%s' was created.%n", createdSite.getId(), createdSite.getUrl());
    }
}
Also used : Site(com.google.api.ads.admanager.axis.v202202.Site) NetworkServiceInterface(com.google.api.ads.admanager.axis.v202202.NetworkServiceInterface) SiteServiceInterface(com.google.api.ads.admanager.axis.v202202.SiteServiceInterface) ChildPublisher(com.google.api.ads.admanager.axis.v202202.ChildPublisher) Network(com.google.api.ads.admanager.axis.v202202.Network)

Aggregations

ChildPublisher (com.google.api.ads.admanager.axis.v202108.ChildPublisher)1 Network (com.google.api.ads.admanager.axis.v202108.Network)1 NetworkServiceInterface (com.google.api.ads.admanager.axis.v202108.NetworkServiceInterface)1 Site (com.google.api.ads.admanager.axis.v202108.Site)1 SiteServiceInterface (com.google.api.ads.admanager.axis.v202108.SiteServiceInterface)1 ChildPublisher (com.google.api.ads.admanager.axis.v202111.ChildPublisher)1 Network (com.google.api.ads.admanager.axis.v202111.Network)1 NetworkServiceInterface (com.google.api.ads.admanager.axis.v202111.NetworkServiceInterface)1 Site (com.google.api.ads.admanager.axis.v202111.Site)1 SiteServiceInterface (com.google.api.ads.admanager.axis.v202111.SiteServiceInterface)1 ChildPublisher (com.google.api.ads.admanager.axis.v202202.ChildPublisher)1 Network (com.google.api.ads.admanager.axis.v202202.Network)1 NetworkServiceInterface (com.google.api.ads.admanager.axis.v202202.NetworkServiceInterface)1 Site (com.google.api.ads.admanager.axis.v202202.Site)1 SiteServiceInterface (com.google.api.ads.admanager.axis.v202202.SiteServiceInterface)1