use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.
the class SeafConnection method deleteRepo.
public void deleteRepo(String repoID) throws SeafException {
try {
HttpRequest req = prepareApiDeleteRequest(String.format("api2/repos/%s/", repoID), null);
checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
} catch (HttpRequestException e) {
throw getSeafExceptionFromHttpRequestException(e);
}
}
use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.
the class SeafConnection method getRepos.
public String getRepos() throws SeafException {
HttpRequest req = null;
try {
req = prepareApiGetRequest("api2/repos/");
checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
String result = new String(req.bytes(), "UTF-8");
return result;
} catch (SeafException e) {
throw e;
} catch (HttpRequestException e) {
throw getSeafExceptionFromHttpRequestException(e);
} catch (IOException e) {
throw SeafException.networkException;
}
}
use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.
the class SeafConnection method copy.
/**
* Copy a file or multiple files, multiple file/folder names should be seperated by a ":".
*
* @param srcRepoId the source repo id
* @param srcDir the source folder in src_repo
* @param srcFn list of file/folder names to copy. Multiple file/folder names can be seperated by ":"
* @param dstRepoId the destination repo id
* @param dstDir the destination folder in dst_repo
* @throws SeafException
*/
public void copy(String srcRepoId, String srcDir, String srcFn, String dstRepoId, String dstDir) throws SeafException {
try {
Map<String, Object> params = Maps.newHashMap();
params.put("p", encodeUriComponent(srcDir).replaceAll("\\+", "%20"));
HttpRequest req = prepareApiPostRequest("api2/repos/" + srcRepoId + "/fileops/copy/", true, params);
req.form("dst_repo", dstRepoId);
req.form("dst_dir", dstDir);
req.form("file_names", srcFn);
checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
} catch (SeafException e) {
throw e;
} catch (HttpRequestException e) {
throw getSeafExceptionFromHttpRequestException(e);
} catch (UnsupportedEncodingException e) {
throw SeafException.encodingException;
}
}
use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.
the class SeafConnection method getAvatar.
public String getAvatar(String email, int size) throws SeafException {
try {
String apiPath = String.format("api2/avatars/user/%s/resized/%d", email, size);
HttpRequest req = prepareApiGetRequest(apiPath);
checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
String result = new String(req.bytes(), "UTF-8");
return result;
} catch (SeafException e) {
throw e;
} catch (HttpRequestException e) {
throw getSeafExceptionFromHttpRequestException(e);
} catch (IOException e) {
throw SeafException.networkException;
}
}
use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.
the class SeafConnection method createNewFile.
public Pair<String, String> createNewFile(String repoID, String parentDir, String fileName) throws SeafException {
try {
String fullPath = Utils.pathJoin(parentDir, fileName);
final String encodeUriComponent = encodeUriComponent(fullPath).replaceAll("\\+", "%20");
Map<String, Object> params = Maps.newHashMap();
params.put("p", encodeUriComponent);
params.put("reloaddir", "true");
HttpRequest req = prepareApiPostRequest("api2/repos/" + repoID + "/file/", true, params, false);
req.form("operation", "create");
checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
String newDirID = req.header("oid");
if (newDirID == null) {
return null;
}
String content = new String(req.bytes(), "UTF-8");
if (content.length() == 0) {
return null;
}
return new Pair<String, String>(newDirID, content);
} catch (SeafException e) {
throw e;
} catch (UnsupportedEncodingException e) {
throw SeafException.encodingException;
} catch (HttpRequestException e) {
throw getSeafExceptionFromHttpRequestException(e);
}
}
Aggregations