Search in sources :

Example 11 with Money

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

the class UploadOfflineData method createOfflineData.

/**
 * Returns a new offline data object with the specified values.
 */
private static OfflineData createOfflineData(DateTime transactionTime, long transactionMicroAmount, String transactionCurrency, String conversionName, List<UserIdentifier> userIdentifiers) {
    StoreSalesTransaction storeSalesTransaction = new StoreSalesTransaction();
    // For times use the format yyyyMMdd HHmmss [tz].
    // For details, see
    // https://developers.google.com/adwords/api/docs/appendix/codes-formats#date-and-time-formats
    storeSalesTransaction.setTransactionTime(transactionTime.toString("yyyyMMdd HHmmss ZZZ"));
    storeSalesTransaction.setConversionName(conversionName);
    storeSalesTransaction.setUserIdentifiers(userIdentifiers.toArray(new UserIdentifier[userIdentifiers.size()]));
    Money money = new Money();
    money.setMicroAmount(transactionMicroAmount);
    MoneyWithCurrency moneyWithCurrency = new MoneyWithCurrency();
    moneyWithCurrency.setMoney(money);
    moneyWithCurrency.setCurrencyCode(transactionCurrency);
    storeSalesTransaction.setTransactionAmount(moneyWithCurrency);
    OfflineData offlineData = new OfflineData();
    offlineData.setStoreSalesTransaction(storeSalesTransaction);
    return offlineData;
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) OfflineData(com.google.api.ads.adwords.axis.v201809.rm.OfflineData) StoreSalesTransaction(com.google.api.ads.adwords.axis.v201809.rm.StoreSalesTransaction) MoneyWithCurrency(com.google.api.ads.adwords.axis.v201809.rm.MoneyWithCurrency) UserIdentifier(com.google.api.ads.adwords.axis.v201809.rm.UserIdentifier)

Example 12 with Money

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

the class AddSmartShoppingAd method createBudget.

/**
 * Creates a non-shared budget for a Smart Shopping campaign. Smart Shopping campaigns support
 * only non-shared budgets.
 */
private static Budget createBudget(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException {
    BudgetServiceInterface budgetService = adWordsServices.get(session, BudgetServiceInterface.class);
    // Create a budget.
    Budget budget = new Budget();
    budget.setName("Interplanetary Cruise #" + System.currentTimeMillis());
    Money budgetAmount = new Money();
    // This budget equals 50.00 units of your account's currency, e.g.,
    // 50 USD if your currency is USD.
    budgetAmount.setMicroAmount(50_000_000L);
    budget.setAmount(budgetAmount);
    budget.setDeliveryMethod(BudgetBudgetDeliveryMethod.STANDARD);
    // Non-shared budgets are required for Smart Shopping campaigns.
    budget.setIsExplicitlyShared(false);
    // Create operation.
    BudgetOperation budgetOperation = new BudgetOperation();
    budgetOperation.setOperand(budget);
    budgetOperation.setOperator(Operator.ADD);
    // Add the budget.
    Budget newBudget = budgetService.mutate(new BudgetOperation[] { budgetOperation }).getValue(0);
    System.out.printf("Budget with name '%s' and ID %d was added.%n", newBudget.getName(), newBudget.getBudgetId());
    return newBudget;
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) BudgetOperation(com.google.api.ads.adwords.axis.v201809.cm.BudgetOperation) BudgetServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.BudgetServiceInterface) Budget(com.google.api.ads.adwords.axis.v201809.cm.Budget)

Example 13 with Money

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

the class JaxWsBatchJobUploadBodyProviderTest method addBudgetOperation.

@Override
protected void addBudgetOperation(BatchJobMutateRequest request, long budgetId, String budgetName, long budgetAmountInMicros, String deliveryMethod) {
    Budget budget = new Budget();
    budget.setBudgetId(budgetId);
    budget.setName(budgetName);
    Money budgetAmount = new Money();
    budgetAmount.setMicroAmount(budgetAmountInMicros);
    budget.setAmount(budgetAmount);
    budget.setDeliveryMethod(BudgetBudgetDeliveryMethod.valueOf(deliveryMethod));
    BudgetOperation budgetOperation = new BudgetOperation();
    budgetOperation.setOperand(budget);
    budgetOperation.setOperator(Operator.ADD);
    request.addOperation(budgetOperation);
}
Also used : Money(com.google.api.ads.adwords.jaxws.v201809.cm.Money) BudgetOperation(com.google.api.ads.adwords.jaxws.v201809.cm.BudgetOperation) Budget(com.google.api.ads.adwords.jaxws.v201809.cm.Budget)

Example 14 with Money

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

the class AdWordsJaxWsSoapCompressionIntegrationTest method testGoldenSoap_oauth2.

/**
 * Tests making a JAX-WS AdWords API call with OAuth2 and compression enabled.
 */
@Test
public void testGoldenSoap_oauth2() 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 budgetService = 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 = budgetService.mutate(Lists.newArrayList(operation)).getValue().get(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());
}
Also used : Money(com.google.api.ads.adwords.jaxws.v201809.cm.Money) Diff(org.xmlunit.diff.Diff) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) AdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession) DiffBuilder(org.xmlunit.builder.DiffBuilder) BudgetOperation(com.google.api.ads.adwords.jaxws.v201809.cm.BudgetOperation) BudgetServiceInterface(com.google.api.ads.adwords.jaxws.v201809.cm.BudgetServiceInterface) Budget(com.google.api.ads.adwords.jaxws.v201809.cm.Budget) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) AdWordsServices(com.google.api.ads.adwords.jaxws.factory.AdWordsServices) Test(org.junit.Test) MockHttpIntegrationTest(com.google.api.ads.common.lib.testing.MockHttpIntegrationTest)

Example 15 with Money

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

the class AddDynamicPageFeed method addDsaTargeting.

/**
 * Sets custom targeting for the page feed URLs based on a list of labels.
 *
 * @param adWordsServices
 * @param session
 * @param adGroupId
 * @param dsaPageUrlLabel
 */
private static void addDsaTargeting(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long adGroupId, String dsaPageUrlLabel) throws ApiException, RemoteException {
    // Get the AdGroupCriterionService.
    AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
    // Create a webpage criterion.
    Webpage webpage = new Webpage();
    WebpageParameter parameter = new WebpageParameter();
    parameter.setCriterionName("Test criterion");
    webpage.setParameter(parameter);
    // Add a condition for label=specified_label_name.
    WebpageCondition condition = new WebpageCondition();
    condition.setOperand(WebpageConditionOperand.CUSTOM_LABEL);
    condition.setArgument(dsaPageUrlLabel);
    parameter.setConditions(new WebpageCondition[] { condition });
    BiddableAdGroupCriterion criterion = new BiddableAdGroupCriterion();
    criterion.setAdGroupId(adGroupId);
    criterion.setCriterion(webpage);
    // Set a custom bid for this criterion.
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    CpcBid cpcBid = new CpcBid();
    Money money = new Money();
    money.setMicroAmount(1_500_000L);
    cpcBid.setBid(money);
    biddingStrategyConfiguration.setBids(new Bids[] { cpcBid });
    criterion.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    AdGroupCriterionOperation operation = new AdGroupCriterionOperation();
    operation.setOperand(criterion);
    operation.setOperator(Operator.ADD);
    BiddableAdGroupCriterion newCriterion = (BiddableAdGroupCriterion) adGroupCriterionService.mutate(new AdGroupCriterionOperation[] { operation }).getValue(0);
    System.out.printf("Web page criterion with ID %d and status '%s' was created.%n", newCriterion.getCriterion().getId(), newCriterion.getUserStatus());
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) Webpage(com.google.api.ads.adwords.axis.v201809.cm.Webpage) AdGroupCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid) WebpageParameter(com.google.api.ads.adwords.axis.v201809.cm.WebpageParameter) WebpageCondition(com.google.api.ads.adwords.axis.v201809.cm.WebpageCondition)

Aggregations

Money (com.google.api.ads.adwords.axis.v201809.cm.Money)30 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)12 Budget (com.google.api.ads.adwords.axis.v201809.cm.Budget)11 CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)11 BudgetOperation (com.google.api.ads.adwords.axis.v201809.cm.BudgetOperation)10 BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)8 BudgetServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.BudgetServiceInterface)8 AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)6 AdGroup (com.google.api.ads.adwords.axis.v201809.cm.AdGroup)4 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)4 AdGroupCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface)4 AdGroupOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)4 Bids (com.google.api.ads.adwords.axis.v201809.cm.Bids)4 Budget (com.google.api.ads.adwords.jaxws.v201809.cm.Budget)4 BudgetOperation (com.google.api.ads.adwords.jaxws.v201809.cm.BudgetOperation)4 Money (com.google.api.ads.adwords.jaxws.v201809.cm.Money)4 AdWordsSession (com.google.api.ads.adwords.lib.client.AdWordsSession)4 AdWordsServices (com.google.api.ads.adwords.axis.factory.AdWordsServices)3 AdGroupServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface)3 CampaignOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation)3