use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.
the class SeafConnection method prepareApiGetRequest.
private HttpRequest prepareApiGetRequest(String apiPath, Map<String, ?> params) throws IOException {
HttpRequest req = HttpRequest.get(account.server + apiPath, params, false);
setRequestCommon(req);
return req;
}
use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.
the class SeafConnection method getBlockDownloadLink.
/**
* get file server link for downloading a block
*
* @param repoID
* @param fileId
* @param blockId
* @return
* @throws SeafException
* @throws IOException
*/
private String getBlockDownloadLink(String repoID, String fileId, String blockId) throws SeafException, IOException {
try {
String apiPath = String.format("api2/repos/%s/files/%s/blks/%s/download-link/", repoID, fileId, blockId);
HttpRequest req = prepareApiGetRequest(apiPath, null);
checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK);
return new String(req.bytes(), "UTF-8");
} 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 getStarredFiles.
public String getStarredFiles() throws SeafException {
try {
// HttpRequest req = prepareApiGetRequest("api2/starredfiles/");
HttpRequest req = prepareApiGetRequest("api/v2.1/starred-items/");
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 realLogin.
/**
* Login into the server
* @return true if login success, false otherwise
* @throws SeafException
*/
private boolean realLogin(String passwd, String authToken, boolean rememberDevice) throws SeafException {
boolean withAuthToken = false;
HttpRequest req = null;
try {
req = prepareApiPostRequest("api2/auth-token/", false, null);
if (!TextUtils.isEmpty(authToken)) {
req.header("X-Seafile-OTP", authToken);
withAuthToken = true;
// Log.d(DEBUG_TAG, "authToken " + authToken);
}
if (!TextUtils.isEmpty(account.sessionKey)) {
req.header("X-SEAFILE-S2FA", account.sessionKey);
}
if (rememberDevice) {
req.header("X-SEAFILE-2FA-TRUST-DEVICE", 1);
}
req.form("username", account.email);
req.form("password", passwd);
String appVersion = "";
Context context = SeadroidApplication.getAppContext();
try {
PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
appVersion = pInfo.versionName;
} catch (NameNotFoundException e) {
// ignore
}
String deviceId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
req.form("platform", "android");
req.form("device_id", deviceId);
req.form("device_name", Build.MODEL);
req.form("client_version", appVersion);
req.form("platform_version", Build.VERSION.RELEASE);
checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK, withAuthToken);
String sessionKey = req.header("x-seafile-s2fa");
if (!TextUtils.isEmpty(sessionKey)) {
account.sessionKey = sessionKey;
}
String contentAsString = new String(req.bytes(), "UTF-8");
JSONObject obj = Utils.parseJsonObject(contentAsString);
if (obj == null)
return false;
account.token = obj.getString("token");
return true;
} catch (SeafException e) {
throw e;
} catch (HttpRequestException e) {
throw getSeafExceptionFromHttpRequestException(e);
} catch (IOException e) {
e.printStackTrace();
throw SeafException.networkException;
} catch (JSONException e) {
throw SeafException.illFormatException;
}
}
use of com.github.kevinsawicki.http.HttpRequest in project seadroid by haiwen.
the class SeafConnection method prepareApiPutRequest.
private HttpRequest prepareApiPutRequest(String apiPath, Map<String, ?> params) throws IOException {
HttpRequest req = HttpRequest.put(account.server + apiPath, params, false);
setRequestCommon(req);
return req;
}
Aggregations