use of retrofit2.Call in project Tusky by Vavassor.
the class BaseActivity method enablePushNotifications.
protected void enablePushNotifications() {
Callback<ResponseBody> callback = new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) {
if (response.isSuccessful()) {
pushNotificationClient.subscribeToTopic(getPushNotificationTopic());
pushNotificationClient.connect(BaseActivity.this);
} else {
onEnablePushNotificationsFailure(response.message());
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
onEnablePushNotificationsFailure(t.getMessage());
}
};
String deviceToken = pushNotificationClient.getDeviceToken();
Session session = new Session(getDomain(), getAccessToken(), deviceToken);
tuskyApi.register(session).enqueue(callback);
}
use of retrofit2.Call in project Tusky by Vavassor.
the class LoginActivity method onStart.
@Override
protected void onStart() {
super.onStart();
/* Check if we are resuming during authorization by seeing if the intent contains the
* redirect that was given to the server. If so, its response is here! */
Uri uri = getIntent().getData();
String redirectUri = getOauthRedirectUri();
preferences = getSharedPreferences(getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
if (preferences.getString("accessToken", null) != null && preferences.getString("domain", null) != null) {
// We are already logged in, go to MainActivity
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
return;
}
if (uri != null && uri.toString().startsWith(redirectUri)) {
// This should either have returned an authorization code or an error.
String code = uri.getQueryParameter("code");
String error = uri.getQueryParameter("error");
if (code != null) {
/* During the redirect roundtrip this Activity usually dies, which wipes out the
* instance variables, so they have to be recovered from where they were saved in
* SharedPreferences. */
domain = preferences.getString("domain", null);
clientId = preferences.getString("clientId", null);
clientSecret = preferences.getString("clientSecret", null);
setLoading(true);
/* Since authorization has succeeded, the final step to log in is to exchange
* the authorization code for an access token. */
Callback<AccessToken> callback = new Callback<AccessToken>() {
@Override
public void onResponse(Call<AccessToken> call, Response<AccessToken> response) {
if (response.isSuccessful()) {
onLoginSuccess(response.body().accessToken);
} else {
setLoading(false);
editText.setError(getString(R.string.error_retrieving_oauth_token));
Log.e(TAG, String.format("%s %s", getString(R.string.error_retrieving_oauth_token), response.message()));
}
}
@Override
public void onFailure(Call<AccessToken> call, Throwable t) {
setLoading(false);
editText.setError(getString(R.string.error_retrieving_oauth_token));
Log.e(TAG, String.format("%s %s", getString(R.string.error_retrieving_oauth_token), t.getMessage()));
}
};
getApiFor(domain).fetchOAuthToken(clientId, clientSecret, redirectUri, code, "authorization_code").enqueue(callback);
} else if (error != null) {
/* Authorization failed. Put the error response where the user can read it and they
* can try again. */
setLoading(false);
editText.setError(getString(R.string.error_authorization_denied));
Log.e(TAG, getString(R.string.error_authorization_denied) + error);
} else {
setLoading(false);
// This case means a junk response was received somehow.
editText.setError(getString(R.string.error_authorization_unknown));
}
}
}
use of retrofit2.Call in project Rocket.Chat.Android by RocketChat.
the class DefaultServerPolicyApi method getOkHttpCallback.
private okhttp3.Callback getOkHttpCallback(@NonNull FlowableEmitter<Response<JSONObject>> emitter, @NonNull String protocol) {
return new okhttp3.Callback() {
@Override
public void onFailure(Call call, IOException ioException) {
if (emitter.isCancelled()) {
return;
}
emitter.onError(ioException);
}
@Override
public void onResponse(Call call, okhttp3.Response response) throws IOException {
if (emitter.isCancelled()) {
return;
}
if (!response.isSuccessful()) {
emitter.onNext(new Response<>(false, protocol, null));
emitter.onComplete();
return;
}
final ResponseBody body = response.body();
if (body == null || body.contentLength() == 0) {
emitter.onNext(new Response<>(false, protocol, null));
emitter.onComplete();
return;
}
try {
emitter.onNext(new Response<>(true, protocol, new JSONObject(body.string())));
} catch (Exception e) {
emitter.onNext(new Response<>(false, protocol, null));
}
emitter.onComplete();
}
};
}
use of retrofit2.Call in project yyl_example by Relucent.
the class OkhttpTest2 method main.
public static void main(String[] args) throws IOException {
OkHttpClient client;
(client = //
new OkHttpClient.Builder().build()).newCall(//
new Request.Builder().url(//
"https://www.baidu.com/").header("Connection", //close | keep-alive
"close").get().build()).enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) throws IOException {
System.out.println(response.body().string());
}
@Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
}
});
//应用关闭时候需要关闭线程池
client.dispatcher().executorService().shutdown();
}
use of retrofit2.Call in project azure-sdk-for-java by Azure.
the class KeyVaultClientImpl method decryptWithServiceResponseAsync.
/**
* Decrypts a single block of encrypted data.
*
* @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net.
* @param keyName The name of the key.
* @param keyVersion The version of the key.
* @param algorithm algorithm identifier. Possible values include: 'RSA-OAEP', 'RSA1_5'
* @param value the Base64Url value
* @return the observable to the KeyOperationResult object
*/
public Observable<ServiceResponse<KeyOperationResult>> decryptWithServiceResponseAsync(String vaultBaseUrl, String keyName, String keyVersion, JsonWebKeyEncryptionAlgorithm algorithm, byte[] value) {
if (vaultBaseUrl == null) {
throw new IllegalArgumentException("Parameter vaultBaseUrl is required and cannot be null.");
}
if (keyName == null) {
throw new IllegalArgumentException("Parameter keyName is required and cannot be null.");
}
if (keyVersion == null) {
throw new IllegalArgumentException("Parameter keyVersion is required and cannot be null.");
}
if (this.apiVersion() == null) {
throw new IllegalArgumentException("Parameter this.apiVersion() is required and cannot be null.");
}
if (algorithm == null) {
throw new IllegalArgumentException("Parameter algorithm is required and cannot be null.");
}
if (value == null) {
throw new IllegalArgumentException("Parameter value is required and cannot be null.");
}
KeyOperationsParameters parameters = new KeyOperationsParameters();
parameters.withAlgorithm(algorithm);
parameters.withValue(value);
String parameterizedHost = Joiner.on(", ").join("{vaultBaseUrl}", vaultBaseUrl);
return service.decrypt(keyName, keyVersion, this.apiVersion(), this.acceptLanguage(), parameters, parameterizedHost, this.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<KeyOperationResult>>>() {
@Override
public Observable<ServiceResponse<KeyOperationResult>> call(Response<ResponseBody> response) {
try {
ServiceResponse<KeyOperationResult> clientResponse = decryptDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
Aggregations