Search in sources :

Example 41 with Callback

use of zipkin2.Callback in project Tusky by tuskyapp.

the class ReportActivity method fetchRecentStatuses.

private void fetchRecentStatuses(String accountId) {
    Callback<List<Status>> callback = new Callback<List<Status>>() {

        @Override
        public void onResponse(Call<List<Status>> call, Response<List<Status>> response) {
            if (!response.isSuccessful()) {
                onFetchStatusesFailure(new Exception(response.message()));
                return;
            }
            List<Status> statusList = response.body();
            List<ReportAdapter.ReportStatus> itemList = new ArrayList<>();
            for (Status status : statusList) {
                if (status.getReblog() == null) {
                    ReportAdapter.ReportStatus item = new ReportAdapter.ReportStatus(status.getId(), status.getContent(), false);
                    itemList.add(item);
                }
            }
            adapter.addItems(itemList);
        }

        @Override
        public void onFailure(Call<List<Status>> call, Throwable t) {
            onFetchStatusesFailure((Exception) t);
        }
    };
    mastodonApi.accountStatuses(accountId, null, null, null, null).enqueue(callback);
}
Also used : Status(com.keylesspalace.tusky.entity.Status) ReportAdapter(com.keylesspalace.tusky.adapter.ReportAdapter) Call(retrofit2.Call) ArrayList(java.util.ArrayList) Response(retrofit2.Response) Callback(retrofit2.Callback) ArrayList(java.util.ArrayList) List(java.util.List)

Example 42 with Callback

use of zipkin2.Callback in project EssayJoke by qiyei2015.

the class OkHttpEngine method post.

@Override
public void post(HttpRequest httpRequest, final IHttpCallback callback) {
    RequestBody requestBody = buildPostRequest(httpRequest);
    Request request = new Request.Builder().url(httpRequest.getUrl()).post(requestBody).build();
    LogManager.e("Post请求路径:", httpRequest.getUrl());
    mClient.newCall(request).enqueue(new Callback() {

        @Override
        public void onFailure(Call call, IOException e) {
            callback.onFail(e);
        }

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            if (response != null && response.isSuccessful()) {
                callback.onSuccess(response.body().string());
            } else {
                callback.onFail(new Exception("error"));
            }
        }
    });
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Callback(okhttp3.Callback) IHttpCallback(com.qiyei.sdk.http.base.IHttpCallback) Request(okhttp3.Request) HttpRequest(com.qiyei.sdk.http.base.HttpRequest) IOException(java.io.IOException) IOException(java.io.IOException) RequestBody(okhttp3.RequestBody)

Example 43 with Callback

use of zipkin2.Callback in project butter-android by butterproject.

the class ButterUpdateManager method downloadFile.

private void downloadFile(final String location) {
    Request request = new Request.Builder().url(location).build();
    mHttpClient.newCall(request).enqueue(new Callback() {

        @Override
        public void onFailure(Call call, IOException e) {
        // uhoh
        }

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            if (response.isSuccessful()) {
                String fileName = location.substring(location.lastIndexOf('/') + 1);
                File downloadedFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), fileName);
                BufferedSink sink = Okio.buffer(Okio.sink(downloadedFile));
                sink.writeAll(response.body().source());
                sink.close();
                String updateFilePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/" + fileName;
                prefManager.getPrefs().edit().putString(SHA1_KEY, hashSHA1(updateFilePath)).putString(UPDATE_FILE, updateFilePath).putLong(SHA1_TIME, System.currentTimeMillis()).apply();
                if (mListener != null) {
                    mListener.updateAvailable(updateFilePath);
                }
            }
        }
    });
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Callback(okhttp3.Callback) Request(okhttp3.Request) BufferedSink(okio.BufferedSink) IOException(java.io.IOException) File(java.io.File)

Example 44 with Callback

use of zipkin2.Callback in project AnyMemo by helloworld1.

the class DropboxApiHelper method getUserInfo.

public Single<UserInfo> getUserInfo(@NonNull final String token) {
    return Single.create(new SingleOnSubscribe<UserInfo>() {

        @Override
        public void subscribe(@NonNull final SingleEmitter<UserInfo> emitter) throws Exception {
            RequestBody requestBody = RequestBody.create(null, new byte[0]);
            Request request = new Request.Builder().url(USER_INFO_ENDPOINT).addHeader("Authorization", "Bearer " + token).post(requestBody).build();
            okHttpClient.newCall(request).enqueue(new Callback() {

                @Override
                public void onFailure(Call call, IOException e) {
                    emitter.onError(e);
                }

                @Override
                public void onResponse(Call call, Response response) throws IOException {
                    if (!response.isSuccessful()) {
                        emitter.onError(new IOException(getResponseErrorString(call.request(), response)));
                        return;
                    }
                    UserInfo userInfo = new UserInfo();
                    try {
                        JSONObject userInfoObject = new JSONObject(response.body().string());
                        userInfo.accountId = userInfoObject.getString("account_id");
                        userInfo.email = userInfoObject.getString("email");
                        JSONObject nameObject = userInfoObject.getJSONObject("name");
                        userInfo.displayName = nameObject.getString("display_name");
                        emitter.onSuccess(userInfo);
                    } catch (JSONException e) {
                        emitter.onError(e);
                    }
                }
            });
        }
    });
}
Also used : Call(okhttp3.Call) Request(okhttp3.Request) JSONException(org.json.JSONException) UserInfo(org.liberty.android.fantastischmemo.downloader.dropbox.entity.UserInfo) IOException(java.io.IOException) JSONException(org.json.JSONException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Response(okhttp3.Response) Callback(okhttp3.Callback) JSONObject(org.json.JSONObject) RequestBody(okhttp3.RequestBody)

Example 45 with Callback

use of zipkin2.Callback in project syndesis by syndesisio.

the class KubernetesSupport method watchLog.

/*
     * Feeds the controller of the given podName to the callback handler for processing.
     *
     * We do this instead of using the watchLog() feature of the k8s client lib because it really sucks due to:
     *  1. You can't configure the timestamps option or the sinceTime option.  Need to resume log downloads.
     *  2. It seems to need extra threads..
     *  3. It might be hiding some of the http failure conditions.
     *
     */
protected void watchLog(String podName, Consumer<InputStream> handler, String sinceTime, Executor executor) throws IOException {
    try {
        PodOperationsImpl pod = (PodOperationsImpl) client.pods().withName(podName);
        StringBuilder url = new StringBuilder().append(pod.getResourceUrl().toString()).append("/log?pretty=false&follow=true&timestamps=true");
        if (sinceTime != null) {
            url.append("&sinceTime=");
        }
        Request request = new Request.Builder().url(new URL(url.toString())).get().build();
        OkHttpClient clone = okHttpClient.newBuilder().readTimeout(0, TimeUnit.MILLISECONDS).build();
        clone.newCall(request).enqueue(new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                LOG.info("Failure occurred getting  controller for pod: {},", podName, e);
                handler.accept(null);
            }

            @Override
            public void onResponse(final Call call, final Response response) throws IOException {
                executor.execute(() -> {
                    try {
                        if (response.code() == 200) {
                            handler.accept(response.body().byteStream());
                        } else {
                            LOG.info("Failure occurred while processing controller for pod: {}, http status: {}, details: {}", podName, response.code(), response.body().string());
                            handler.accept(null);
                        }
                    } catch (IOException e) {
                        LOG.error("Unexpected Error", e);
                    }
                });
            }
        });
    } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") RuntimeException t) {
        throw new IOException("Unexpected Error", t);
    }
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) OkHttpClient(okhttp3.OkHttpClient) Callback(okhttp3.Callback) Request(okhttp3.Request) IOException(java.io.IOException) PodOperationsImpl(io.fabric8.kubernetes.client.dsl.internal.PodOperationsImpl) URL(java.net.URL)

Aggregations

Callback (okhttp3.Callback)173 IOException (java.io.IOException)137 Call (okhttp3.Call)132 Response (okhttp3.Response)132 Request (okhttp3.Request)110 Callback (retrofit2.Callback)42 Call (retrofit2.Call)41 Test (org.junit.Test)39 Response (retrofit2.Response)39 RequestBody (okhttp3.RequestBody)37 OkHttpClient (okhttp3.OkHttpClient)34 File (java.io.File)27 Context (android.content.Context)24 JSONObject (org.json.JSONObject)20 FormBody (okhttp3.FormBody)19 ArrayList (java.util.ArrayList)18 View (android.view.View)16 Intent (android.content.Intent)14 TextView (android.widget.TextView)14 GsonBuilder (com.google.gson.GsonBuilder)14