Search in sources :

Example 1 with Dimensions

use of com.google.api.ads.adwords.axis.v201809.cm.Dimensions in project googleads-java-lib by googleads.

the class GetAllImagesAndVideos method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices 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(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException {
    // Get the MediaService.
    MediaServiceInterface mediaService = adWordsServices.get(session, MediaServiceInterface.class);
    int offset = 0;
    // Create selector.
    SelectorBuilder builder = new SelectorBuilder();
    Selector selector = builder.fields(MediaField.MediaId, MediaField.Width, MediaField.Height, MediaField.MimeType).orderAscBy(MediaField.MediaId).offset(offset).limit(PAGE_SIZE).in(MediaField.Type, "IMAGE", "VIDEO").build();
    MediaPage page = null;
    do {
        // Get all images.
        page = mediaService.get(selector);
        // Display images.
        if (page != null && page.getEntries() != null) {
            for (Media media : page.getEntries()) {
                Map<MediaSize, Dimensions> dimensions = Maps.toMap(media.getDimensions());
                System.out.printf("Media with ID %d, dimensions %s, and MIME type '%s' was found.%n", media.getMediaId(), toString(dimensions.get(MediaSize.FULL)), media.getMediaType());
            }
        } else {
            System.out.println("No images/videos were found.");
        }
        offset += PAGE_SIZE;
        selector = builder.increaseOffsetBy(PAGE_SIZE).build();
    } while (offset < page.getTotalNumEntries());
}
Also used : MediaSize(com.google.api.ads.adwords.axis.v201809.cm.MediaSize) SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) MediaPage(com.google.api.ads.adwords.axis.v201809.cm.MediaPage) MediaServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.MediaServiceInterface) Media(com.google.api.ads.adwords.axis.v201809.cm.Media) Dimensions(com.google.api.ads.adwords.axis.v201809.cm.Dimensions) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Example 2 with Dimensions

use of com.google.api.ads.adwords.axis.v201809.cm.Dimensions in project googleads-java-lib by googleads.

the class ProductPartitionTreeImpl method addMutateOperations.

/**
 * Adds to the operations list all operations required to mutate {@code originalNode} to the state
 * of {@code newNode}.
 *
 * <p>The returned set of child product dimensions will only <em>potentially</em> be non-empty if
 * both {@code originalNode != null} and {@code newNode != null}.
 *
 * @param originalNode may be null
 * @param newNode may be null
 * @param ops the operations list to add to
 *
 * @return the set of child product dimensions that require further processing
 */
private Set<ProductDimension> addMutateOperations(@Nullable ProductPartitionNode originalNode, @Nullable ProductPartitionNode newNode, List<OperationPair> ops) {
    Set<ProductDimension> childDimensionsToProcess = Sets.newTreeSet(dimensionComparator);
    NodeDifference nodeDifference = ProductPartitionNodeDiffer.diff(originalNode, newNode, dimensionComparator);
    boolean isProcessChildren;
    switch(nodeDifference) {
        case NEW_NODE:
            ops.addAll(createAddOperations(newNode));
            // No need to further process children. The ADD operations above will include operations
            // for all children of newNode.
            isProcessChildren = false;
            break;
        case REMOVED_NODE:
            ops.add(createRemoveOperation(originalNode));
            // No need to further process children. The REMOVE operation above will perform a
            // cascading delete of all children of newNode.
            isProcessChildren = false;
            break;
        case PARTITION_TYPE_CHANGE:
        case EXCLUDED_UNIT_CHANGE:
            ops.add(createRemoveOperation(originalNode));
            ops.addAll(createAddOperations(newNode));
            // No need to further process children. The ADD operations above will include operations
            // for all children of newNode.
            isProcessChildren = false;
            break;
        case BIDDABLE_UNIT_CHANGE:
            // Ensure that the new node has the proper ID (this may have been lost if the node
            // was removed and then re-added).
            newNode = newNode.setProductPartitionId(originalNode.getProductPartitionId());
            ops.add(createSetBidOperation(newNode));
            // Process the children of newNode. The SET operation above will only handle changes
            // made to newNode, not its children.
            isProcessChildren = true;
            break;
        case NONE:
            // Ensure that the new node has the proper ID (this may have been lost if the node
            // was removed and then re-added).
            newNode = newNode.setProductPartitionId(originalNode.getProductPartitionId());
            // This node does not have changes, but its children may.
            isProcessChildren = true;
            break;
        default:
            throw new IllegalStateException("Unrecognized difference: " + nodeDifference);
    }
    if (isProcessChildren) {
        for (ProductPartitionNode childNode : Iterables.concat(originalNode.getChildren(), newNode.getChildren())) {
            childDimensionsToProcess.add(childNode.getDimension());
        }
    }
    return childDimensionsToProcess;
}
Also used : NodeDifference(com.google.api.ads.adwords.axis.utils.v201809.shopping.ProductPartitionNodeDiffer.NodeDifference) ProductDimension(com.google.api.ads.adwords.axis.v201809.cm.ProductDimension)

Example 3 with Dimensions

use of com.google.api.ads.adwords.axis.v201809.cm.Dimensions in project googleads-java-lib by googleads.

the class ProductPartitionTreeImpl method addMutateOperationsByParent.

/**
 * Adds to the operations list all operations required to mutate the children of
 * {@code originalParentNode} to {@code newParentNode}.
 *
 * @param originalParentNode required - must not be null
 * @param newParentNode required - must not be null
 * @param childDimensionsToProcess the child dimensions to process
 * @param ops the operations list to add to
 */
private void addMutateOperationsByParent(ProductPartitionNode originalParentNode, ProductPartitionNode newParentNode, Set<ProductDimension> childDimensionsToProcess, List<OperationPair> ops) {
    for (ProductDimension dimensionToProcess : childDimensionsToProcess) {
        ProductPartitionNode originalChild = originalParentNode.hasChild(dimensionToProcess) ? originalParentNode.getChild(dimensionToProcess) : null;
        ProductPartitionNode newChild = newParentNode.hasChild(dimensionToProcess) ? newParentNode.getChild(dimensionToProcess) : null;
        Set<ProductDimension> grandchildDimensionsToProcess = addMutateOperations(originalChild, newChild, ops);
        if (!grandchildDimensionsToProcess.isEmpty()) {
            // Logic check - the only condition where further processing of children is required
            // is when the parent exists in both trees. If the parent is null in one tree but
            // not the other, then the node for dimensionToProcess was either:
            // 1) removed from the original OR
            // 2) added to the new tree
            // In both cases, the call to addMutateOperations above will have already added all of the
            // necessary operations to handle the node and all of its children.
            Preconditions.checkState(originalChild != null, "Original child should not be null if there are children to process");
            Preconditions.checkState(newChild != null, "New child should not be null if there are children to process");
            addMutateOperationsByParent(originalChild, newChild, grandchildDimensionsToProcess, ops);
        }
    }
}
Also used : ProductDimension(com.google.api.ads.adwords.axis.v201809.cm.ProductDimension)

Example 4 with Dimensions

use of com.google.api.ads.adwords.axis.v201809.cm.Dimensions in project googleads-java-lib by googleads.

the class BaseProductDimensionComparatorTest method testCompareToDifferentDimensionType.

@Test
public void testCompareToDifferentDimensionType() {
    ProductDimension dimension = createOtherProductDimension();
    ProductDimension otherTypeOfDimension = dimension instanceof ProductBrand ? ProductDimensions.createOfferId("abc") : ProductDimensions.createBrand("google");
    assertThat("Comparing dimensions of different types should return a non-zero result", comparator.compare(dimension, otherTypeOfDimension), Matchers.not(0));
    assertThat("Comparing dimensions of different types should return a non-zero result", comparator.compare(otherTypeOfDimension, dimension), Matchers.not(0));
}
Also used : ProductBrand(com.google.api.ads.adwords.axis.v201809.cm.ProductBrand) ProductDimension(com.google.api.ads.adwords.axis.v201809.cm.ProductDimension) Test(org.junit.Test)

Example 5 with Dimensions

use of com.google.api.ads.adwords.axis.v201809.cm.Dimensions in project googleads-java-lib by googleads.

the class UploadImage method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices 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.
 * @throws IOException if unable to get media data from the URL.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws IOException {
    // Get the MediaService.
    MediaServiceInterface mediaService = adWordsServices.get(session, MediaServiceInterface.class);
    // Create image.
    Image image = new Image();
    image.setData(com.google.api.ads.common.lib.utils.Media.getMediaDataFromUrl("https://goo.gl/3b9Wfh"));
    image.setType(MediaMediaType.IMAGE);
    Media[] media = new Media[] { image };
    // Upload image.
    Media[] result = mediaService.upload(media);
    // Display images.
    image = (Image) result[0];
    Map<MediaSize, Dimensions> dimensions = Maps.toMap(image.getDimensions());
    System.out.printf("Image with ID %d, dimensions %dx%d, and MIME type '%s' was " + "uploaded.%n", image.getMediaId(), dimensions.get(MediaSize.FULL).getWidth(), dimensions.get(MediaSize.FULL).getHeight(), image.getMediaType());
}
Also used : MediaSize(com.google.api.ads.adwords.axis.v201809.cm.MediaSize) MediaServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.MediaServiceInterface) Media(com.google.api.ads.adwords.axis.v201809.cm.Media) Dimensions(com.google.api.ads.adwords.axis.v201809.cm.Dimensions) Image(com.google.api.ads.adwords.axis.v201809.cm.Image)

Aggregations

Dimensions (com.google.api.ads.adwords.axis.v201809.cm.Dimensions)4 Media (com.google.api.ads.adwords.axis.v201809.cm.Media)3 MediaServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.MediaServiceInterface)3 MediaSize (com.google.api.ads.adwords.axis.v201809.cm.MediaSize)3 ProductDimension (com.google.api.ads.adwords.axis.v201809.cm.ProductDimension)3 MediaBundle (com.google.api.ads.adwords.axis.v201809.cm.MediaBundle)2 ProductBrand (com.google.api.ads.adwords.axis.v201809.cm.ProductBrand)2 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)1 NodeDifference (com.google.api.ads.adwords.axis.utils.v201809.shopping.ProductPartitionNodeDiffer.NodeDifference)1 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)1 AdGroupAdOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation)1 AdGroupAdReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdReturnValue)1 AdGroupAdServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface)1 CampaignCriterion (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion)1 CampaignCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation)1 CampaignCriterionReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionReturnValue)1 CampaignCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface)1 Image (com.google.api.ads.adwords.axis.v201809.cm.Image)1 MediaPage (com.google.api.ads.adwords.axis.v201809.cm.MediaPage)1 ProductBiddingCategory (com.google.api.ads.adwords.axis.v201809.cm.ProductBiddingCategory)1