use of com.google.api.ads.adwords.jaxws.v201809.cm.CampaignOperation in project googleads-java-lib by googleads.
the class UpdateCampaign method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param campaignId the ID of the campaign 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(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long campaignId) throws RemoteException {
// Get the CampaignService.
CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
// Create campaign with updated status.
Campaign campaign = new Campaign();
campaign.setId(campaignId);
campaign.setStatus(CampaignStatus.PAUSED);
// Create operations.
CampaignOperation operation = new CampaignOperation();
operation.setOperand(campaign);
operation.setOperator(Operator.SET);
CampaignOperation[] operations = new CampaignOperation[] { operation };
// Update campaign.
CampaignReturnValue result = campaignService.mutate(operations);
// Display campaigns.
for (Campaign campaignResult : result.getValue()) {
System.out.printf("Campaign with name '%s', ID %d, and budget delivery method '%s' " + "was updated.%n", campaignResult.getName(), campaignResult.getId(), campaignResult.getBudget().getDeliveryMethod());
}
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.CampaignOperation in project googleads-java-lib by googleads.
the class AxisSerializerTest method testSerialize.
@Test
public void testSerialize() throws SAXException, IOException {
BatchJobMutateRequest mutate = new BatchJobMutateRequest();
List<Operation> ops = Lists.newArrayList();
Campaign campaign = new Campaign();
campaign.setId(-1L);
campaign.setName("Test campaign");
campaign.setAdvertisingChannelType(AdvertisingChannelType.SEARCH);
ops.add(new CampaignOperation(Operator.ADD, "ADD", campaign));
AdGroup adGroup = new AdGroup();
adGroup.setName("Test ad group");
adGroup.setCampaignId(campaign.getId());
ops.add(new AdGroupOperation(Operator.ADD, "ADD", adGroup));
mutate.setOperations(ops.toArray(new Operation[0]));
AxisSerializer serializer = new AxisSerializer();
StringWriter writer = new StringWriter();
SerializationContext context = new SerializationContext(writer);
context.setSendDecl(true);
context.setPretty(true);
serializer.serialize(mutate, context);
String serializedRequest = writer.toString();
assertNotNull("Serialized request is null", serializedRequest);
String expectedSerializedRequest = CharStreams.toString(new InputStreamReader(AxisSerializerTest.class.getResourceAsStream("resources/BatchJobMutate.request.xml"), UTF_8));
Diff diff = DiffBuilder.compare(expectedSerializedRequest).withTest(serializedRequest).checkForSimilar().build();
assertFalse("Serialized request does not match expected XML", diff.hasDifferences());
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.CampaignOperation in project googleads-java-lib by googleads.
the class AxisBatchJobUploadBodyProviderTest method addCampaignOperation.
@Override
protected void addCampaignOperation(BatchJobMutateRequest request, long campaignId, String campaignName, String status, String advertisingChannelType, long budgetId, String biddingStrategyType, boolean enhancedCpcEnabled) {
Campaign campaign = new Campaign();
campaign.setId(campaignId);
campaign.setName(campaignName);
campaign.setStatus(CampaignStatus.fromString(status));
campaign.setAdvertisingChannelType(AdvertisingChannelType.fromString(advertisingChannelType));
Budget budget = new Budget();
budget.setBudgetId(budgetId);
campaign.setBudget(budget);
BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
biddingStrategyConfiguration.setBiddingStrategyType(BiddingStrategyType.fromString(biddingStrategyType));
ManualCpcBiddingScheme cpcBiddingScheme = new ManualCpcBiddingScheme();
cpcBiddingScheme.setEnhancedCpcEnabled(enhancedCpcEnabled);
biddingStrategyConfiguration.setBiddingScheme(cpcBiddingScheme);
campaign.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
CampaignOperation operation = new CampaignOperation();
operation.setOperand(campaign);
operation.setOperator(Operator.ADD);
request.addOperation(operation);
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.CampaignOperation in project googleads-java-lib by googleads.
the class JaxWsSerializationTest method testSerializeBatchJobMutateRequest.
@SuppressWarnings("cast")
@Test
public void testSerializeBatchJobMutateRequest() throws IOException, SAXException {
BatchJobMutateRequest request = new BatchJobMutateRequest();
CampaignOperation campaignOp = new CampaignOperation();
campaignOp.setOperator(Operator.ADD);
Campaign campaign = new Campaign();
campaign.setId(-1L);
campaign.setName("Test campaign");
campaign.setAdvertisingChannelType(AdvertisingChannelType.SEARCH);
campaignOp.setOperand(campaign);
request.addOperation(campaignOp);
AdGroupOperation adGroupOp = new AdGroupOperation();
adGroupOp.setOperator(Operator.ADD);
AdGroup adGroup = new AdGroup();
adGroup.setName("Test ad group");
adGroup.setCampaignId(campaign.getId());
adGroupOp.setOperand(adGroup);
request.addOperation(adGroupOp);
JaxBSerializer<BatchJobMutateRequest> serializer = new JaxBSerializer<>(BatchJobMutateRequest.class, new QName("https://adwords.google.com/api/adwords/cm/v201809", "mutate"));
String serializedRequest = serializer.serialize(request);
assertNotNull("Null serialized request returned", serializedRequest);
String expectedSerializedRequest = CharStreams.toString(new InputStreamReader(JaxWsSerializationTest.class.getResourceAsStream("resources/BatchJobMutate.request.xml"), UTF_8));
// Perform XML diffs using the custom difference listener that properly handles namespaces
// and attributes.
Diff diff = DiffBuilder.compare(expectedSerializedRequest).withDifferenceEvaluator(DifferenceEvaluators.chain(DifferenceEvaluators.Default, new CustomDifferenceEvaluator())).withTest(serializedRequest).checkForSimilar().build();
assertFalse("Serialized request does not match expected value", diff.hasDifferences());
// Serialize again, this time without the XML declaration, and confirm the serialized XML
// matches the expected string.
serializedRequest = serializer.serialize(request, false);
expectedSerializedRequest = expectedSerializedRequest.replaceFirst("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>", "");
diff = DiffBuilder.compare(expectedSerializedRequest).normalizeWhitespace().withDifferenceEvaluator(new CustomDifferenceEvaluator()).withTest(serializedRequest).checkForSimilar().build();
assertFalse("Serialized request with XML declaration excluded does not match expected value", diff.hasDifferences());
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.CampaignOperation in project googleads-java-lib by googleads.
the class BatchJobHelperTest method getPauseCampaignOperation.
@Override
protected Operation getPauseCampaignOperation(Long campaignId) {
CampaignOperation op = new CampaignOperation();
Campaign campaign = new Campaign();
campaign.setId(campaignId);
campaign.setStatus(CampaignStatus.PAUSED);
op.setOperand(campaign);
op.setOperator(Operator.SET);
return op;
}
Aggregations