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;
}
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;
}
}
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;
}
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);
}
}
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;
}
Aggregations