use of com.squareup.okhttp.Response in project pictureapp by EyeSeeTea.
the class BasicAuthenticator method pullOrgUnitsNotBannedCodes.
/**
* This method returns a String[] whit the Organitation codes
*/
public static String[] pullOrgUnitsNotBannedCodes(String url) {
try {
String orgUnitsURL = getDhisOrgUnitsURL(url);
Response response = executeCall(null, orgUnitsURL, "GET");
//Error -> null
if (!response.isSuccessful()) {
Log.e(TAG, "pullOrgUnitsCodes (" + response.code() + "): " + response.body().string());
throw new IOException(response.message());
}
//{"organisationUnits":[{}]}
JSONArray orgUnitsArray = parseResponse(response.body().string()).getJSONArray(TAG_ORGANISATIONUNITS);
//0 matches -> Error
if (orgUnitsArray.length() == 0) {
throw new Exception("Found 0 matches");
}
return Utils.jsonArrayToStringArray(orgUnitsArray, TAG_ID);
} catch (Exception ex) {
Log.e(TAG, String.format("pullOrgUnitsCodes(%url): %s", url, ex.getMessage()));
String[] value = new String[1];
value[0] = "";
return value;
}
}
use of com.squareup.okhttp.Response in project pictureapp by EyeSeeTea.
the class BasicAuthenticator method patchDescriptionClosedDate.
static void patchDescriptionClosedDate(String url, String orgUnitUID, String orgUnitDescription) {
//https://malariacare.psi.org/api/organisationUnits/u5jlxuod8xQ/closedDate
try {
String urlPathClosedDescription = getPatchClosedDescriptionUrl(url, orgUnitUID);
JSONObject data = prepareClosingDescriptionValue(orgUnitDescription);
Response response = executeCall(data, urlPathClosedDescription, "PATCH");
if (!response.isSuccessful()) {
Log.e(TAG, "patchDescriptionClosedDate (" + response.code() + "): " + response.body().string());
throw new IOException(response.message());
}
} catch (Exception e) {
Log.e(TAG, String.format("patchDescriptionClosedDate(%s,%s): %s", url, orgUnitUID, e.getMessage()));
}
}
use of com.squareup.okhttp.Response in project pictureapp by EyeSeeTea.
the class BasicAuthenticator method isValidProgram.
/**
* Returns if the given url contains the current program
*/
public static boolean isValidProgram(String url) {
Log.d(TAG, String.format("isValidProgram(%s) ...", url));
String programUIDInServer;
try {
String urlValidProgram = getIsValidProgramUrl(url);
Response response = executeCall(null, urlValidProgram, "GET");
//Error -> null
if (!response.isSuccessful()) {
Log.e(TAG, "isValidProgram (" + response.code() + "): " + response.body().string());
throw new IOException(response.message());
}
JSONObject data = parseResponse(response.body().string());
programUIDInServer = String.valueOf(data.get(TAG_ID));
} catch (Exception ex) {
Log.e(TAG, "isValidProgram: " + ex.toString());
return false;
}
boolean valid = getProgramUID() != null && getProgramUID().equals(programUIDInServer);
Log.d(TAG, String.format("isValidProgram(%s) -> %b (Thread: %d)", url, valid, Thread.currentThread().getId()));
return valid;
}
use of com.squareup.okhttp.Response in project PocketHub by pockethub.
the class RawCommentFragment method onActivityResult.
@Override
public void onActivityResult(final int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_SELECT_PHOTO && resultCode == Activity.RESULT_OK) {
showProgressIndeterminate(R.string.loading);
ImageBinPoster.post(getActivity(), data.getData(), new Callback() {
@Override
public void onFailure(Request request, IOException e) {
dismissProgress();
showImageError();
}
@Override
public void onResponse(Response response) throws IOException {
dismissProgress();
if (response.isSuccessful()) {
insertImage(ImageBinPoster.getUrl(response.body().string()));
} else {
showImageError();
}
}
});
}
}
use of com.squareup.okhttp.Response in project openzaly by akaxincom.
the class ZalyHttpClient method get.
public byte[] get(String url) throws Exception {
Request request = new Request.Builder().url(url).build();
Response response = httpClient.newCall(request).execute();
if (response.isSuccessful()) {
return response.body().bytes();
} else {
logger.error("http get url={} error.{}", url, response.message());
}
return null;
}
Aggregations