Search in sources :

Example 21 with ApiCallException

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;
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) HashMap(java.util.HashMap) ApiCallException(com.odysee.app.exceptions.ApiCallException) DecimalFormat(java.text.DecimalFormat) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) Claim(com.odysee.app.model.Claim)

Example 22 with ApiCallException

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;
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) ApiCallException(com.odysee.app.exceptions.ApiCallException) LbryFile(com.odysee.app.model.LbryFile) JSONObject(org.json.JSONObject)

Example 23 with ApiCallException

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;
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) ApiCallException(com.odysee.app.exceptions.ApiCallException) LbryioRequestException(com.odysee.app.exceptions.LbryioRequestException) JSONException(org.json.JSONException) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException)

Example 24 with ApiCallException

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;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ApiCallException(com.odysee.app.exceptions.ApiCallException) JSONObject(org.json.JSONObject) LbryResponseException(com.odysee.app.exceptions.LbryResponseException) LbryRequestException(com.odysee.app.exceptions.LbryRequestException)

Example 25 with ApiCallException

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;
}
Also used : ClaimCacheKey(com.odysee.app.model.ClaimCacheKey) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ApiCallException(com.odysee.app.exceptions.ApiCallException) LbryFile(com.odysee.app.model.LbryFile) JSONObject(org.json.JSONObject) LbryResponseException(com.odysee.app.exceptions.LbryResponseException) LbryRequestException(com.odysee.app.exceptions.LbryRequestException)

Aggregations

ApiCallException (com.odysee.app.exceptions.ApiCallException)31 JSONObject (org.json.JSONObject)28 HashMap (java.util.HashMap)22 JSONException (org.json.JSONException)17 Claim (com.odysee.app.model.Claim)10 JSONArray (org.json.JSONArray)10 ArrayList (java.util.ArrayList)8 LbryRequestException (com.odysee.app.exceptions.LbryRequestException)7 LbryResponseException (com.odysee.app.exceptions.LbryResponseException)7 MainActivity (com.odysee.app.MainActivity)6 DecimalFormat (java.text.DecimalFormat)5 DecimalFormatSymbols (java.text.DecimalFormatSymbols)5 LinkedHashMap (java.util.LinkedHashMap)5 ExecutorService (java.util.concurrent.ExecutorService)5 AccountManager (android.accounts.AccountManager)4 Response (okhttp3.Response)4 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 View (android.view.View)3 TextView (android.widget.TextView)3 Subscription (com.odysee.app.model.lbryinc.Subscription)3