Search in sources :

Example 1 with JSONRequestCallback

use of oscar.riksdagskollen.Utilities.Callbacks.JSONRequestCallback in project Riksdagskollen by OAndell.

the class RiksdagenAPIManager method getRepresentative.

/**
 * Get representative(ledamot) information by intressent_id.
 * @param iid intressent_id for the representative
 * @param callback callback function which the a Representative JSON model is returned.
 */
public void getRepresentative(String iid, final RepresentativeCallback callback) {
    String subURL = "/personlista/?iid=" + iid + "&utformat=json";
    requestManager.doGetRequest(subURL, new JSONRequestCallback() {

        @Override
        public void onRequestSuccess(JSONObject response) {
            try {
                JSONObject jsonDocuments = response.getJSONObject("personlista").getJSONObject("person");
                Representative representative = gson.fromJson(jsonDocuments.toString(), Representative.class);
                callback.onPersonFetched(representative);
            } catch (JSONException e) {
                e.printStackTrace();
                callback.onFail(new VolleyError("Failed to parse JSON"));
            }
        }

        @Override
        public void onRequestFail(VolleyError error) {
            callback.onFail(error);
        }
    });
}
Also used : VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) JSONRequestCallback(oscar.riksdagskollen.Utilities.Callbacks.JSONRequestCallback) JSONException(org.json.JSONException) Representative(oscar.riksdagskollen.Utilities.JSONModels.Representative)

Example 2 with JSONRequestCallback

use of oscar.riksdagskollen.Utilities.Callbacks.JSONRequestCallback in project Riksdagskollen by OAndell.

the class RiksdagenAPIManager method getDocumentsForParty.

public void getDocumentsForParty(Party party, int page, final PartyDocumentCallback callback) {
    String subURL = "/dokumentlista/?avd=dokument&del=dokument&fcs=1&sort=datum&sortorder=desc&utformat=json" + "&parti=" + party.getID() + "&p=" + page;
    requestManager.doGetRequest(subURL, new JSONRequestCallback() {

        @Override
        public void onRequestSuccess(JSONObject response) {
            try {
                JSONArray jsonDocuments = response.getJSONObject("dokumentlista").getJSONArray("dokument");
                PartyDocument[] documents = gson.fromJson(jsonDocuments.toString(), PartyDocument[].class);
                callback.onDocumentsFetched(Arrays.asList(documents));
            } catch (JSONException e) {
                e.printStackTrace();
                callback.onFail(new VolleyError("Failed to parse JSON"));
            }
        }

        @Override
        public void onRequestFail(VolleyError error) {
            callback.onFail(error);
        }
    });
}
Also used : VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) JSONRequestCallback(oscar.riksdagskollen.Utilities.Callbacks.JSONRequestCallback) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Example 3 with JSONRequestCallback

use of oscar.riksdagskollen.Utilities.Callbacks.JSONRequestCallback in project Riksdagskollen by OAndell.

the class RiksdagenAPIManager method getCurrentNews.

/**
 * Get the current news (Aktuellt)
 * @param callback callback which a List of currentNews is returned
 */
public void getCurrentNews(final CurrentNewsCallback callback) {
    String subURL = "/dokumentlista/?avd=aktuellt&sort=datum&sortorder=desc&lang=sv&cmskategori=startsida&utformat=json&p=1";
    requestManager.doGetRequest(subURL, new JSONRequestCallback() {

        @Override
        public void onRequestSuccess(JSONObject response) {
            try {
                JSONArray jsonDocuments = response.getJSONObject("dokumentlista").getJSONArray("dokument");
                CurrentNews[] news = gson.fromJson(jsonDocuments.toString(), CurrentNews[].class);
                callback.onNewsFetched(Arrays.asList(news));
            } catch (JSONException e) {
                e.printStackTrace();
                callback.onFail(new VolleyError("Failed to parse JSON"));
            }
        }

        @Override
        public void onRequestFail(VolleyError error) {
            callback.onFail(error);
        }
    });
}
Also used : VolleyError(com.android.volley.VolleyError) JSONObject(org.json.JSONObject) JSONRequestCallback(oscar.riksdagskollen.Utilities.Callbacks.JSONRequestCallback) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Aggregations

VolleyError (com.android.volley.VolleyError)3 JSONException (org.json.JSONException)3 JSONObject (org.json.JSONObject)3 JSONRequestCallback (oscar.riksdagskollen.Utilities.Callbacks.JSONRequestCallback)3 JSONArray (org.json.JSONArray)2 Representative (oscar.riksdagskollen.Utilities.JSONModels.Representative)1