Search in sources :

Example 36 with Response

use of com.yahoo.vespa.clustercontroller.core.restapiv2.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);
}
Also used : Call(retrofit2.Call) OkHttpClient(okhttp3.OkHttpClient) HttpUrl(okhttp3.HttpUrl) Response(retrofit2.Response) Retrofit(retrofit2.Retrofit) Callback(retrofit2.Callback)

Example 37 with Response

use of com.yahoo.vespa.clustercontroller.core.restapiv2.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);
            }
        }
    });
}
Also used : Call(okhttp3.Call) OkHttpClient(okhttp3.OkHttpClient) SharedPreferences(android.content.SharedPreferences) JSONException(org.json.JSONException) Intent(android.content.Intent) IOException(java.io.IOException) Response(okhttp3.Response) Callback(okhttp3.Callback) ResultCallback(com.google.android.gms.common.api.ResultCallback) JSONObject(org.json.JSONObject)

Example 38 with Response

use of com.yahoo.vespa.clustercontroller.core.restapiv2.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;
            }
    }
}
Also used : Response(retrofit2.Response) Call(retrofit2.Call) Callback(retrofit2.Callback) Relationship(com.keylesspalace.tusky.entity.Relationship)

Example 39 with Response

use of com.yahoo.vespa.clustercontroller.core.restapiv2.Response in project Tusky by Vavassor.

the class BaseActivity method disablePushNotifications.

protected void disablePushNotifications() {
    Callback<ResponseBody> callback = new Callback<ResponseBody>() {

        @Override
        public void onResponse(Call<ResponseBody> call, retrofit2.Response<ResponseBody> response) {
            if (response.isSuccessful()) {
                pushNotificationClient.unsubscribeToTopic(getPushNotificationTopic());
            } else {
                onDisablePushNotificationsFailure();
            }
        }

        @Override
        public void onFailure(Call<ResponseBody> call, Throwable t) {
            onDisablePushNotificationsFailure();
        }
    };
    String deviceToken = pushNotificationClient.getDeviceToken();
    Session session = new Session(getDomain(), getAccessToken(), deviceToken);
    tuskyApi.unregister(session).enqueue(callback);
}
Also used : Response(okhttp3.Response) Call(retrofit2.Call) Callback(retrofit2.Callback) ResponseBody(okhttp3.ResponseBody) Session(com.keylesspalace.tusky.entity.Session)

Example 40 with Response

use of com.yahoo.vespa.clustercontroller.core.restapiv2.Response in project Tusky by Vavassor.

the class BaseActivity method createMastodonAPI.

protected void createMastodonAPI() {
    mastodonApiDispatcher = new Dispatcher();
    Gson gson = new GsonBuilder().registerTypeAdapter(Spanned.class, new SpannedTypeAdapter()).registerTypeAdapter(StringWithEmoji.class, new StringWithEmojiTypeAdapter()).create();
    OkHttpClient okHttpClient = OkHttpUtils.getCompatibleClientBuilder().addInterceptor(new Interceptor() {

        @Override
        public Response intercept(Chain chain) throws IOException {
            Request originalRequest = chain.request();
            Request.Builder builder = originalRequest.newBuilder();
            String accessToken = getAccessToken();
            if (accessToken != null) {
                builder.header("Authorization", String.format("Bearer %s", accessToken));
            }
            Request newRequest = builder.build();
            return chain.proceed(newRequest);
        }
    }).dispatcher(mastodonApiDispatcher).build();
    Retrofit retrofit = new Retrofit.Builder().baseUrl(getBaseUrl()).client(okHttpClient).addConverterFactory(GsonConverterFactory.create(gson)).build();
    mastodonAPI = retrofit.create(MastodonAPI.class);
}
Also used : OkHttpClient(okhttp3.OkHttpClient) GsonBuilder(com.google.gson.GsonBuilder) GsonBuilder(com.google.gson.GsonBuilder) SpannedTypeAdapter(com.keylesspalace.tusky.json.SpannedTypeAdapter) Request(okhttp3.Request) Gson(com.google.gson.Gson) IOException(java.io.IOException) Dispatcher(okhttp3.Dispatcher) Response(okhttp3.Response) Retrofit(retrofit2.Retrofit) StringWithEmojiTypeAdapter(com.keylesspalace.tusky.json.StringWithEmojiTypeAdapter) MastodonAPI(com.keylesspalace.tusky.network.MastodonAPI) Interceptor(okhttp3.Interceptor) StringWithEmoji(com.keylesspalace.tusky.json.StringWithEmoji)

Aggregations

Response (okhttp3.Response)1083 Request (okhttp3.Request)814 IOException (java.io.IOException)434 Test (org.junit.Test)330 Response (retrofit2.Response)319 Call (okhttp3.Call)236 ResponseBody (okhttp3.ResponseBody)208 OkHttpClient (okhttp3.OkHttpClient)192 ServiceResponse (com.microsoft.rest.ServiceResponse)179 RequestBody (okhttp3.RequestBody)128 Observable (rx.Observable)116 Callback (okhttp3.Callback)111 MockResponse (okhttp3.mockwebserver.MockResponse)93 List (java.util.List)89 HttpUrl (okhttp3.HttpUrl)81 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)72 TypeToken (com.google.common.reflect.TypeToken)71 ArrayList (java.util.ArrayList)71 File (java.io.File)70 JSONObject (org.json.JSONObject)65