mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +00:00 
			
		
		
		
	Allow retrieval of several instances from webfinger
This commit is contained in:
		
							parent
							
								
									2458db1828
								
							
						
					
					
						commit
						0017079a69
					
				| @ -36,11 +36,11 @@ import com.squareup.moshi.Moshi | ||||
| import timber.log.Timber | ||||
| import java.net.URL | ||||
| 
 | ||||
| class GetOCInstanceViaWebfingerOperation( | ||||
| class GetInstancesViaWebfingerOperation( | ||||
|     private val lockupServerDomain: String, | ||||
|     private val rel: String, | ||||
|     private val resource: String, | ||||
| ) : RemoteOperation<String>() { | ||||
| ) : RemoteOperation<List<String>>() { | ||||
| 
 | ||||
|     private fun buildRequestUri() = | ||||
|         Uri.parse(lockupServerDomain).buildUpon() | ||||
| @ -61,30 +61,25 @@ class GetOCInstanceViaWebfingerOperation( | ||||
|         method: HttpMethod, | ||||
|         response: String?, | ||||
|         status: Int | ||||
|     ): RemoteOperationResult<String> { | ||||
|     ): RemoteOperationResult<List<String>> { | ||||
|         Timber.e("Failed requesting webfinger info") | ||||
|         if (response != null) { | ||||
|             Timber.e("*** status code: $status; response message: $response") | ||||
|         } else { | ||||
|             Timber.e("*** status code: $status") | ||||
|         } | ||||
|         return RemoteOperationResult<String>(method) | ||||
|         return RemoteOperationResult<List<String>>(method) | ||||
|     } | ||||
| 
 | ||||
|     private fun onRequestSuccessful(rawResponse: String): RemoteOperationResult<String> { | ||||
|     private fun onRequestSuccessful(rawResponse: String): RemoteOperationResult<List<String>> { | ||||
|         val response = parseResponse(rawResponse) | ||||
|         for (i in response.links) { | ||||
|             if (i.rel == rel) { | ||||
|                 val operationResult = RemoteOperationResult<String>(RemoteOperationResult.ResultCode.OK) | ||||
|                 operationResult.data = i.href | ||||
|         Timber.d("Successful Webfinger request: $response") | ||||
|         val operationResult = RemoteOperationResult<List<String>>(RemoteOperationResult.ResultCode.OK) | ||||
|         operationResult.data = response.links.map { it.href } | ||||
|         return operationResult | ||||
|     } | ||||
|         } | ||||
|         Timber.e("Could not find ownCloud relevant information in webfinger response: $rawResponse") | ||||
|         throw java.lang.Exception("Could not find ownCloud relevant information in webfinger response") | ||||
|     } | ||||
| 
 | ||||
|     override fun run(client: OwnCloudClient): RemoteOperationResult<String> { | ||||
|     override fun run(client: OwnCloudClient): RemoteOperationResult<List<String>> { | ||||
|         val requestUri = buildRequestUri() | ||||
|         val getMethod = GetMethod(URL(requestUri.toString())) | ||||
|         return try { | ||||
| @ -98,7 +93,7 @@ class GetOCInstanceViaWebfingerOperation( | ||||
|             } | ||||
|         } catch (e: Exception) { | ||||
|             Timber.e(e, "Requesting webfinger info failed") | ||||
|             RemoteOperationResult<String>(e) | ||||
|             RemoteOperationResult<List<String>>(e) | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| @ -21,9 +21,10 @@ import com.owncloud.android.lib.common.OwnCloudClient | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult | ||||
| 
 | ||||
| interface WebfingerService { | ||||
|     fun getInstanceFromWebfinger( | ||||
|     fun getInstancesFromWebfinger( | ||||
|         lookupServer: String, | ||||
|         username: String, | ||||
|         rel: String, | ||||
|         client: OwnCloudClient, | ||||
|     ): RemoteOperationResult<String> | ||||
|     ): RemoteOperationResult<List<String>> | ||||
| } | ||||
|  | ||||
| @ -19,20 +19,16 @@ package com.owncloud.android.lib.resources.webfinger.services.implementation | ||||
| 
 | ||||
| import com.owncloud.android.lib.common.OwnCloudClient | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult | ||||
| import com.owncloud.android.lib.resources.webfinger.GetOCInstanceViaWebfingerOperation | ||||
| import com.owncloud.android.lib.resources.webfinger.GetInstancesViaWebfingerOperation | ||||
| import com.owncloud.android.lib.resources.webfinger.services.WebfingerService | ||||
| 
 | ||||
| class OCWebfingerService : WebfingerService { | ||||
| 
 | ||||
|     override fun getInstanceFromWebfinger( | ||||
|     override fun getInstancesFromWebfinger( | ||||
|         lookupServer: String, | ||||
|         username: String, | ||||
|         rel: String, | ||||
|         client: OwnCloudClient, | ||||
|     ): RemoteOperationResult<String> = | ||||
|         GetOCInstanceViaWebfingerOperation(lookupServer, OWNCLOUD_REL, username).execute(client) | ||||
| 
 | ||||
|     companion object { | ||||
|         private const val OWNCLOUD_REL = "http://webfinger.owncloud/rel/server-instance" | ||||
|     } | ||||
| 
 | ||||
|     ): RemoteOperationResult<List<String>> = | ||||
|         GetInstancesViaWebfingerOperation(lookupServer, rel, username).execute(client) | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user