Skip to content

Commit a5b967b

Browse files
Merge pull request #1271 from nextcloud/depocc/helpers
Deprecate OwncloudClient - Helpers
2 parents 26dc847 + 32a0006 commit a5b967b

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Nextcloud Android Library
3+
*
4+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-FileCopyrightText: 2024 ZetaTom <[email protected]>
6+
* SPDX-License-Identifier: MIT
7+
*/
8+
package com.nextcloud.common
9+
10+
import com.google.gson.Gson
11+
import okhttp3.MediaType.Companion.toMediaType
12+
import okhttp3.RequestBody
13+
import okhttp3.RequestBody.Companion.toRequestBody
14+
15+
class JSONRequestBody() {
16+
private val content = mutableMapOf<String, String>()
17+
18+
constructor(key: String, value: String) : this() {
19+
put(key, value)
20+
}
21+
22+
fun put(
23+
key: String,
24+
value: String
25+
) {
26+
content[key] = value
27+
}
28+
29+
fun get(): RequestBody {
30+
val json = Gson().toJson(content)
31+
return json.toRequestBody(JSON_MEDIATYPE)
32+
}
33+
34+
override fun toString(): String {
35+
return content.toString()
36+
}
37+
38+
companion object {
39+
private val JSON_MEDIATYPE = "application/json; charset=utf-8".toMediaType()
40+
}
41+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Nextcloud Android Library
3+
*
4+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-FileCopyrightText: 2024 ZetaTom <[email protected]>
6+
* SPDX-License-Identifier: MIT
7+
*/
8+
package com.nextcloud.operations
9+
10+
import com.nextcloud.common.OkHttpMethodBase
11+
import okhttp3.Request
12+
13+
/**
14+
* HTTP HEAD method that uses OkHttp with new NextcloudClient
15+
*/
16+
class HeadMethod(
17+
uri: String,
18+
useOcsApiRequestHeader: Boolean
19+
) : OkHttpMethodBase(uri, useOcsApiRequestHeader) {
20+
override fun applyType(temp: Request.Builder) {
21+
temp.head()
22+
}
23+
}

0 commit comments

Comments
 (0)