use of com.google.api.ads.adwords.axis.v201809.cm.Operation in project googleads-java-lib by googleads.
the class AdWordsAxisSoapCompressionIntegrationTest method testGoldenSoap_oauth2_compressionEnabled.
/**
* Tests making an Axis AdWords API call with OAuth2 and compression enabled.
*/
@Test
public void testGoldenSoap_oauth2_compressionEnabled() throws Exception {
testHttpServer.setMockResponseBody(SoapResponseXmlProvider.getTestSoapResponse(API_VERSION));
GoogleCredential credential = new GoogleCredential.Builder().setTransport(new NetHttpTransport()).setJsonFactory(new JacksonFactory()).build();
credential.setAccessToken("TEST_ACCESS_TOKEN");
AdWordsSession session = new AdWordsSession.Builder().withUserAgent("TEST_APP").withOAuth2Credential(credential).withEndpoint(testHttpServer.getServerUrl()).withDeveloperToken("TEST_DEVELOPER_TOKEN").withClientCustomerId("TEST_CLIENT_CUSTOMER_ID").build();
BudgetServiceInterface companyService = new AdWordsServices().get(session, BudgetServiceInterface.class);
Budget budget = new Budget();
budget.setName("Test Budget Name");
Money money = new Money();
money.setMicroAmount(50000000L);
budget.setAmount(money);
budget.setDeliveryMethod(BudgetBudgetDeliveryMethod.STANDARD);
BudgetOperation operation = new BudgetOperation();
operation.setOperand(budget);
operation.setOperator(Operator.ADD);
Budget responseBudget = companyService.mutate(new BudgetOperation[] { operation }).getValue(0);
assertEquals("Budget ID does not match", 251877074L, responseBudget.getBudgetId().longValue());
assertEquals("Budget name does not match", budget.getName(), responseBudget.getName());
assertEquals("Budget amount does not match", budget.getAmount().getMicroAmount(), responseBudget.getAmount().getMicroAmount());
assertEquals("Budget delivery method does not match", budget.getDeliveryMethod(), responseBudget.getDeliveryMethod());
assertTrue("Compression was enabled but the last request body was not compressed", testHttpServer.wasLastRequestBodyCompressed());
Diff diff = DiffBuilder.compare(SoapRequestXmlProvider.getOAuth2SoapRequest(API_VERSION)).withTest(testHttpServer.getLastRequestBody()).checkForSimilar().build();
assertFalse(diff.hasDifferences());
assertEquals("Bearer TEST_ACCESS_TOKEN", testHttpServer.getLastAuthorizationHttpHeader());
}
use of com.google.api.ads.adwords.axis.v201809.cm.Operation in project googleads-java-lib by googleads.
the class AdWordsAxisSoapIntegrationTest method testBudgetServiceMutateRequest.
/**
* Submits a BudgetService.mutate call to the test server and asserts that the response contains
* expected values.
*/
private void testBudgetServiceMutateRequest(AdWordsSession session) throws RemoteException, ApiException, IOException, SAXException {
BudgetServiceInterface companyService = new AdWordsServices().get(session, BudgetServiceInterface.class);
Budget budget = new Budget();
budget.setName("Test Budget Name");
Money money = new Money();
money.setMicroAmount(50000000L);
budget.setAmount(money);
budget.setDeliveryMethod(BudgetBudgetDeliveryMethod.STANDARD);
BudgetOperation operation = new BudgetOperation();
operation.setOperand(budget);
operation.setOperator(Operator.ADD);
Budget responseBudget = companyService.mutate(new BudgetOperation[] { operation }).getValue(0);
assertEquals("Budget ID does not match", 251877074L, responseBudget.getBudgetId().longValue());
assertEquals("Budget name does not match", budget.getName(), responseBudget.getName());
assertEquals("Budget amount does not match", budget.getAmount().getMicroAmount(), responseBudget.getAmount().getMicroAmount());
assertEquals("Budget delivery method does not match", budget.getDeliveryMethod(), responseBudget.getDeliveryMethod());
assertFalse("Did not request compression but request was compressed", testHttpServer.wasLastRequestBodyCompressed());
Diff diff = DiffBuilder.compare(SoapRequestXmlProvider.getOAuth2SoapRequest(API_VERSION)).withTest(testHttpServer.getLastRequestBody()).checkForSimilar().build();
assertFalse(diff.hasDifferences());
}
use of com.google.api.ads.adwords.axis.v201809.cm.Operation in project googleads-java-lib by googleads.
the class AcceptServiceLink method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param serviceLinkId the ID of the service link to accept.
* @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 serviceLinkId) throws RemoteException {
// Get the CustomerService.
CustomerServiceInterface customerService = adWordsServices.get(session, CustomerServiceInterface.class);
// Create the operation to set the status to ACTIVE.
ServiceLinkOperation op = new ServiceLinkOperation();
op.setOperator(Operator.SET);
ServiceLink serviceLink = new ServiceLink();
serviceLink.setServiceLinkId(serviceLinkId);
serviceLink.setServiceType(ServiceType.MERCHANT_CENTER);
serviceLink.setLinkStatus(ServiceLinkLinkStatus.ACTIVE);
op.setOperand(serviceLink);
// Update the service link.
ServiceLink[] mutatedServiceLinks = customerService.mutateServiceLinks(new ServiceLinkOperation[] { op });
// Display the results.
for (ServiceLink mutatedServiceLink : mutatedServiceLinks) {
System.out.printf("Service link with service link ID %d, type '%s' updated to status: %s.%n", mutatedServiceLink.getServiceLinkId(), mutatedServiceLink.getServiceType(), mutatedServiceLink.getLinkStatus());
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.Operation in project googleads-java-lib by googleads.
the class CreateAccount 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 CampaignService.
ManagedCustomerServiceInterface managedCustomerService = adWordsServices.get(session, ManagedCustomerServiceInterface.class);
// Create account.
ManagedCustomer customer = new ManagedCustomer();
customer.setName("Customer created with ManagedCustomerService on " + DateTime.now());
customer.setCurrencyCode("EUR");
customer.setDateTimeZone("Europe/London");
// Create operations.
ManagedCustomerOperation operation = new ManagedCustomerOperation();
operation.setOperand(customer);
operation.setOperator(Operator.ADD);
ManagedCustomerOperation[] operations = new ManagedCustomerOperation[] { operation };
// Add account.
ManagedCustomerReturnValue result = managedCustomerService.mutate(operations);
// Display accounts.
for (ManagedCustomer customerResult : result.getValue()) {
System.out.printf("Account with customer ID %d was created.%n", customerResult.getCustomerId());
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.Operation in project googleads-java-lib by googleads.
the class AddAdCustomizer method restrictFeedItemToAdGroup.
/**
* Restricts the feed item to an ad group.
*/
private static void restrictFeedItemToAdGroup(AdWordsServicesInterface adWordsServices, AdWordsSession session, FeedItem feedItem, long adGroupId) throws RemoteException {
// Get the FeedItemTargetingService.
FeedItemTargetServiceInterface feedItemTargetService = adWordsServices.get(session, FeedItemTargetServiceInterface.class);
FeedItemAdGroupTarget adGroupTarget = new FeedItemAdGroupTarget();
adGroupTarget.setFeedId(feedItem.getFeedId());
adGroupTarget.setFeedItemId(feedItem.getFeedItemId());
adGroupTarget.setAdGroupId(adGroupId);
FeedItemTargetOperation operation = new FeedItemTargetOperation();
operation.setOperator(Operator.ADD);
operation.setOperand(adGroupTarget);
FeedItemTargetReturnValue returnValue = feedItemTargetService.mutate(new FeedItemTargetOperation[] { operation });
FeedItemAdGroupTarget addedAdGroupTarget = (FeedItemAdGroupTarget) returnValue.getValue(0);
System.out.printf("Feed item target for feed ID %d and feed item ID %d " + "was created to restrict serving to ad group ID %d.%n", addedAdGroupTarget.getFeedId(), addedAdGroupTarget.getFeedItemId(), addedAdGroupTarget.getAdGroupId());
}
Aggregations