use of com.loopj.android.http.JsonHttpResponseHandler in project app by TourLive.
the class APIClient method getJudgments.
public static String getJudgments(String url, RequestParams params) {
final String[] messages = { "success" };
APIClient.get(url, null, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject data) {
try {
Parser.parseJudgmentsAndPersist(data.getJSONObject("data").getJSONArray("judgements"), stageNr);
messages[0] = "success";
} catch (Exception ex) {
messages[0] = ex.getMessage();
}
}
@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray riders) {
// Not needed and therefore not implemented
}
@Override
public void onFailure(int error, Header[] headers, Throwable throwable, JSONObject riders) {
if (throwable.getMessage().equals(throwableType)) {
messages[0] = readTimeOutMessage + throwable.getMessage();
} else {
messages[0] = throwable.getMessage();
}
}
});
return messages[0];
}
use of com.loopj.android.http.JsonHttpResponseHandler in project app by TourLive.
the class APIClient method getStages.
public static String getStages(String url, RequestParams params) {
final String[] messages = { "success" };
APIClient.get(url, null, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject data) {
// Not needed and therefore not implemented
}
@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray stages) {
try {
for (int i = 0; i < stages.length(); i++) {
JSONObject stage = stages.getJSONObject(i);
if (stage.getInt("stageId") == Integer.valueOf(stageId)) {
// gets the second last stage, cause of data leak on API
stageNr = i;
}
}
Parser.parseStagesAndPersist(stages, stageNr);
messages[0] = "success";
} catch (Exception ex) {
messages[0] = ex.getMessage();
}
}
@Override
public void onFailure(int error, Header[] headers, Throwable throwable, JSONObject riders) {
if (throwable.getMessage().equals(throwableType)) {
messages[0] = readTimeOutMessage + throwable.getMessage();
} else {
messages[0] = throwable.getMessage();
}
}
});
return messages[0];
}
use of com.loopj.android.http.JsonHttpResponseHandler in project app by TourLive.
the class APIClient method getMaillots.
public static String getMaillots(String url, RequestParams params) {
final String[] messages = { "success" };
APIClient.get(url, null, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject data) {
// Not needed and therefore not implemented
}
@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray maillots) {
try {
Parser.parseMaillotsAndPersist(maillots);
messages[0] = "success";
} catch (Exception ex) {
messages[0] = ex.getMessage();
}
}
@Override
public void onFailure(int error, Header[] headers, Throwable throwable, JSONObject riders) {
if (throwable.getMessage().equals(throwableType)) {
messages[0] = readTimeOutMessage + throwable.getMessage();
} else {
messages[0] = throwable.getMessage();
}
}
});
return messages[0];
}
use of com.loopj.android.http.JsonHttpResponseHandler in project app by TourLive.
the class APIClient method postToAPI.
public static void postToAPI(String url, RequestParams params) {
if (Looper.myLooper() == null)
Looper.prepare();
uiHandler = new Handler();
APIClient.post(url, null, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject data) {
try {
uiHandler.post(() -> {
new String("successfully");
});
} catch (Exception ex) {
uiHandler.post(ex::getMessage);
}
}
@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray data) {
try {
// Not needed
} catch (Exception ex) {
uiHandler.post(ex::getMessage);
}
}
@Override
public void onFailure(int error, Header[] headers, Throwable throwable, JSONObject riders) {
uiHandler.post(throwable::getMessage);
}
});
}
use of com.loopj.android.http.JsonHttpResponseHandler in project app by TourLive.
the class APIClient method getActualRaceId.
public static String getActualRaceId(String url, RequestParams params) {
final String[] messages = { "success" };
APIClient.get(url, null, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject data) {
// Not needed and therefore not implemented
}
@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray settings) {
try {
stageId = settings.getJSONObject(0).getString("parameter");
raceId = settings.getJSONObject(1).getString("parameter");
messages[0] = "success";
} catch (JSONException ex) {
messages[0] = ex.getMessage();
}
}
@Override
public void onFailure(int error, Header[] headers, Throwable throwable, JSONObject riders) {
if (throwable.getMessage().equals(throwableType)) {
messages[0] = readTimeOutMessage + throwable.getMessage();
} else {
messages[0] = throwable.getMessage();
}
}
});
return messages[0];
}
Aggregations