mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 10:27:45 +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 timber.log.Timber | ||||||
| import java.net.URL | import java.net.URL | ||||||
| 
 | 
 | ||||||
| class GetOCInstanceViaWebfingerOperation( | class GetInstancesViaWebfingerOperation( | ||||||
|     private val lockupServerDomain: String, |     private val lockupServerDomain: String, | ||||||
|     private val rel: String, |     private val rel: String, | ||||||
|     private val resource: String, |     private val resource: String, | ||||||
| ) : RemoteOperation<String>() { | ) : RemoteOperation<List<String>>() { | ||||||
| 
 | 
 | ||||||
|     private fun buildRequestUri() = |     private fun buildRequestUri() = | ||||||
|         Uri.parse(lockupServerDomain).buildUpon() |         Uri.parse(lockupServerDomain).buildUpon() | ||||||
| @ -61,30 +61,25 @@ class GetOCInstanceViaWebfingerOperation( | |||||||
|         method: HttpMethod, |         method: HttpMethod, | ||||||
|         response: String?, |         response: String?, | ||||||
|         status: Int |         status: Int | ||||||
|     ): RemoteOperationResult<String> { |     ): RemoteOperationResult<List<String>> { | ||||||
|         Timber.e("Failed requesting webfinger info") |         Timber.e("Failed requesting webfinger info") | ||||||
|         if (response != null) { |         if (response != null) { | ||||||
|             Timber.e("*** status code: $status; response message: $response") |             Timber.e("*** status code: $status; response message: $response") | ||||||
|         } else { |         } else { | ||||||
|             Timber.e("*** status code: $status") |             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) |         val response = parseResponse(rawResponse) | ||||||
|         for (i in response.links) { |         Timber.d("Successful Webfinger request: $response") | ||||||
|             if (i.rel == rel) { |         val operationResult = RemoteOperationResult<List<String>>(RemoteOperationResult.ResultCode.OK) | ||||||
|                 val operationResult = RemoteOperationResult<String>(RemoteOperationResult.ResultCode.OK) |         operationResult.data = response.links.map { it.href } | ||||||
|                 operationResult.data = i.href |  | ||||||
|         return operationResult |         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 requestUri = buildRequestUri() | ||||||
|         val getMethod = GetMethod(URL(requestUri.toString())) |         val getMethod = GetMethod(URL(requestUri.toString())) | ||||||
|         return try { |         return try { | ||||||
| @ -98,7 +93,7 @@ class GetOCInstanceViaWebfingerOperation( | |||||||
|             } |             } | ||||||
|         } catch (e: Exception) { |         } catch (e: Exception) { | ||||||
|             Timber.e(e, "Requesting webfinger info failed") |             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 | import com.owncloud.android.lib.common.operations.RemoteOperationResult | ||||||
| 
 | 
 | ||||||
| interface WebfingerService { | interface WebfingerService { | ||||||
|     fun getInstanceFromWebfinger( |     fun getInstancesFromWebfinger( | ||||||
|         lookupServer: String, |         lookupServer: String, | ||||||
|         username: String, |         username: String, | ||||||
|  |         rel: String, | ||||||
|         client: OwnCloudClient, |         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.OwnCloudClient | ||||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult | 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 | import com.owncloud.android.lib.resources.webfinger.services.WebfingerService | ||||||
| 
 | 
 | ||||||
| class OCWebfingerService : WebfingerService { | class OCWebfingerService : WebfingerService { | ||||||
| 
 | 
 | ||||||
|     override fun getInstanceFromWebfinger( |     override fun getInstancesFromWebfinger( | ||||||
|         lookupServer: String, |         lookupServer: String, | ||||||
|         username: String, |         username: String, | ||||||
|  |         rel: String, | ||||||
|         client: OwnCloudClient, |         client: OwnCloudClient, | ||||||
|     ): RemoteOperationResult<String> = |     ): RemoteOperationResult<List<String>> = | ||||||
|         GetOCInstanceViaWebfingerOperation(lookupServer, OWNCLOUD_REL, username).execute(client) |         GetInstancesViaWebfingerOperation(lookupServer, rel, username).execute(client) | ||||||
| 
 |  | ||||||
|     companion object { |  | ||||||
|         private const val OWNCLOUD_REL = "http://webfinger.owncloud/rel/server-instance" |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user