Skip to content

Commit

Permalink
Merge pull request #1523 from nextcloud/add-new-operation
Browse files Browse the repository at this point in the history
Update License Header and Add New Operation
  • Loading branch information
alperozturk96 authored Aug 23, 2024
2 parents 86b0279 + 9c45fdb commit a4d86ef
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
# SPDX-FileCopyrightText: 2018-2023 Tobias Kaminsky <[email protected]>
# SPDX-FileCopyrightText: 2023 Andy Scherzinger <[email protected]>
# SPDX-FileCopyrightText: 2023 Alper Ozturk <[email protected]>
# SPDX-FileCopyrightText: 2023 Alper Ozturk <[email protected]>
# SPDX-License-Identifier: MIT

# can be overriden by ~/.gradle/gradle.properties
Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2023 Andy Scherzinger <[email protected]>
* SPDX-FileCopyrightText: 2023 Tobias Kaminsky <[email protected]>
* SPDX-FileCopyrightText: 2023 Alper Ozturk <[email protected]>
* SPDX-FileCopyrightText: 2023 Alper Ozturk <[email protected]>
* SPDX-FileCopyrightText: 2022 Álvaro Brey Vilas <[email protected]>
* SPDX-License-Identifier: MIT
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Nextcloud Android Library
*
* SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2023 Alper Ozturk <[email protected]>
* SPDX-FileCopyrightText: 2023 Alper Ozturk <[email protected]>
* SPDX-License-Identifier: MIT
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Nextcloud Android Library
*
* SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2023 Alper Ozturk <[email protected]>
* SPDX-FileCopyrightText: 2023 Alper Ozturk <[email protected]>
* SPDX-License-Identifier: MIT
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Nextcloud Android Library
*
* SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2023 Alper Ozturk <[email protected]>
* SPDX-FileCopyrightText: 2023 Alper Ozturk <[email protected]>
* SPDX-License-Identifier: MIT
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Nextcloud Android Library
*
* SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2023 Alper Ozturk <[email protected]>
* SPDX-FileCopyrightText: 2023 Alper Ozturk <[email protected]>
* SPDX-License-Identifier: MIT
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Nextcloud Android Library
*
* SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2023 Alper Ozturk <[email protected]>
* SPDX-FileCopyrightText: 2023 Alper Ozturk <[email protected]>
* SPDX-License-Identifier: MIT
*/
package com.nextcloud.extensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Nextcloud Android Library
*
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2023 Alper Ozturk <[email protected]>
* SPDX-FileCopyrightText: 2023 Alper Ozturk <[email protected]>
* SPDX-FileCopyrightText: 2023 Álvaro Brey <[email protected]>
* SPDX-FileCopyrightText: 2015 ownCloud Inc.
* SPDX-License-Identifier: MIT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Nextcloud Android Library
*
* SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2023 Alper Ozturk <[email protected]>
* SPDX-FileCopyrightText: 2023 Alper Ozturk <[email protected]>
* SPDX-FileCopyrightText: 2022 Álvaro Brey <[email protected]>
* SPDX-FileCopyrightText: 2018-2022 Tobias Kaminsky <[email protected]>
* SPDX-FileCopyrightText: 2014-2015 ownCloud Inc.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Nextcloud Android Library
*
* SPDX-FileCopyrightText: 2024 Alper Ozturk <[email protected]>
* SPDX-License-Identifier: MIT
*/

package com.owncloud.android.lib.resources.users

import com.nextcloud.common.NextcloudClient
import com.nextcloud.operations.GetMethod
import com.owncloud.android.lib.common.operations.RemoteOperation
import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.common.utils.Log_OC
import org.apache.commons.httpclient.HttpStatus
import org.json.JSONObject

class GetServerPublicKeyRemoteOperation : RemoteOperation<String>() {
companion object {
private val TAG: String = GetPublicKeyRemoteOperation::class.java.simpleName
private const val ENDPOINT = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/server-key"
}

@Suppress("TooGenericExceptionCaught")
override fun run(client: NextcloudClient): RemoteOperationResult<String> {
var getMethod: GetMethod? = null
var result: RemoteOperationResult<String>
val user: String = client.userId

try {
getMethod = GetMethod(client.baseUri.toString() + ENDPOINT + JSON_FORMAT, true)

val status = client.execute(getMethod)

if (status == HttpStatus.SC_OK) {
val response = getMethod.getResponseBodyAsString()
val respJSON = JSONObject(response)
val serverKey = respJSON.getJSONObject("ocs").getJSONObject("data").getString("public-key")

result = RemoteOperationResult(true, getMethod)
result.setResultData(serverKey)
} else {
result = RemoteOperationResult(false, getMethod)
}
} catch (e: Exception) {
result = RemoteOperationResult(e)
Log_OC.e(
TAG,
"Fetching of server public key failed for user " + user + ": " + result.logMessage,
result.exception
)
} finally {
getMethod?.releaseConnection()
}

return result
}
}
2 changes: 1 addition & 1 deletion sample_client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2022-2023 Tobias Kaminsky <[email protected]>
* SPDX-FileCopyrightText: 2023 Andy Scherzinger <[email protected]>
* SPDX-FileCopyrightText: 2023 Alper Ozturk <[email protected]>
* SPDX-FileCopyrightText: 2023 Alper Ozturk <[email protected]>
* SPDX-FileCopyrightText: 2014 Marcello Steiner <[email protected]>
* SPDX-License-Identifier: MIT
*/
Expand Down

0 comments on commit a4d86ef

Please sign in to comment.