use of com.ecwid.consul.v1.Response in project Pokemap by omkarmoghe.
the class GoogleManager method refreshToken.
public void refreshToken(String refreshToken, final RefreshListener listener) {
HttpUrl url = HttpUrl.parse(OAUTH_TOKEN_ENDPOINT).newBuilder().addQueryParameter("client_id", CLIENT_ID).addQueryParameter("client_secret", SECRET).addQueryParameter("refresh_token", refreshToken).addQueryParameter("grant_type", "refresh_token").build();
Callback<GoogleService.TokenResponse> googleCallback = new Callback<GoogleService.TokenResponse>() {
@Override
public void onResponse(Call<GoogleService.TokenResponse> call, Response<GoogleService.TokenResponse> response) {
if (response != null && response.body() != null) {
listener.refreshSuccessful(response.body().getIdToken(), response.body().getRefreshToken());
} else {
listener.refreshFailed("Failed on requesting the id token");
}
}
@Override
public void onFailure(Call<GoogleService.TokenResponse> call, Throwable t) {
t.printStackTrace();
listener.refreshFailed("Failed on requesting the id token");
}
};
if (mGoogleService != null) {
Call<GoogleService.TokenResponse> call = mGoogleService.requestToken(url.toString());
call.enqueue(googleCallback);
}
}
use of com.ecwid.consul.v1.Response in project Pokemap by omkarmoghe.
the class NetworkRequestLoggingInterceptor method intercept.
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
final Request request = chain.request();
// Log request
Log.d(TAG, MessageFormat.format(REQUEST_SEND_LOG, request.method(), sanitize(request.url()), chain.connection(), request.headers()));
if (request.method().compareToIgnoreCase("post") == 0)
Log.d(TAG, MessageFormat.format(REQUEST_BODY_LOG, convertRequestBodyToString(request)));
final long requestStart = System.currentTimeMillis();
final Response response = chain.proceed(request);
final long requestEnd = System.currentTimeMillis();
final long responseTime = requestEnd - requestStart;
// Log response
Log.d(TAG, MessageFormat.format(RESPONSE_RECEIVE_LOG, responseTime, sanitize(response.request().url()), response.headers()));
final String responseBodyString = response.body().string();
if (responseBodyString.length() > 0)
Log.d(TAG, MessageFormat.format(RESPONSE_BODY_LOG, responseBodyString.trim()));
return response.newBuilder().body(ResponseBody.create(response.body().contentType(), responseBodyString)).build();
}
use of com.ecwid.consul.v1.Response in project Pokemap by omkarmoghe.
the class NianticManager method loginPTC.
private void loginPTC(final String username, final String password, NianticService.LoginValues values, final LoginListener loginListener) {
HttpUrl url = HttpUrl.parse(LOGIN_URL).newBuilder().addQueryParameter("lt", values.getLt()).addQueryParameter("execution", values.getExecution()).addQueryParameter("_eventId", "submit").addQueryParameter("username", username).addQueryParameter("password", password).build();
OkHttpClient client = mClient.newBuilder().followRedirects(false).followSslRedirects(false).build();
NianticService service = new Retrofit.Builder().baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create()).client(client).build().create(NianticService.class);
Callback<NianticService.LoginResponse> loginCallback = new Callback<NianticService.LoginResponse>() {
@Override
public void onResponse(Call<NianticService.LoginResponse> call, Response<NianticService.LoginResponse> response) {
String location = response.headers().get("location");
if (location != null && location.split("ticket=").length > 0) {
String ticket = location.split("ticket=")[1];
requestToken(ticket, loginListener);
} else {
Log.e(TAG, "PTC login failed via loginPTC(). There was no location header in response.");
loginListener.authFailed("Pokemon Trainer Club Login Failed");
}
}
@Override
public void onFailure(Call<NianticService.LoginResponse> call, Throwable t) {
t.printStackTrace();
Log.e(TAG, "PTC login failed via loginPTC(). loginCallback.onFailure() threw: " + t.getMessage());
loginListener.authFailed("Pokemon Trainer Club Login Failed");
}
};
Call<NianticService.LoginResponse> call = service.login(url.toString());
call.enqueue(loginCallback);
}
use of com.ecwid.consul.v1.Response in project Android by Tracman-org.
the class LoginActivity method authenticateWithTracmanServer.
private void authenticateWithTracmanServer(final Request request) throws Exception {
// Needed to support TLS 1.1 and 1.2
// TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(
// TrustManagerFactory.getDefaultAlgorithm());
// trustManagerFactory.init((KeyStore) null);
// TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
// if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) {
// throw new IllegalStateException("Unexpected default trust managers:"
// + Arrays.toString(trustManagers));
// }
// X509TrustManager trustManager = (X509TrustManager) trustManagers[0];
OkHttpClient client = new OkHttpClient.Builder().build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
//Log.e(TAG, "Failed to connect to Tracman server!");
showError(R.string.server_connection_error);
e.printStackTrace();
}
@Override
public void onResponse(Call call, Response res) throws IOException {
if (!res.isSuccessful()) {
showError(R.string.login_no_user_error);
res.body().close();
throw new IOException("Unexpected code: " + res);
} else {
//Log.d(TAG, "Response code: " + res.code());
String userString = res.body().string();
System.out.println("Full response: " + userString);
String userID, userName, userSK;
try {
JSONObject user = new JSONObject(userString);
userID = user.getString("_id");
userName = user.getString("name");
userSK = user.getString("sk32");
//Log.v(TAG, "User retrieved with ID: " + userID);
} catch (JSONException e) {
//Log.e(TAG, "Unable to parse user JSON: ", e);
//Log.e(TAG, "JSON String used: " + userString);
userID = null;
userName = null;
userSK = null;
}
// Save user as loggedInUser
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("loggedInUser", userString);
editor.putString("loggedInUserId", userID);
editor.putString("loggedInUserName", userName);
editor.putString("loggedInUserSk", userSK);
editor.commit();
startActivityForResult(new Intent(LoginActivity.this, SettingsActivity.class), SIGN_OUT);
}
}
});
}
use of com.ecwid.consul.v1.Response in project Tusky by Vavassor.
the class AccountActivity method follow.
private void follow(final String id) {
Callback<Relationship> cb = new Callback<Relationship>() {
@Override
public void onResponse(Call<Relationship> call, Response<Relationship> response) {
if (response.isSuccessful()) {
Relationship relationship = response.body();
if (relationship.following) {
followState = FollowState.FOLLOWING;
} else if (relationship.requested) {
followState = FollowState.REQUESTED;
Snackbar.make(container, R.string.state_follow_requested, Snackbar.LENGTH_LONG).show();
} else {
followState = FollowState.NOT_FOLLOWING;
broadcast(TimelineReceiver.Types.UNFOLLOW_ACCOUNT, id);
}
updateButtons();
} else {
onFollowFailure(id);
}
}
@Override
public void onFailure(Call<Relationship> call, Throwable t) {
onFollowFailure(id);
}
};
Assert.expect(followState != FollowState.REQUESTED);
switch(followState) {
case NOT_FOLLOWING:
{
mastodonAPI.followAccount(id).enqueue(cb);
break;
}
case FOLLOWING:
{
mastodonAPI.unfollowAccount(id).enqueue(cb);
break;
}
}
}
Aggregations