use of com.odysee.app.exceptions.ApiCallException in project odysee-android by OdyseeTeam.
the class Comments method checkCommentsEndpointStatus.
public static void checkCommentsEndpointStatus() throws IOException, JSONException, ApiCallException {
Request request = new Request.Builder().url(STATUS_ENDPOINT).build();
OkHttpClient client = new OkHttpClient.Builder().writeTimeout(30, TimeUnit.SECONDS).readTimeout(30, TimeUnit.SECONDS).build();
Response response = client.newCall(request).execute();
JSONObject status = new JSONObject(Objects.requireNonNull(response.body()).string());
String statusText = Helper.getJSONString("text", null, status);
boolean isRunning = Helper.getJSONBoolean("is_running", false, status);
if (!"ok".equalsIgnoreCase(statusText) || !isRunning) {
throw new ApiCallException("The comment server is not available at this time. Please try again later.");
}
}
use of com.odysee.app.exceptions.ApiCallException in project odysee-android by OdyseeTeam.
the class Lbry method directApiCall.
/**
* @deprecated Use authenticatedGenericApiCall(String, Map, String) instead
* @param method
* @param p
* @param authToken
* @return
* @throws ApiCallException
*/
@Deprecated
public static Object directApiCall(String method, Map<String, Object> p, String authToken) throws ApiCallException {
p.put("auth_token", authToken);
Object response = null;
try {
response = parseResponse(apiCall(method, p, API_CONNECTION_STRING));
} catch (LbryRequestException | LbryResponseException ex) {
throw new ApiCallException(String.format("Could not execute %s call: %s", method, ex.getMessage()), ex);
}
return response;
}
use of com.odysee.app.exceptions.ApiCallException in project odysee-android by OdyseeTeam.
the class Lbry method fileList.
public static List<LbryFile> fileList(String claimId, boolean downloads, int page, int pageSize) throws ApiCallException {
List<LbryFile> files = new ArrayList<>();
Map<String, Object> params = new HashMap<>();
if (!Helper.isNullOrEmpty(claimId)) {
params.put("claim_id", claimId);
}
if (downloads) {
params.put("download_path", null);
params.put("comparison", "ne");
}
if (page > 0) {
params.put("page", page);
}
if (pageSize > 0) {
params.put("page_size", pageSize);
}
try {
JSONObject result = (JSONObject) parseResponse(apiCall(METHOD_FILE_LIST, params));
JSONArray items = result.getJSONArray("items");
for (int i = 0; i < items.length(); i++) {
JSONObject fileObject = items.getJSONObject(i);
LbryFile file = LbryFile.fromJSONObject(fileObject);
files.add(file);
String fileClaimId = file.getClaimId();
if (!Helper.isNullOrEmpty(fileClaimId)) {
ClaimCacheKey key = new ClaimCacheKey();
key.setClaimId(fileClaimId);
if (claimCache.containsKey(key)) {
claimCache.get(key).setFile(file);
}
}
}
} catch (LbryRequestException | LbryResponseException | JSONException ex) {
throw new ApiCallException("Could not execute resolve call", ex);
}
return files;
}
use of com.odysee.app.exceptions.ApiCallException in project odysee-android by OdyseeTeam.
the class MainActivity method unlockTips.
public void unlockTips() {
if (unlockingTips) {
return;
}
Map<String, Object> options = new HashMap<>();
options.put("type", "support");
options.put("is_not_my_input", true);
options.put("blocking", true);
AccountManager am = AccountManager.get(getApplicationContext());
String authToken = am.peekAuthToken(am.getAccounts()[0], "auth_token_type");
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
unlockingTips = true;
Supplier<Boolean> task = new UnlockingTipsSupplier(options, authToken);
CompletableFuture<Boolean> completableFuture = CompletableFuture.supplyAsync(task);
completableFuture.thenAccept(result -> {
unlockingTips = false;
});
} else {
Thread unlockingThread = new Thread(new Runnable() {
@Override
public void run() {
Callable<Boolean> callable = () -> {
try {
Lbry.directApiCall(Lbry.METHOD_TXO_SPEND, options, authToken);
return true;
} catch (ApiCallException | ClassCastException ex) {
ex.printStackTrace();
return false;
}
};
ExecutorService executorService = Executors.newSingleThreadExecutor();
Future<Boolean> future = executorService.submit(callable);
try {
unlockingTips = true;
// This doesn't block main thread as it is called from a different thread
future.get();
unlockingTips = false;
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
});
unlockingThread.start();
}
}
use of com.odysee.app.exceptions.ApiCallException in project odysee-android by OdyseeTeam.
the class CommentCreateTask method doInBackground.
public Comment doInBackground(Void... params) {
Comment createdComment = null;
ResponseBody responseBody = null;
try {
// check comments status endpoint
Comments.checkCommentsEndpointStatus();
JSONObject comment_body = new JSONObject();
comment_body.put("comment", comment.getText());
comment_body.put("claim_id", comment.getClaimId());
if (!Helper.isNullOrEmpty(comment.getParentId())) {
comment_body.put("parent_id", comment.getParentId());
}
comment_body.put("channel_id", comment.getChannelId());
comment_body.put("channel_name", comment.getChannelName());
if (authToken != null) {
comment_body.put("auth_token", authToken);
}
JSONObject jsonChannelSign = Comments.channelSignWithCommentData(comment_body, comment, comment.getText());
if (jsonChannelSign.has("signature") && jsonChannelSign.has("signing_ts")) {
comment_body.put("signature", jsonChannelSign.getString("signature"));
comment_body.put("signing_ts", jsonChannelSign.getString("signing_ts"));
}
Response resp = Comments.performRequest(comment_body, "comment.Create");
responseBody = resp.body();
if (responseBody != null) {
String responseString = responseBody.string();
resp.close();
JSONObject jsonResponse = new JSONObject(responseString);
if (jsonResponse.has("result"))
createdComment = Comment.fromJSONObject(jsonResponse.getJSONObject("result"));
}
} catch (ApiCallException | ClassCastException | IOException | JSONException ex) {
error = ex;
} finally {
if (responseBody != null) {
responseBody.close();
}
}
return createdComment;
}
Aggregations