use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.
the class SeafConnection method getEvents.
public String getEvents(int start, boolean useNewActivity) throws SeafException {
String apiPath;
try {
Map<String, Object> params = Maps.newHashMap();
if (useNewActivity) {
apiPath = String.format("api/v2.1/activities/");
if (start == 0) {
start = 1;
}
params.put("page", start);
} else {
apiPath = String.format("api2/events/");
params.put("start", start);
}
HttpRequest req = prepareApiGetRequest(apiPath, params);
checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
return new String(req.bytes(), "UTF-8");
} 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 delete.
public Pair<String, String> delete(String repoID, String path, boolean isdir) throws SeafException {
try {
Map<String, Object> params = Maps.newHashMap();
params.put("p", encodeUriComponent(path).replaceAll("\\+", "%20"));
params.put("reloaddir", "true");
String suffix = isdir ? "/dir/" : "/file/";
HttpRequest req = prepareApiDeleteRequest("api2/repos/" + repoID + suffix, params);
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);
}
}
use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.
the class SeafConnection method completeRemoteWipe.
public void completeRemoteWipe(String token) throws SeafException {
try {
HttpRequest req = prepareApiPostRequest("api2/device-wiped/", true, null);
req.form("token", token);
checkRequestResponseStatus(req, HttpURLConnection.HTTP_CREATED);
} catch (SeafException e) {
throw e;
} catch (HttpRequestException e) {
throw getSeafExceptionFromHttpRequestException(e);
}
}
use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.
the class SeafConnection method getBlockDownloadList.
public String getBlockDownloadList(String repoID, String path) throws SeafException, IOException {
try {
String apiPath = String.format("api2/repos/%s/file/", repoID);
Map<String, Object> params = Maps.newHashMap();
params.put("p", encodeUriComponent(path));
params.put("op", "downloadblks");
HttpRequest req = prepareApiGetRequest(apiPath, params);
checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
String result = new String(req.bytes(), "UTF-8");
return result;
} catch (SeafException | IOException e) {
throw e;
} catch (HttpRequestException e) {
throw getSeafExceptionFromHttpRequestException(e);
}
}
use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.
the class SeafConnection method getDownloadLink.
public Pair<String, String> getDownloadLink(String repoID, String path, boolean isReUsed) throws SeafException {
try {
String apiPath = String.format("api2/repos/%s/file/", repoID);
Map<String, Object> params = Maps.newHashMap();
params.put("p", encodeUriComponent(path));
params.put("op", "download");
if (isReUsed) {
params.put("reuse", 1);
}
HttpRequest req = prepareApiGetRequest(apiPath, params);
checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
String result = new String(req.bytes(), "UTF-8");
String fileID = req.header("oid");
// should return "\"http://gonggeng.org:8082/...\"" or "\"https://gonggeng.org:8082/...\"
if (result.startsWith("\"http") && fileID != null) {
String url = result.substring(1, result.length() - 1);
return new Pair<String, String>(url, fileID);
} else {
throw SeafException.illFormatException;
}
} catch (SeafException e) {
throw e;
} catch (UnsupportedEncodingException e) {
throw SeafException.encodingException;
} catch (IOException e) {
throw SeafException.networkException;
} catch (HttpRequestException e) {
throw getSeafExceptionFromHttpRequestException(e);
}
}
Aggregations