use of com.odysee.app.exceptions.ApiCallException in project odysee-android by OdyseeTeam.
the class StreamRepostTask method doInBackground.
protected Claim doInBackground(Void... params) {
Claim claimResult = null;
try {
Map<String, Object> options = new HashMap<>();
options.put("name", name);
options.put("bid", new DecimalFormat(Helper.SDK_AMOUNT_FORMAT, new DecimalFormatSymbols(Locale.US)).format(bid.doubleValue()));
options.put("claim_id", claimId);
options.put("channel_id", channelId);
JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_STREAM_REPOST, options);
if (result.has("outputs")) {
JSONArray outputs = result.getJSONArray("outputs");
for (int i = 0; i < outputs.length(); i++) {
JSONObject output = outputs.getJSONObject(i);
if (output.has("claim_id") && output.has("claim_op")) {
claimResult = Claim.claimFromOutput(output);
break;
}
}
}
} catch (ApiCallException | ClassCastException | JSONException ex) {
error = ex;
}
return claimResult;
}
use of com.odysee.app.exceptions.ApiCallException in project odysee-android by OdyseeTeam.
the class GetFileTask method doInBackground.
protected LbryFile doInBackground(Void... params) {
LbryFile file = null;
try {
Map<String, Object> options = new HashMap<>();
options.put("uri", uri);
options.put("save_file", saveFile);
JSONObject streamInfo = (JSONObject) Lbry.genericApiCall("get", options);
if (streamInfo.has("error")) {
throw new ApiCallException(Helper.getJSONString("error", "", streamInfo));
}
file = LbryFile.fromJSONObject(streamInfo);
} catch (ApiCallException ex) {
error = ex;
}
return file;
}
use of com.odysee.app.exceptions.ApiCallException in project odysee-android by OdyseeTeam.
the class ClaimRewardTask method doInBackground.
public String doInBackground(Void... params) {
String message = null;
try {
String txid = null;
if (Reward.TYPE_FIRST_CHANNEL.equalsIgnoreCase(type)) {
// fetch a channel
txid = fetchSingleClaimTxid(Claim.TYPE_CHANNEL);
} else if (Reward.TYPE_FIRST_PUBLISH.equalsIgnoreCase(type)) {
// fetch a publish
txid = fetchSingleClaimTxid(Claim.TYPE_STREAM);
}
// Get a new wallet address for the reward
String address = (String) Lbry.genericApiCall(Lbry.METHOD_ADDRESS_UNUSED, authToken);
Map<String, String> options = new HashMap<>();
options.put("reward_type", type);
options.put("wallet_address", address);
if (!Helper.isNullOrEmpty(rewardCode)) {
options.put("code", rewardCode);
}
if (!Helper.isNullOrEmpty(txid)) {
options.put("transaction_id", txid);
}
if (authToken != null) {
options.put("auth_token", authToken);
}
JSONObject reward = (JSONObject) Lbryio.parseResponse(Lbryio.call("reward", "claim", options, Helper.METHOD_POST, null));
if (reward != null) {
amountClaimed = Helper.getJSONDouble("reward_amount", 0, reward);
message = Helper.getJSONString("reward_notification", "", reward);
}
} catch (ApiCallException | JSONException | LbryioRequestException | LbryioResponseException ex) {
error = ex;
}
return message;
}
use of com.odysee.app.exceptions.ApiCallException in project odysee-android by OdyseeTeam.
the class Lbry method directApiCall.
public static Object directApiCall(String method, String authToken) throws ApiCallException {
Map<String, Object> params = new HashMap<>();
params.put("auth_token", authToken);
Object response = null;
try {
response = parseResponse(apiCall(method, params, 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 get.
public static LbryFile get(boolean saveFile) throws ApiCallException {
LbryFile file = null;
Map<String, Object> params = new HashMap<>();
params.put("save_file", saveFile);
try {
JSONObject result = (JSONObject) parseResponse(apiCall(METHOD_GET, params));
file = LbryFile.fromJSONObject(result);
if (file != null) {
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 ex) {
throw new ApiCallException("Could not execute resolve call", ex);
}
return file;
}
Aggregations