use of okhttp3.Response in project sonarqube by SonarSource.
the class CeHttpServerTest method start_starts_http_server_and_publishes_URL_in_IPC.
@Test
public void start_starts_http_server_and_publishes_URL_in_IPC() throws Exception {
Response response = call(underTest.getUrl() + "/pompom?toto=2");
assertIsPomPomResponse(response);
}
use of okhttp3.Response in project Reader by TheKeeperOfPie.
the class ActivityLogin method loadAccountInfo.
private void loadAccountInfo(final String tokenAuth, final String tokenRefresh, final long timeExpire) {
Request request = new Request.Builder().url(Reddit.OAUTH_URL + "/api/v1/me").header(Reddit.USER_AGENT, Reddit.CUSTOM_USER_AGENT).header(Reddit.AUTHORIZATION, Reddit.BEARER + tokenAuth).header(Reddit.CONTENT_TYPE, Reddit.CONTENT_TYPE_APP_JSON).get().build();
reddit.load(request).flatMap(UtilsRx.flatMapWrapError(response -> User.fromJson(ComponentStatic.getObjectMapper().readValue(response, JsonNode.class)))).subscribe(new FinalizingSubscriber<User>() {
@Override
public void next(User user) {
Account account = new Account(user.getName(), Reddit.ACCOUNT_TYPE);
Intent result = new Intent();
result.putExtra(AccountManager.KEY_ACCOUNT_NAME, user.getName());
result.putExtra(AccountManager.KEY_ACCOUNT_TYPE, Reddit.ACCOUNT_TYPE);
result.putExtra(AccountManager.KEY_AUTHTOKEN, tokenAuth);
if (getIntent().getBooleanExtra(KEY_IS_NEW_ACCOUNT, false)) {
Bundle extras = new Bundle();
extras.putString(KEY_TIME_EXPIRATION, String.valueOf(timeExpire));
accountManager.addAccountExplicitly(account, tokenRefresh, extras);
accountManager.setAuthToken(account, Reddit.AUTH_TOKEN_FULL_ACCESS, tokenAuth);
}
destroyWebView();
setAccountAuthenticatorResult(result.getExtras());
setResult(RESULT_OK, result);
ActivityLogin.this.finish();
}
});
}
use of okhttp3.Response in project Reader by TheKeeperOfPie.
the class ActivityLogin method fetchTokens.
private void fetchTokens(String code) {
RequestBody requestBody = new FormBody.Builder().add(Reddit.QUERY_GRANT_TYPE, Reddit.CODE_GRANT).add(Reddit.QUERY_CODE, code).add(Reddit.QUERY_REDIRECT_URI, Reddit.REDIRECT_URI).build();
Request request = Reddit.withRequestBasicAuth().url(Reddit.ACCESS_URL).post(requestBody).build();
reddit.load(request).subscribe(new FinalizingSubscriber<String>() {
@Override
public void next(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
String tokenAccess = jsonObject.getString(Reddit.QUERY_ACCESS_TOKEN);
String tokenRefresh = jsonObject.getString(Reddit.QUERY_REFRESH_TOKEN);
long timeExpire = System.currentTimeMillis() + jsonObject.getLong(Reddit.QUERY_EXPIRES_IN) * Reddit.SEC_TO_MS;
Log.d(TAG, "timeExpire in: " + jsonObject.getLong(Reddit.QUERY_EXPIRES_IN));
loadAccountInfo(tokenAccess, tokenRefresh, timeExpire);
} catch (JSONException e) {
onError(e);
}
}
@Override
public void error(Throwable e) {
Toast.makeText(ActivityLogin.this, R.string.error_logging_in, Toast.LENGTH_LONG).show();
}
});
}
use of okhttp3.Response in project Reader by TheKeeperOfPie.
the class Reddit method getApplicationWideTokenBlocking.
private void getApplicationWideTokenBlocking() {
if ("".equals(preferences.getString(AppSettings.DEVICE_ID, ""))) {
preferences.edit().putString(AppSettings.DEVICE_ID, UUID.randomUUID().toString()).apply();
}
RequestBody requestBody = new FormBody.Builder().add(QUERY_GRANT_TYPE, INSTALLED_CLIENT_GRANT).add(QUERY_DEVICE_ID, preferences.getString(AppSettings.DEVICE_ID, UUID.randomUUID().toString())).build();
Request request = new Request.Builder().url(ACCESS_URL).post(requestBody).build();
try {
String response = okHttpClientDefault.newCall(request).execute().body().string();
// Check if an account was set while fetching a token
if (account == null) {
JSONObject jsonObject = new JSONObject(response);
tokenAuth = jsonObject.getString(QUERY_ACCESS_TOKEN);
timeExpire = System.currentTimeMillis() + jsonObject.getLong(QUERY_EXPIRES_IN) * SEC_TO_MS;
}
} catch (JSONException | IOException e) {
e.printStackTrace();
}
}
use of okhttp3.Response in project SeriesGuide by UweTrottmann.
the class HttpClientModule method provideOkHttpClient.
/**
* Returns this apps {@link OkHttpClient} with enabled response cache. Should be used with API
* calls.
*/
@Provides
@Singleton
OkHttpClient provideOkHttpClient(SgApp app, Cache cache) {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.connectTimeout(CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
builder.readTimeout(READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
builder.addInterceptor(new SgTmdbInterceptor());
builder.addNetworkInterceptor(new SgTheTvdbInterceptor(app));
builder.addNetworkInterceptor(new SgTraktInterceptor(app));
builder.authenticator(new AllApisAuthenticator(app));
builder.cache(cache);
return builder.build();
}
Aggregations