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);
}
});
}
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);
}
});
}
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);
}
});
}
Aggregations