Search in sources :

Example 51 with HttpTransport

use of com.google.api.client.http.HttpTransport in project googleads-java-lib by googleads.

the class OfflineCredentialsTest method testBuilder.

/**
 * Tests that the builder builds correctly.
 */
@Test
public void testBuilder() throws Exception {
    HttpTransport httpTransport = new NetHttpTransport();
    OfflineCredentials offlineCredentials = new OfflineCredentials.Builder().forApi(OfflineCredentials.Api.AD_MANAGER).withClientSecrets("clientId", "clientSecret").withRefreshToken("refreshToken").withHttpTransport(httpTransport).build();
    assertEquals("clientId", offlineCredentials.getClientId());
    assertEquals("clientSecret", offlineCredentials.getClientSecret());
    assertEquals("refreshToken", offlineCredentials.getRefreshToken());
    assertSame(httpTransport, offlineCredentials.getHttpTransport());
}
Also used : NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) Builder(com.google.api.ads.common.lib.auth.OfflineCredentials.Builder) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) Test(org.junit.Test)

Example 52 with HttpTransport

use of com.google.api.client.http.HttpTransport in project googleads-java-lib by googleads.

the class OfflineCredentialsTest method testGenerateCredential.

/**
 * Tests generating OAuth2 credentials.
 */
@Test
public void testGenerateCredential() throws Exception {
    HttpTransport httpTransport = new NetHttpTransport();
    OfflineCredentials offlineCredentials = new OfflineCredentials.Builder(oAuth2Helper).forApi(OfflineCredentials.Api.AD_MANAGER).withClientSecrets("clientId", "clientSecret").withRefreshToken("refreshToken").withHttpTransport(httpTransport).build();
    when(oAuth2Helper.callRefreshToken(Mockito.<Credential>any())).thenReturn(true);
    Credential credential = offlineCredentials.generateCredential();
    assertEquals("clientId", ((ClientParametersAuthentication) credential.getClientAuthentication()).getClientId());
    assertEquals("clientSecret", ((ClientParametersAuthentication) credential.getClientAuthentication()).getClientSecret());
    assertEquals("refreshToken", credential.getRefreshToken());
    assertSame(httpTransport, credential.getTransport());
}
Also used : NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) Credential(com.google.api.client.auth.oauth2.Credential) Builder(com.google.api.ads.common.lib.auth.OfflineCredentials.Builder) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) Test(org.junit.Test)

Example 53 with HttpTransport

use of com.google.api.client.http.HttpTransport in project data-transfer-project by google.

the class SslHelper method loginViaCertificate.

/**
 * Logs in in via WebTls and return the auth cookie to use*
 */
public String loginViaCertificate() throws GeneralSecurityException, IOException {
    SSLSocketFactory sslSocketFactory = getSocketFactory();
    HttpTransport transport = new NetHttpTransport.Builder().setSslSocketFactory(sslSocketFactory).build();
    return makeCall(transport);
}
Also used : NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) SSLSocketFactory(javax.net.ssl.SSLSocketFactory)

Example 54 with HttpTransport

use of com.google.api.client.http.HttpTransport in project data-transfer-project by google.

the class InstagramTransferExtension method initialize.

@Override
public void initialize(ExtensionContext context) {
    if (initialized) {
        Monitor monitor = context.getMonitor();
        monitor.severe(() -> "InstagramTransferExtension already initialized");
        return;
    }
    ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    HttpTransport httpTransport = context.getService(HttpTransport.class);
    exporter = new InstagramPhotoExporter(mapper, httpTransport);
    initialized = true;
}
Also used : HttpTransport(com.google.api.client.http.HttpTransport) InstagramPhotoExporter(org.datatransferproject.transfer.instagram.photos.InstagramPhotoExporter) Monitor(org.datatransferproject.api.launcher.Monitor) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 55 with HttpTransport

use of com.google.api.client.http.HttpTransport in project data-transfer-project by google.

the class BloggerTransferExtension method initialize.

@Override
public void initialize(ExtensionContext context) {
    // times.
    if (initialized) {
        return;
    }
    Monitor monitor = context.getMonitor();
    AppCredentials appCredentials;
    try {
        appCredentials = context.getService(AppCredentialStore.class).getAppCredentials("GOOGLEBLOGGER_KEY", "GOOGLEBLOGGER_SECRET");
    } catch (IOException e) {
        monitor.info(() -> "Unable to retrieve Google AppCredentials. " + "Did you set GOOGLEBLOGGER_KEY and GOOGLEBLOGGER_SECRET?");
        return;
    }
    HttpTransport httpTransport = context.getService(HttpTransport.class);
    JsonFactory jsonFactory = context.getService(JsonFactory.class);
    // Create the GoogleCredentialFactory with the given {@link AppCredentials}.
    GoogleCredentialFactory credentialFactory = new GoogleCredentialFactory(httpTransport, jsonFactory, appCredentials, monitor);
    ImmutableMap.Builder<String, Importer> importerBuilder = ImmutableMap.builder();
    importerBuilder.put("SOCIAL-POSTS", new GoogleBloggerImporter(credentialFactory));
    importerMap = importerBuilder.build();
    ImmutableMap.Builder<String, Exporter> exporterBuilder = ImmutableMap.builder();
    exporterMap = exporterBuilder.build();
    initialized = true;
}
Also used : AppCredentials(org.datatransferproject.types.transfer.auth.AppCredentials) JsonFactory(com.google.api.client.json.JsonFactory) IOException(java.io.IOException) GoogleCredentialFactory(org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory) Exporter(org.datatransferproject.spi.transfer.provider.Exporter) ImmutableMap(com.google.common.collect.ImmutableMap) HttpTransport(com.google.api.client.http.HttpTransport) Monitor(org.datatransferproject.api.launcher.Monitor) GoogleBloggerImporter(org.datatransferproject.datatransfer.google.blogger.GoogleBloggerImporter) GoogleBloggerImporter(org.datatransferproject.datatransfer.google.blogger.GoogleBloggerImporter) Importer(org.datatransferproject.spi.transfer.provider.Importer)

Aggregations

HttpTransport (com.google.api.client.http.HttpTransport)106 MockHttpTransport (com.google.api.client.testing.http.MockHttpTransport)40 JsonFactory (com.google.api.client.json.JsonFactory)35 HttpRequest (com.google.api.client.http.HttpRequest)29 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)28 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)28 GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)27 IOException (java.io.IOException)24 GoogleNetHttpTransport (com.google.api.client.googleapis.javanet.GoogleNetHttpTransport)21 HttpResponse (com.google.api.client.http.HttpResponse)21 GenericUrl (com.google.api.client.http.GenericUrl)15 MockLowLevelHttpRequest (com.google.api.client.testing.http.MockLowLevelHttpRequest)12 MockLowLevelHttpResponse (com.google.api.client.testing.http.MockLowLevelHttpResponse)11 Credential (com.google.api.client.auth.oauth2.Credential)10 HttpRequestFactory (com.google.api.client.http.HttpRequestFactory)10 Storage (com.google.api.services.storage.Storage)9 HttpRequestInitializer (com.google.api.client.http.HttpRequestInitializer)8 Test (org.junit.Test)8 Monitor (org.datatransferproject.api.launcher.Monitor)7 ErrorTransport (com.google.api.client.googleapis.json.GoogleJsonErrorTest.ErrorTransport)6