Search in sources :

Example 11 with AdGroup

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

the class ProductPartitionTreeImpl method getAdGroupBiddingStrategyConfiguration.

/**
 * Retrieves the {@link BiddingStrategyConfiguration} of an ad group.
 *
 * @param services the AdWordsServices
 * @param session the session to use for the request
 * @param adGroupId the ad group ID
 * @return the non-null BiddingStrategyConfiguration of the ad group
 */
private static BiddingStrategyConfiguration getAdGroupBiddingStrategyConfiguration(AdWordsServicesInterface services, AdWordsSession session, Long adGroupId) throws ApiException, RemoteException {
    AdGroupServiceInterface adGroupService = services.get(session, AdGroupServiceInterface.class);
    Selector selector = new SelectorBuilder().fields(AdGroupField.Id, AdGroupField.BiddingStrategyType, AdGroupField.BiddingStrategyId, AdGroupField.BiddingStrategyName).equalsId(adGroupId).build();
    AdGroupPage adGroupPage = adGroupService.get(selector);
    if (adGroupPage.getEntries() == null || adGroupPage.getEntries().length == 0) {
        throw new IllegalArgumentException("No ad group found with ID " + adGroupId);
    }
    AdGroup adGroup = adGroupPage.getEntries(0);
    Preconditions.checkState(adGroup.getBiddingStrategyConfiguration() != null, "Unexpected state - ad group ID %s has a null BiddingStrategyConfiguration", adGroupId);
    return adGroup.getBiddingStrategyConfiguration();
}
Also used : AdGroupServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface) SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) AdGroupPage(com.google.api.ads.adwords.axis.v201809.cm.AdGroupPage) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Example 12 with AdGroup

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

the class AddDynamicSearchAdsCampaign 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 {
    Budget budget = createBudget(adWordsServices, session);
    Campaign campaign = createCampaign(adWordsServices, session, budget);
    AdGroup adGroup = createAdGroup(adWordsServices, session, campaign);
    createExpandedDSA(adWordsServices, session, adGroup);
    addWebPageCriteria(adWordsServices, session, adGroup);
}
Also used : Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) Budget(com.google.api.ads.adwords.axis.v201809.cm.Budget) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup)

Example 13 with AdGroup

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

the class JaxWsBatchJobResponseDeserializerTest method testDeserializeBatchJobMutateResponseWithErrors.

@Test
public void testDeserializeBatchJobMutateResponseWithErrors() throws Exception {
    BatchJobMutateResponse response = deserializer.deserializeBatchJobMutateResults(BatchJobMutateResponse.class, JaxWsBatchJobResponseDeserializerTest.class.getResource("resources/BatchJobMutate.responseWithErrors.xml"));
    assertNotNull("Null deserialized request returned", response);
    // Expect: Campaign, AdGroup, BiddableAdGroupCriterion, BiddableAdGroupCriterion,
    // CriterionError, CriterionError, CriterionError
    assertEquals(7, response.getMutateResults().length);
    assertNotNull(response.getMutateResults()[0].getOperand().getCampaign());
    assertNotNull(response.getMutateResults()[1].getOperand().getAdGroup());
    assertNotNull(response.getMutateResults()[2].getOperand().getAdGroupCriterion());
    assertThat(response.getMutateResults()[2].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
    assertNotNull(response.getMutateResults()[3].getOperand().getAdGroupCriterion());
    assertThat(response.getMutateResults()[3].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
    assertThat(response.getMutateResults()[4].getErrorList().getErrors()[0], Matchers.instanceOf(CriterionError.class));
    assertThat(response.getMutateResults()[5].getErrorList().getErrors()[0], Matchers.instanceOf(CriterionError.class));
    assertThat(response.getMutateResults()[6].getErrorList().getErrors()[0], Matchers.instanceOf(CriterionError.class));
}
Also used : BatchJobMutateResponse(com.google.api.ads.adwords.jaxws.utils.v201809.batchjob.BatchJobMutateResponse) BiddableAdGroupCriterion(com.google.api.ads.adwords.jaxws.v201809.cm.BiddableAdGroupCriterion) CriterionError(com.google.api.ads.adwords.jaxws.v201809.cm.CriterionError) Test(org.junit.Test)

Example 14 with AdGroup

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

the class JaxWsDeserializationTest method testDeserializeBatchJobMutateRequest.

@Test
public void testDeserializeBatchJobMutateRequest() {
    Source source = new StreamSource(JaxWsDeserializationTest.class.getResourceAsStream("resources/BatchJobMutate.responseWithErrors.xml"));
    BatchJobMutateResponse response = deserializer.deserialize(source);
    assertNotNull("Null deserialized request returned", response);
    // Expect: Campaign, AdGroup, BiddableAdGroupCriterion, BiddableAdGroupCriterion,
    // CriterionError, CriterionError, CriterionError
    assertEquals(7, response.getMutateResults().length);
    assertNotNull(response.getMutateResults()[0].getOperand().getCampaign());
    assertNotNull(response.getMutateResults()[1].getOperand().getAdGroup());
    assertNotNull(response.getMutateResults()[2].getOperand().getAdGroupCriterion());
    assertThat(response.getMutateResults()[2].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
    assertNotNull(response.getMutateResults()[3].getOperand().getAdGroupCriterion());
    assertThat(response.getMutateResults()[3].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
    assertThat(response.getMutateResults()[4].getErrorList().getErrors()[0], Matchers.instanceOf(CriterionError.class));
    assertThat(response.getMutateResults()[5].getErrorList().getErrors()[0], Matchers.instanceOf(CriterionError.class));
    assertThat(response.getMutateResults()[6].getErrorList().getErrors()[0], Matchers.instanceOf(CriterionError.class));
}
Also used : BatchJobMutateResponse(com.google.api.ads.adwords.jaxws.utils.v201809.batchjob.BatchJobMutateResponse) BiddableAdGroupCriterion(com.google.api.ads.adwords.jaxws.v201809.cm.BiddableAdGroupCriterion) StreamSource(javax.xml.transform.stream.StreamSource) CriterionError(com.google.api.ads.adwords.jaxws.v201809.cm.CriterionError) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) Test(org.junit.Test)

Example 15 with AdGroup

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

the class JaxWsDeserializationTest method testDeserializeBatchJobResponseWithoutErrors.

/**
 * Tests that a response without errors will be properly deserialized.
 */
@Test
public void testDeserializeBatchJobResponseWithoutErrors() throws Exception {
    Source source = new StreamSource(JaxWsDeserializationTest.class.getResourceAsStream("resources/BatchJobMutate.responseWithoutErrors.xml"));
    BatchJobMutateResponse response = deserializer.deserialize(source);
    assertNotNull(response);
    // Expect: Campaign, AdGroup, BiddableAdGroupCriterion, BiddableAdGroupCriterion
    assertEquals(4, response.getMutateResults().length);
    assertNotNull(response.getMutateResults()[0].getOperand().getCampaign());
    assertNotNull(response.getMutateResults()[1].getOperand().getAdGroup());
    assertNotNull(response.getMutateResults()[2].getOperand().getAdGroupCriterion());
    assertThat(response.getMutateResults()[3].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
    assertNotNull(response.getMutateResults()[3].getOperand().getAdGroupCriterion());
    assertThat(response.getMutateResults()[3].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
}
Also used : BatchJobMutateResponse(com.google.api.ads.adwords.jaxws.utils.v201809.batchjob.BatchJobMutateResponse) BiddableAdGroupCriterion(com.google.api.ads.adwords.jaxws.v201809.cm.BiddableAdGroupCriterion) StreamSource(javax.xml.transform.stream.StreamSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) Test(org.junit.Test)

Aggregations

AdGroup (com.google.api.ads.adwords.axis.v201809.cm.AdGroup)14 AdGroupOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)9 AdGroupServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface)9 AdGroupReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupReturnValue)6 Test (org.junit.Test)6 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)5 Campaign (com.google.api.ads.adwords.axis.v201809.cm.Campaign)5 CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)4 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)4 BatchJobMutateResponse (com.google.api.ads.adwords.jaxws.utils.v201809.batchjob.BatchJobMutateResponse)4 BiddableAdGroupCriterion (com.google.api.ads.adwords.jaxws.v201809.cm.BiddableAdGroupCriterion)4 Budget (com.google.api.ads.adwords.axis.v201809.cm.Budget)3 CampaignOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation)3 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)2 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)2 AdGroupPage (com.google.api.ads.adwords.axis.v201809.cm.AdGroupPage)2 Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)2 CriterionError (com.google.api.ads.adwords.jaxws.v201809.cm.CriterionError)2 InputStreamReader (java.io.InputStreamReader)2 Source (javax.xml.transform.Source)2