Search in sources :

Example 1 with Operator

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

the class AddAdGroupBidModifier method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group where bid modifiers will be added.
 * @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, Long adGroupId) throws RemoteException {
    // Get the AdGroupBidModifierService.
    AdGroupBidModifierServiceInterface adGroupBidModifierService = adWordsServices.get(session, AdGroupBidModifierServiceInterface.class);
    // Create mobile platform. The ID can be found in the documentation.
    // https://developers.google.com/adwords/api/docs/appendix/platforms
    Platform mobile = new Platform();
    mobile.setId(30001L);
    AdGroupBidModifier adGroupBidModifier = new AdGroupBidModifier();
    adGroupBidModifier.setAdGroupId(adGroupId);
    adGroupBidModifier.setBidModifier(BID_MODIFIER);
    adGroupBidModifier.setCriterion(mobile);
    // Create ADD operation.
    AdGroupBidModifierOperation operation = new AdGroupBidModifierOperation();
    operation.setOperand(adGroupBidModifier);
    // Use 'ADD' to add a new modifier and 'SET' to update an existing one. A
    // modifier can be removed with the 'REMOVE' operator.
    operation.setOperator(Operator.ADD);
    // Update ad group bid modifier.
    AdGroupBidModifierReturnValue result = adGroupBidModifierService.mutate(new AdGroupBidModifierOperation[] { operation });
    for (AdGroupBidModifier bidModifierResult : result.getValue()) {
        System.out.printf("Campaign ID %d, ad group ID %d was updated with ad group level modifier: %.4f%n", bidModifierResult.getCampaignId(), bidModifierResult.getAdGroupId(), bidModifierResult.getBidModifier());
    }
}
Also used : AdGroupBidModifierReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierReturnValue) Platform(com.google.api.ads.adwords.axis.v201809.cm.Platform) AdGroupBidModifier(com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifier) AdGroupBidModifierServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierServiceInterface) AdGroupBidModifierOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierOperation)

Example 2 with Operator

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

the class SelectorBuilderImpl method multipleValuePredicate.

/**
 * Adds a predicate for the specified field, property values, and operator.
 */
private SelectorBuilderImpl multipleValuePredicate(String field, String[] propertyValues, PredicateOperator operator) {
    if (propertyValues == null) {
        return this;
    }
    Predicate predicate = new Predicate();
    predicate.setOperator(operator);
    predicate.setField(field);
    String[] values = Arrays.copyOf(propertyValues, propertyValues.length);
    predicate.setValues(values);
    this.predicates.add(predicate);
    return this;
}
Also used : Predicate(com.google.api.ads.adwords.axis.v201809.cm.Predicate)

Example 3 with Operator

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

the class SelectorBuilderImpl method singleValuePredicate.

/**
 * Adds a predicate for the specified field, property value, and operator.
 */
private SelectorBuilderImpl singleValuePredicate(String field, String propertyValue, PredicateOperator operator) {
    Predicate predicate = new Predicate();
    predicate.setField(field);
    predicate.setOperator(operator);
    String[] values = new String[1];
    values[0] = propertyValue;
    predicate.setValues(values);
    this.predicates.add(predicate);
    return this;
}
Also used : Predicate(com.google.api.ads.adwords.axis.v201809.cm.Predicate)

Example 4 with Operator

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

the class ProductPartitionTreeTest method testCreateMultiNodeTreeFromScratch.

/**
 * Tests creating an empty tree and then adding several levels of nodes.
 */
@Test
public void testCreateMultiNodeTreeFromScratch() {
    ProductPartitionTree tree = ProductPartitionTree.createAdGroupTree(-1L, biddingStrategyConfig, Collections.<AdGroupCriterion>emptyList());
    ProductPartitionNode rootNode = tree.getRoot().asSubdivision();
    ProductPartitionNode brand1 = rootNode.addChild(ProductDimensions.createBrand("google")).asSubdivision();
    ProductPartitionNode brand1Offer1 = brand1.addChild(ProductDimensions.createOfferId("A")).asBiddableUnit().setBid(1000000L).putCustomParameter("param1", "value1").putCustomParameter("param2", "value2");
    ProductPartitionNode brand1Offer2 = brand1.addChild(ProductDimensions.createOfferId(null)).asExcludedUnit();
    ProductPartitionNode brand2 = rootNode.addChild(ProductDimensions.createBrand(null)).asExcludedUnit();
    int expectedOpCount = 5;
    List<AdGroupCriterionOperation> mutateOperations = tree.getMutateOperations();
    assertEquals("Number of operations is incorrect", expectedOpCount, mutateOperations.size());
    List<CriterionDescriptor> nodeDescriptors = Stream.of(rootNode, brand1, brand1Offer1, brand1Offer2, brand2).map(CriterionDescriptor::new).collect(Collectors.toList());
    int opNum = 0;
    List<CriterionDescriptor> opDescriptors = Lists.newArrayList();
    Map<Long, CriterionDescriptor> opDescriptorsById = Maps.newHashMap();
    for (AdGroupCriterionOperation op : mutateOperations) {
        CriterionDescriptor opDescriptor = new CriterionDescriptor(op.getOperand(), opNum++);
        opDescriptors.add(opDescriptor);
        opDescriptorsById.put(opDescriptor.partitionId, opDescriptor);
    }
    Map<Long, Map<Long, CriterionDescriptor>> opDescriptorMap = buildDescriptorMap(opDescriptors);
    for (CriterionDescriptor nodeDescriptor : nodeDescriptors) {
        CriterionDescriptor opDescriptor = opDescriptorMap.get(nodeDescriptor.parentPartitionId).get(nodeDescriptor.partitionId);
        nodeDescriptor.assertDescriptorEquals(opDescriptor);
        AdGroupCriterionOperation op = mutateOperations.get(opDescriptor.operationNumber);
        assertEquals("operator is incorrect", Operator.ADD, op.getOperator());
        if (nodeDescriptor.parentPartitionId != null) {
            CriterionDescriptor parentOpDescriptor = opDescriptorsById.get(nodeDescriptor.parentPartitionId);
            assertNotNull("no operation found for parent", parentOpDescriptor);
            assertThat("operation # for parent is > operation # for child", opDescriptor.operationNumber, Matchers.greaterThan(parentOpDescriptor.operationNumber));
        }
    }
    assertThat("Tree toString does not contain the root's detailed toString", tree.toString(), Matchers.containsString(tree.getRoot().toDetailedString()));
    assertThat("Tree toString does not contain the ad group ID", tree.toString(), Matchers.containsString(tree.getAdGroupId().toString()));
}
Also used : AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) Map(java.util.Map) HashMap(java.util.HashMap) MockHttpIntegrationTest(com.google.api.ads.common.lib.testing.MockHttpIntegrationTest) Test(org.junit.Test)

Aggregations

Predicate (com.google.api.ads.adwords.axis.v201809.cm.Predicate)2 AdGroupBidModifier (com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifier)1 AdGroupBidModifierOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierOperation)1 AdGroupBidModifierReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierReturnValue)1 AdGroupBidModifierServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierServiceInterface)1 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)1 Platform (com.google.api.ads.adwords.axis.v201809.cm.Platform)1 MockHttpIntegrationTest (com.google.api.ads.common.lib.testing.MockHttpIntegrationTest)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1