-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: tobiasKaminsky <[email protected]>
- Loading branch information
1 parent
420666a
commit b59f39c
Showing
3 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
...om/nextcloud/android/lib/resources/recommendations/GetRecommendationsRemoteOperationIT.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Nextcloud Android Library | ||
* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-FileCopyrightText: 2024 Tobias Kaminsky <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
package com.nextcloud.android.lib.resources.recommendations | ||
|
||
import com.owncloud.android.AbstractIT | ||
import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
|
||
class GetRecommendationsRemoteOperationIT : AbstractIT() { | ||
@Test | ||
fun getRecommendations() { | ||
assertTrue(CreateFolderRemoteOperation("/test/", true).execute(client).isSuccess) | ||
|
||
val result = GetRecommendationsRemoteOperation().execute(nextcloudClient).resultData | ||
|
||
assertTrue(result.isNotEmpty()) | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
.../com/nextcloud/android/lib/resources/recommendations/GetRecommendationsRemoteOperation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Nextcloud Android Library | ||
* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-FileCopyrightText: 2024 Tobias Kaminsky <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
package com.nextcloud.android.lib.resources.recommendations | ||
|
||
import com.google.gson.reflect.TypeToken | ||
import com.nextcloud.common.NextcloudClient | ||
import com.nextcloud.operations.GetMethod | ||
import com.owncloud.android.lib.common.operations.RemoteOperationResult | ||
import com.owncloud.android.lib.common.utils.Log_OC | ||
import com.owncloud.android.lib.ocs.ServerResponse | ||
import com.owncloud.android.lib.resources.OCSRemoteOperation | ||
import org.apache.commons.httpclient.HttpStatus | ||
|
||
/** | ||
* Get recommendation of an user | ||
*/ | ||
class GetRecommendationsRemoteOperation : | ||
OCSRemoteOperation<List<Recommendation>>() { | ||
@Suppress("TooGenericExceptionCaught") | ||
override fun run(client: NextcloudClient): RemoteOperationResult<List<Recommendation>> { | ||
var result: RemoteOperationResult<List<Recommendation>> | ||
var getMethod: GetMethod? = null | ||
try { | ||
getMethod = | ||
GetMethod( | ||
client.baseUri.toString() + ENDPOINT + JSON_FORMAT, | ||
true | ||
) | ||
val status = client.execute(getMethod) | ||
if (status == HttpStatus.SC_OK) { | ||
val map = | ||
getServerResponse( | ||
getMethod, | ||
object : TypeToken<ServerResponse<List<Recommendation>>>() {} | ||
)?.ocs?.data | ||
|
||
if (map != null) { | ||
result = RemoteOperationResult(true, getMethod) | ||
result.setResultData(map) | ||
} else { | ||
result = RemoteOperationResult(false, getMethod) | ||
} | ||
} else { | ||
result = RemoteOperationResult(false, getMethod) | ||
} | ||
} catch (e: Exception) { | ||
result = RemoteOperationResult(e) | ||
Log_OC.e( | ||
TAG, | ||
"Get recommendations failed: " + result.logMessage, | ||
result.exception | ||
) | ||
} finally { | ||
getMethod?.releaseConnection() | ||
} | ||
return result | ||
} | ||
|
||
companion object { | ||
private val TAG = GetRecommendationsRemoteOperation::class.java.simpleName | ||
private const val ENDPOINT = "/ocs/v2.php/apps/recommendations/api/v1/recommendations" | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
library/src/main/java/com/nextcloud/android/lib/resources/recommendations/Recommendation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Nextcloud Android Library | ||
* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-FileCopyrightText: 2024 Tobias Kaminsky <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
package com.nextcloud.android.lib.resources.recommendations | ||
|
||
data class Recommendation( | ||
val id: Long, | ||
val timestamp: Long, | ||
val name: String, | ||
val directory: String, | ||
val extension: String, | ||
val mimeType: String, | ||
val hasPreview: Boolean, | ||
val reason: String | ||
) |