Search in sources :

Example 51 with Call

use of zipkin2.Call in project bitcoin-wallet by bitcoin-wallet.

the class ExchangeRatesProvider method requestExchangeRates.

private Map<String, ExchangeRate> requestExchangeRates() {
    final Stopwatch watch = Stopwatch.createStarted();
    final Request.Builder request = new Request.Builder();
    request.url(BITCOINAVERAGE_URL);
    request.header("User-Agent", userAgent);
    final Call call = Constants.HTTP_CLIENT.newCall(request.build());
    try {
        final Response response = call.execute();
        if (response.isSuccessful()) {
            final String content = response.body().string();
            final JSONObject head = new JSONObject(content);
            final Map<String, ExchangeRate> rates = new TreeMap<String, ExchangeRate>();
            for (final Iterator<String> i = head.keys(); i.hasNext(); ) {
                final String currencyCode = i.next();
                if (currencyCode.startsWith("BTC")) {
                    final String fiatCurrencyCode = currencyCode.substring(3);
                    if (!fiatCurrencyCode.equals(MonetaryFormat.CODE_BTC) && !fiatCurrencyCode.equals(MonetaryFormat.CODE_MBTC) && !fiatCurrencyCode.equals(MonetaryFormat.CODE_UBTC)) {
                        final JSONObject exchangeRate = head.getJSONObject(currencyCode);
                        final JSONObject averages = exchangeRate.getJSONObject("averages");
                        try {
                            final Fiat rate = parseFiatInexact(fiatCurrencyCode, averages.getString("day"));
                            if (rate.signum() > 0)
                                rates.put(fiatCurrencyCode, new ExchangeRate(new org.bitcoinj.utils.ExchangeRate(rate), BITCOINAVERAGE_SOURCE));
                        } catch (final IllegalArgumentException x) {
                            log.warn("problem fetching {} exchange rate from {}: {}", currencyCode, BITCOINAVERAGE_URL, x.getMessage());
                        }
                    }
                }
            }
            watch.stop();
            log.info("fetched exchange rates from {}, {} chars, took {}", BITCOINAVERAGE_URL, content.length(), watch);
            return rates;
        } else {
            log.warn("http status {} when fetching exchange rates from {}", response.code(), BITCOINAVERAGE_URL);
        }
    } catch (final Exception x) {
        log.warn("problem fetching exchange rates from " + BITCOINAVERAGE_URL, x);
    }
    return null;
}
Also used : Call(okhttp3.Call) Stopwatch(com.google.common.base.Stopwatch) Request(okhttp3.Request) TreeMap(java.util.TreeMap) Response(okhttp3.Response) JSONObject(org.json.JSONObject) Fiat(org.bitcoinj.utils.Fiat)

Example 52 with Call

use of zipkin2.Call in project instructure-android by instructure.

the class QuizSubmissionQuestionListRecyclerAdapter method bindTheHolder.

public void bindTheHolder(final QuizSubmissionQuestion baseItem, RecyclerView.ViewHolder holder, int position) {
    int courseColor = ColorKeeper.getOrGenerateColor(canvasContext);
    if (position == super.getItemCount()) {
        // submit button
        SubmitButtonBinder.bind((SubmitButtonViewHolder) holder, getContext(), canvasContext, QuizSubmissionQuestionListRecyclerAdapter.this, new QuizSubmit() {

            @Override
            public void submitQuiz() {
                QuizManager.postQuizSubmit(canvasContext, quizSubmission, true, new StatusCallback<QuizSubmissionResponse>() {

                    @Override
                    public void onResponse(@NonNull Response<QuizSubmissionResponse> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
                        if (type == ApiType.CACHE)
                            return;
                        // Submitted!
                        Toast.makeText(getContext(), R.string.quizSubmittedSuccessfully, Toast.LENGTH_SHORT).show();
                        // Go back to the startQuizFragment
                        ((Activity) getContext()).onBackPressed();
                        Fragment fragment = ((NavigationActivity) getContext()).getTopFragment();
                        if (fragment instanceof QuizStartFragment) {
                            ((QuizStartFragment) fragment).updateQuizInfo();
                        }
                    }

                    @Override
                    public void onFail(@Nullable Call<QuizSubmissionResponse> call, @NonNull Throwable error, @Nullable Response response) {
                        Toast.makeText(getContext(), R.string.quizSubmittedFailure, Toast.LENGTH_SHORT).show();
                    }
                });
            }
        });
        return;
    }
    switch(baseItem.getQuestionType()) {
        case ESSAY:
        case SHORT_ANSWER:
            addEssayQuestion(baseItem, (QuizEssayViewHolder) holder, position, courseColor);
            break;
        case MUTIPLE_CHOICE:
        case TRUE_FALSE:
            addMultipleChoiceQuestion(baseItem, (QuizMultiChoiceViewHolder) holder, position, courseColor);
            break;
        case TEXT_ONLY:
            QuizTextOnlyBinder.bind((QuizTextOnlyViewHolder) holder, baseItem);
            break;
        case MULTIPLE_ANSWERS:
            addMultipleAnswerQuestion((QuizMultiChoiceViewHolder) holder, position, courseColor);
            break;
        case MATCHING:
            addMatchingQuestion(baseItem, (QuizMatchingViewHolder) holder, position, courseColor);
            break;
        case FILE_UPLOAD:
            addFileUploadQuestion(baseItem, (QuizFileUploadViewHolder) holder, position, courseColor);
            break;
        case NUMERICAL:
            addNumericalQuestion(baseItem, (QuizNumericalViewHolder) holder, position, courseColor);
            break;
        case MULTIPLE_DROPDOWNS:
            addMultipleDropdown(baseItem, (QuizMultipleDropdownViewHolder) holder, position, courseColor);
            break;
    }
}
Also used : Call(retrofit2.Call) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) FragmentActivity(android.support.v4.app.FragmentActivity) NavigationActivity(com.instructure.candroid.activity.NavigationActivity) Activity(android.app.Activity) StatusCallback(com.instructure.canvasapi2.StatusCallback) Fragment(android.support.v4.app.Fragment) InternalWebviewFragment(com.instructure.candroid.fragment.InternalWebviewFragment) QuizStartFragment(com.instructure.candroid.fragment.QuizStartFragment) QuizStartFragment(com.instructure.candroid.fragment.QuizStartFragment) QuizSubmissionResponse(com.instructure.canvasapi2.models.QuizSubmissionResponse) Response(retrofit2.Response) QuizSubmissionQuestionResponse(com.instructure.canvasapi2.models.QuizSubmissionQuestionResponse) QuizSubmit(com.instructure.candroid.interfaces.QuizSubmit) NonNull(android.support.annotation.NonNull) ApiType(com.instructure.canvasapi2.utils.ApiType) NavigationActivity(com.instructure.candroid.activity.NavigationActivity) Nullable(android.support.annotation.Nullable)

Example 53 with Call

use of zipkin2.Call in project EhViewer by seven332.

the class EhEngine method getArchiveList.

public static Pair<String, Pair<String, String>[]> getArchiveList(@Nullable EhClient.Task task, OkHttpClient okHttpClient, String url) throws Exception {
    Log.d(TAG, url);
    Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
    Call call = okHttpClient.newCall(request);
    // Put call
    if (null != task) {
        task.setCall(call);
    }
    String body = null;
    Headers headers = null;
    Pair<String, Pair<String, String>[]> result;
    int code = -1;
    try {
        Response response = call.execute();
        code = response.code();
        headers = response.headers();
        body = response.body().string();
        result = ArchiveParser.parse(body);
    } catch (Exception e) {
        throwException(call, code, headers, body, e);
        throw e;
    }
    return result;
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Headers(okhttp3.Headers) Request(okhttp3.Request) EhException(com.hippo.ehviewer.client.exception.EhException) ParseException(com.hippo.ehviewer.client.exception.ParseException) CancelledException(com.hippo.ehviewer.client.exception.CancelledException) NoHAtHClientException(com.hippo.ehviewer.client.exception.NoHAtHClientException) StatusCodeException(com.hippo.network.StatusCodeException)

Example 54 with Call

use of zipkin2.Call in project baseio by generallycloud.

the class TestOkHttp method test2.

static void test2() throws Exception {
    OkHttpClient client = new OkHttpClient();
    String url = "https://localhost:443/test";
    url = "https://www.baidu.com";
    Request request = new Request.Builder().url(url).get().build();
    Call call = client.newCall(request);
    Response response = call.execute();
    if (response.isSuccessful()) {
        String result = response.body().string();
        System.out.println(result);
    }
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request)

Example 55 with Call

use of zipkin2.Call in project brave by openzipkin.

the class ITHttp method takeSpan.

/**
 * Call this to block until a span was reported
 */
protected Span takeSpan() throws InterruptedException {
    Span result = spans.take();
    assertThat(result.annotations()).extracting(Annotation::value).doesNotContain(CONTEXT_LEAK);
    return result;
}
Also used : Span(zipkin2.Span)

Aggregations

Call (okhttp3.Call)409 Response (okhttp3.Response)309 Request (okhttp3.Request)282 IOException (java.io.IOException)232 Call (retrofit2.Call)134 Callback (okhttp3.Callback)133 OkHttpClient (okhttp3.OkHttpClient)98 Test (org.junit.Test)88 ResponseBody (okhttp3.ResponseBody)76 RequestBody (okhttp3.RequestBody)58 Retrofit (retrofit2.Retrofit)48 Gson (com.google.gson.Gson)47 Response (retrofit2.Response)47 File (java.io.File)44 Headers (okhttp3.Headers)41 Callback (retrofit2.Callback)41 GsonBuilder (com.google.gson.GsonBuilder)40 JSONObject (org.json.JSONObject)39 MockResponse (okhttp3.mockwebserver.MockResponse)38 List (java.util.List)35