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