Search in sources :

Example 6 with Builder

use of com.google.api.ads.adwords.lib.client.AdWordsSession.Builder in project googleads-java-lib by googleads.

the class AdWordsSessionTest method testBuilder_returnsCopies.

/**
 * Makes sure the builder returns a copy so that making (un-validated) changes in the builder
 * doesn't mutate previously built objects.
 */
@Test
public void testBuilder_returnsCopies() throws Exception {
    AdWordsSession.Builder builder = new AdWordsSession.Builder().withUserAgent("FooBar").withOAuth2Credential(credential).withEndpoint("https://www.google.com").withDeveloperToken("developerToken");
    assertNotSame(build(builder), build(builder));
}
Also used : Builder(com.google.api.ads.adwords.lib.client.AdWordsSession.Builder) ImmutableAdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession.ImmutableAdWordsSession) Builder(com.google.api.ads.adwords.lib.client.AdWordsSession.Builder) Test(org.junit.Test)

Example 7 with Builder

use of com.google.api.ads.adwords.lib.client.AdWordsSession.Builder in project googleads-java-lib by googleads.

the class AdWordsSessionTest method testBuilder_withReportingConfiguration.

@Test
public void testBuilder_withReportingConfiguration() throws Exception {
    ReportingConfiguration reportingConfiguration = new ReportingConfiguration.Builder().skipReportHeader(true).skipReportSummary(true).build();
    AdWordsSession adWordsSession = build(new AdWordsSession.Builder().withUserAgent("FooBar").withEndpoint("https://www.google.com").withOAuth2Credential(credential).withDeveloperToken("developerToken").withReportingConfiguration(reportingConfiguration));
    ReportingConfiguration sessionReportingConfig = adWordsSession.getReportingConfiguration();
    assertNotNull("reporting configuration should not be null when passed to the builder", sessionReportingConfig);
}
Also used : ImmutableAdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession.ImmutableAdWordsSession) Builder(com.google.api.ads.adwords.lib.client.AdWordsSession.Builder) ReportingConfiguration(com.google.api.ads.adwords.lib.client.reporting.ReportingConfiguration) Test(org.junit.Test)

Example 8 with Builder

use of com.google.api.ads.adwords.lib.client.AdWordsSession.Builder in project googleads-java-lib by googleads.

the class AdWordsSessionTest method testBuilder_defaultEndpoint.

/**
 * Tests that the builder builds correctly with a default endpoint.
 */
@Test
public void testBuilder_defaultEndpoint() throws Exception {
    AdWordsSession adWordsSession = build(new AdWordsSession.Builder().withUserAgent("FooBar").withOAuth2Credential(credential).withDeveloperToken("developerToken"));
    assertEquals("FooBar", adWordsSession.getUserAgent());
    assertSame(credential, adWordsSession.getOAuth2Credential());
    assertEquals(AdWordsSession.DEFAULT_ENDPOINT, adWordsSession.getEndpoint());
    assertEquals("developerToken", adWordsSession.getDeveloperToken());
}
Also used : ImmutableAdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession.ImmutableAdWordsSession) Builder(com.google.api.ads.adwords.lib.client.AdWordsSession.Builder) Test(org.junit.Test)

Example 9 with Builder

use of com.google.api.ads.adwords.lib.client.AdWordsSession.Builder in project googleads-java-lib by googleads.

the class AddShoppingDynamicRemarketingCampaign method main.

public static void main(String[] args) {
    final AdWordsServicesInterface services = AdWordsServices.getInstance();
    AdWordsSession session;
    try {
        Credential oAuth2Credential;
        oAuth2Credential = new OfflineCredentials.Builder().forApi(OfflineCredentials.Api.ADWORDS).fromFile().build().generateCredential();
        session = new Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
    } catch (ConfigurationLoadException cle) {
        System.err.printf("Failed to load configuration from the %s file%n", DEFAULT_CONFIGURATION_FILENAME);
        return;
    } catch (ValidationException ve) {
        System.err.printf("Invalid configuration in the %s file%n", DEFAULT_CONFIGURATION_FILENAME);
        return;
    } catch (OAuthException oe) {
        System.err.printf("Failed to create OAuth credentials. Check OAuth settings in the %s file%n", DEFAULT_CONFIGURATION_FILENAME);
        return;
    }
    final AddShoppingDynamicRemarketingCampaignParams params = new AddShoppingDynamicRemarketingCampaignParams();
    if (!params.parseArguments(args)) {
        params.merchantId = Long.parseLong("INSERT_MERCHANT_ID");
        params.budgetId = Long.parseLong("INSERT_BUDGET_ID");
        params.userListId = Long.parseLong("INSERT_USER_LIST_ID");
    }
    try {
        runExample(services, session, params.merchantId, params.budgetId, params.userListId);
    } catch (ApiException apiException) {
        // ApiException is the base class for most exceptions thrown by an API request. Instances
        // of this exception have a message and a collection of ApiErrors that indicate the
        // type and underlying cause of the exception. Every exception object in the adwords.axis
        // packages will return a meaningful value from toString.
        // 
        // ApiException extends RemoteException, so this catch block must appear before the
        // catch block for RemoteException.
        System.err.print("Request failed due to ApiException. Underlying ApiErrors:");
        if (apiException.getErrors() != null) {
            int i = 0;
            for (ApiError apiError : apiException.getErrors()) {
                System.err.printf("  Error %d: %s%n", i++, apiError);
            }
        }
    } catch (RemoteException re) {
        System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
    } catch (IOException e) {
        System.err.printf("Request failed unexpectedly due to IOException: %s%n", e);
    }
}
Also used : Credential(com.google.api.client.auth.oauth2.Credential) ValidationException(com.google.api.ads.common.lib.exception.ValidationException) OfflineCredentials(com.google.api.ads.common.lib.auth.OfflineCredentials) AdWordsServicesInterface(com.google.api.ads.adwords.lib.factory.AdWordsServicesInterface) Builder(com.google.api.ads.adwords.lib.client.AdWordsSession.Builder) OAuthException(com.google.api.ads.common.lib.exception.OAuthException) IOException(java.io.IOException) AdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession) ConfigurationLoadException(com.google.api.ads.common.lib.conf.ConfigurationLoadException) ApiError(com.google.api.ads.adwords.axis.v201809.cm.ApiError) RemoteException(java.rmi.RemoteException) ApiException(com.google.api.ads.adwords.axis.v201809.cm.ApiException)

Example 10 with Builder

use of com.google.api.ads.adwords.lib.client.AdWordsSession.Builder in project googleads-java-lib by googleads.

the class AdWordsSessionTest method testBuilder_oAuth2.

/**
 * Tests that the builder builds correctly for OAuth2.
 */
@Test
public void testBuilder_oAuth2() throws Exception {
    AdWordsSession adWordsSession = build(new AdWordsSession.Builder().withUserAgent("FooBar").withEndpoint("https://www.google.com").withOAuth2Credential(credential).withDeveloperToken("developerToken"));
    assertEquals("FooBar", adWordsSession.getUserAgent());
    assertSame(credential, adWordsSession.getOAuth2Credential());
    assertEquals("https://www.google.com", adWordsSession.getEndpoint());
    assertEquals("developerToken", adWordsSession.getDeveloperToken());
}
Also used : Builder(com.google.api.ads.adwords.lib.client.AdWordsSession.Builder) ImmutableAdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession.ImmutableAdWordsSession) Test(org.junit.Test)

Aggregations

Builder (com.google.api.ads.adwords.lib.client.AdWordsSession.Builder)12 ImmutableAdWordsSession (com.google.api.ads.adwords.lib.client.AdWordsSession.ImmutableAdWordsSession)11 Test (org.junit.Test)11 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)5 ReportingConfiguration (com.google.api.ads.adwords.lib.client.reporting.ReportingConfiguration)2 ApiError (com.google.api.ads.adwords.axis.v201809.cm.ApiError)1 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)1 AdWordsSession (com.google.api.ads.adwords.lib.client.AdWordsSession)1 AdWordsServicesInterface (com.google.api.ads.adwords.lib.factory.AdWordsServicesInterface)1 OfflineCredentials (com.google.api.ads.common.lib.auth.OfflineCredentials)1 ConfigurationLoadException (com.google.api.ads.common.lib.conf.ConfigurationLoadException)1 OAuthException (com.google.api.ads.common.lib.exception.OAuthException)1 ValidationException (com.google.api.ads.common.lib.exception.ValidationException)1 Credential (com.google.api.client.auth.oauth2.Credential)1 IOException (java.io.IOException)1 RemoteException (java.rmi.RemoteException)1