mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Update GetMethod to be used in GetRemoteUserInfoOperation
This commit is contained in:
parent
1cf44a9fff
commit
dc9a37db28
@ -8,18 +8,18 @@ import okhttp3.Response;
|
||||
|
||||
public class GetMethod extends HttpMethod {
|
||||
|
||||
public GetMethod(OkHttpClient okHttpClient, Request requestBase) {
|
||||
super(okHttpClient, requestBase);
|
||||
public GetMethod(OkHttpClient okHttpClient, Request baseRequest) {
|
||||
super(okHttpClient, baseRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int execute() throws IOException {
|
||||
final Request request = mBaseRequest
|
||||
mRequest = mBaseRequest
|
||||
.newBuilder()
|
||||
.get()
|
||||
.build();
|
||||
|
||||
mResponse = mOkHttpClient.newCall(request).execute();
|
||||
mResponse = mOkHttpClient.newCall(mRequest).execute();
|
||||
return mResponse.code();
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/* ownCloud Android Library is available under MIT license
|
||||
* Copyright (C) 2016 ownCloud GmbH.
|
||||
* Copyright (C) 2018 ownCloud GmbH.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@ -37,12 +37,15 @@ import com.owncloud.android.lib.common.methods.nonwebdav.GetMethod;
|
||||
|
||||
import okhttp3.Request;
|
||||
|
||||
import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK;
|
||||
|
||||
|
||||
/**
|
||||
* Gets information (id, display name, and e-mail address) about the user logged in.
|
||||
*
|
||||
* @author masensio
|
||||
* @author David A. Velasco
|
||||
* @author David González Verdugo
|
||||
*/
|
||||
|
||||
public class GetRemoteUserInfoOperation extends RemoteOperation {
|
||||
@ -64,62 +67,49 @@ public class GetRemoteUserInfoOperation extends RemoteOperation {
|
||||
|
||||
@Override
|
||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||
RemoteOperationResult result = null;
|
||||
RemoteOperationResult result;
|
||||
|
||||
//Get the user
|
||||
try {
|
||||
|
||||
final Request request = new Request.Builder()
|
||||
.url(client.getBaseUri() + OCS_ROUTE)
|
||||
.addHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
|
||||
.build();
|
||||
|
||||
GetMethod getMethod = new GetMethod(client.getOkHttpClient(), request);
|
||||
int status = client.executeHttpMethod(getMethod);
|
||||
String response = getMethod.getResponse().body().string();
|
||||
|
||||
// client.executeHttpMethod(getMethod);
|
||||
//
|
||||
// get = new GetMethod(client.getBaseUri() + OCS_ROUTE);
|
||||
// get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
|
||||
// status = client.executeMethod(get);
|
||||
// if (isSuccess(status)) {
|
||||
// String response = get.getResponseBodyAsString();
|
||||
// Log_OC.d(TAG, "Successful response");
|
||||
//
|
||||
// // Parse the response
|
||||
// JSONObject respJSON = new JSONObject(response);
|
||||
// JSONObject respOCS = respJSON.getJSONObject(NODE_OCS);
|
||||
// JSONObject respData = respOCS.getJSONObject(NODE_DATA);
|
||||
//
|
||||
// UserInfo userInfo = new UserInfo();
|
||||
// userInfo.mId = respData.getString(NODE_ID);
|
||||
// userInfo.mDisplayName = respData.getString(NODE_DISPLAY_NAME);
|
||||
// userInfo.mEmail = respData.getString(NODE_EMAIL);
|
||||
//
|
||||
// // Result
|
||||
// result = new RemoteOperationResult(true, get);
|
||||
// // Username in result.data
|
||||
// ArrayList<Object> data = new ArrayList<Object>();
|
||||
// data.add(userInfo);
|
||||
// result.setData(data);
|
||||
//
|
||||
// } else {
|
||||
// result = new RemoteOperationResult(false, get);
|
||||
// String response = get.getResponseBodyAsString();
|
||||
// Log_OC.e(TAG, "Failed response while getting user information ");
|
||||
// if (response != null) {
|
||||
// Log_OC.e(TAG, "*** status code: " + status + " ; response message: " + response);
|
||||
// } else {
|
||||
// Log_OC.e(TAG, "*** status code: " + status);
|
||||
// }
|
||||
// }
|
||||
if (isSuccess(status)) {
|
||||
Log_OC.d(TAG, "Successful response");
|
||||
|
||||
JSONObject respJSON = new JSONObject(response);
|
||||
JSONObject respOCS = respJSON.getJSONObject(NODE_OCS);
|
||||
JSONObject respData = respOCS.getJSONObject(NODE_DATA);
|
||||
|
||||
UserInfo userInfo = new UserInfo();
|
||||
userInfo.mId = respData.getString(NODE_ID);
|
||||
userInfo.mDisplayName = respData.getString(NODE_DISPLAY_NAME);
|
||||
userInfo.mEmail = respData.getString(NODE_EMAIL);
|
||||
|
||||
result = new RemoteOperationResult(OK);
|
||||
|
||||
ArrayList<Object> data = new ArrayList<>();
|
||||
data.add(userInfo);
|
||||
result.setData(data);
|
||||
|
||||
} else {
|
||||
result = new RemoteOperationResult(false, getMethod.getRequest(), getMethod.getResponse());
|
||||
Log_OC.e(TAG, "Failed response while getting user information ");
|
||||
if (response != null) {
|
||||
Log_OC.e(TAG, "*** status code: " + status + " ; response message: " + response);
|
||||
} else {
|
||||
Log_OC.e(TAG, "*** status code: " + status);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result = new RemoteOperationResult(e);
|
||||
Log_OC.e(TAG, "Exception while getting OC user information", e);
|
||||
|
||||
} finally {
|
||||
// if (get != null) {
|
||||
// get.releaseConnection();
|
||||
// }
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -129,7 +119,6 @@ public class GetRemoteUserInfoOperation extends RemoteOperation {
|
||||
return (status == HttpStatus.SC_OK);
|
||||
}
|
||||
|
||||
|
||||
public static class UserInfo {
|
||||
public String mId = "";
|
||||
public String mDisplayName = "";
|
||||
|
Loading…
x
Reference in New Issue
Block a user