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());
}
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());
}
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);
}
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;
}
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;
}
Aggregations