use of com.nextcloud.operations.PutMethod in project android-library by nextcloud.
the class SetUserDefinedCustomStatusMessageRemoteOperation method run.
/**
* @param client Client object
*/
@Override
public RemoteOperationResult run(NextcloudClient client) {
PutMethod putMethod = null;
RemoteOperationResult result;
try {
// request body
MediaType json = MediaType.parse("application/json; charset=utf-8");
RequestBody requestBody = RequestBody.create(json, "{\"message\": \"" + message + "\", " + "\"statusIcon\": \"" + statusIcon + "\", " + "\"clearAt\": " + clearAt + "}");
// remote request
putMethod = new PutMethod(client.getBaseUri() + SET_STATUS_URL, true, requestBody);
int status = client.execute(putMethod);
if (status == HttpStatus.SC_OK) {
result = new RemoteOperationResult(true, putMethod);
} else {
result = new RemoteOperationResult(false, putMethod);
putMethod.releaseConnection();
}
} catch (Exception e) {
result = new RemoteOperationResult(e);
Log_OC.e(TAG, "Setting of predefined custom status failed: " + result.getLogMessage(), result.getException());
} finally {
if (putMethod != null) {
putMethod.releaseConnection();
}
}
return result;
}
use of com.nextcloud.operations.PutMethod in project android-library by nextcloud.
the class SetUserInfoRemoteOperation method run.
@Override
public RemoteOperationResult<Boolean> run(NextcloudClient client) {
RemoteOperationResult<Boolean> result;
PutMethod method = null;
try {
// request body
MediaType json = MediaType.parse("application/json; charset=utf-8");
RequestBody requestBody = RequestBody.create(json, "{\"key\": \"" + field.getFieldName() + "\"" + ", \"value\": \"" + value + "\"}");
// remote request
method = new PutMethod(client.getBaseUri() + OCS_ROUTE_PATH + client.getUserId(), true, requestBody);
int status = client.execute(method);
if (status == HttpStatus.SC_OK) {
result = new RemoteOperationResult<>(true, method);
} else {
result = new RemoteOperationResult<>(false, method);
String response = method.getResponseBodyAsString();
Log_OC.e(TAG, "Failed response while setting user information");
Log_OC.e(TAG, "*** status code: " + status + "; response: " + response);
}
} catch (Exception e) {
result = new RemoteOperationResult<>(e);
Log_OC.e(TAG, "Exception while setting OC user information", e);
} finally {
if (method != null)
method.releaseConnection();
}
return result;
}
use of com.nextcloud.operations.PutMethod in project android-library by nextcloud.
the class SetPredefinedCustomStatusMessageRemoteOperation method run.
/**
* @param client Client object
*/
@Override
public RemoteOperationResult<ArrayList<PredefinedStatus>> run(NextcloudClient client) {
PutMethod putMethod = null;
RemoteOperationResult<ArrayList<PredefinedStatus>> result;
try {
// request body
MediaType json = MediaType.parse("application/json; charset=utf-8");
RequestBody requestBody = RequestBody.create(json, "{\"messageId\": \"" + messageId + "\", " + "\"clearAt\": " + clearAt + "}");
// remote request
putMethod = new PutMethod(client.getBaseUri() + SET_STATUS_URL, true, requestBody);
int status = client.execute(putMethod);
if (status == HttpStatus.SC_OK) {
result = new RemoteOperationResult<>(true, putMethod);
} else {
result = new RemoteOperationResult<>(false, putMethod);
putMethod.releaseConnection();
}
} catch (Exception e) {
result = new RemoteOperationResult<>(e);
Log_OC.e(TAG, "Setting of predefined custom status failed: " + result.getLogMessage(), result.getException());
} finally {
if (putMethod != null) {
putMethod.releaseConnection();
}
}
return result;
}
use of com.nextcloud.operations.PutMethod in project android-library by nextcloud.
the class SetStatusRemoteOperation method run.
/**
* @param client Client object
*/
@Override
public RemoteOperationResult<Boolean> run(NextcloudClient client) {
PutMethod putMethod = null;
RemoteOperationResult<Boolean> result;
try {
// request body
MediaType json = MediaType.parse("application/json; charset=utf-8");
RequestBody requestBody = RequestBody.create(json, "{\"statusType\": \"" + type.getString() + "\"}");
// remote request
putMethod = new PutMethod(client.getBaseUri() + SET_STATUS_URL, true, requestBody);
int status = client.execute(putMethod);
if (status == HttpStatus.SC_OK) {
result = new RemoteOperationResult<>(true, putMethod);
} else {
result = new RemoteOperationResult<>(false, putMethod);
putMethod.releaseConnection();
}
} catch (Exception e) {
result = new RemoteOperationResult<>(e);
Log_OC.e(TAG, "Setting of own status failed: " + result.getLogMessage(), result.getException());
} finally {
if (putMethod != null) {
putMethod.releaseConnection();
}
}
return result;
}
Aggregations