package com.joinmarrow.marrow.tasks; import android.os.AsyncTask; import android.util.Log; import android.widget.ArrayAdapter; import android.widget.ListView; import com.joinmarrow.marrow.R; import org.jdeferred.Deferred; import java.io.IOException; import us.monoid.json.JSONArray; import us.monoid.json.JSONException; import us.monoid.json.JSONObject; import us.monoid.web.Resty; /** * Created by edwlan on 4/6/15. */ public class GetSubscriptions extends AsyncTask<Void, Void, JSONObject> { Deferred<JSONArray, Void, Void> taskDeferred; private String endpoint; public GetSubscriptions(Deferred d, String url) { taskDeferred = d; endpoint = url.concat("/api/bones/subscriptions"); } @Override protected JSONObject doInBackground(Void... loginData) { JSONObject result = new JSONObject(); try { result = new Resty().json(endpoint).toObject(); } catch (IOException | JSONException e) { Log.e("marrow", e.getMessage()); } finally { Log.i("marrow", result.toString()); } return result; } @Override protected void onPostExecute(JSONObject result) { JSONArray data = new JSONArray(); try { data = result.getJSONArray("marrow"); } catch (JSONException e) { Log.i("marrow", "unexpected JSONException"); e.printStackTrace(); Log.d("marrow", result.toString()); } taskDeferred.resolve(data); } }