Search in sources :

Example 31 with ApiCallException

use of com.odysee.app.exceptions.ApiCallException in project odysee-android by OdyseeTeam.

the class ChannelCreateUpdateTask method doInBackground.

protected Claim doInBackground(Void... params) {
    Map<String, Object> options = new HashMap<>();
    if (!update) {
        options.put("name", claim.getName());
    } else {
        options.put("claim_id", claim.getClaimId());
    }
    options.put("bid", new DecimalFormat(Helper.SDK_AMOUNT_FORMAT, new DecimalFormatSymbols(Locale.US)).format(deposit.doubleValue()));
    if (!Helper.isNullOrEmpty(claim.getTitle())) {
        options.put("title", claim.getTitle());
    }
    if (!Helper.isNullOrEmpty(claim.getCoverUrl())) {
        options.put("cover_url", claim.getCoverUrl());
    }
    if (!Helper.isNullOrEmpty(claim.getThumbnailUrl())) {
        options.put("thumbnail_url", claim.getThumbnailUrl());
    }
    if (!Helper.isNullOrEmpty(claim.getDescription())) {
        options.put("description", claim.getDescription());
    }
    if (!Helper.isNullOrEmpty(claim.getWebsiteUrl())) {
        options.put("website_url", claim.getWebsiteUrl());
    }
    if (!Helper.isNullOrEmpty(claim.getEmail())) {
        options.put("email", claim.getEmail());
    }
    if (claim.getTags() != null && claim.getTags().size() > 0) {
        options.put("tags", claim.getTags());
    }
    options.put("blocking", true);
    Claim claimResult = null;
    String method = !update ? Lbry.METHOD_CHANNEL_CREATE : Lbry.METHOD_CHANNEL_UPDATE;
    try {
        JSONObject result = (JSONObject) Lbry.authenticatedGenericApiCall(method, options, authToken);
        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)

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