File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
library/src/main/java/com/nextcloud/common Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com.nextcloud.common
2
+
3
+ import com.google.gson.Gson
4
+ import okhttp3.MediaType.Companion.toMediaType
5
+ import okhttp3.RequestBody
6
+ import okhttp3.RequestBody.Companion.toRequestBody
7
+
8
+ class JSONRequestBody () {
9
+ private val content = mutableMapOf<String , String >()
10
+
11
+ constructor (key: String , value: String ) : this () {
12
+ put(key, value)
13
+ }
14
+
15
+ fun put (key : String , value : String ) {
16
+ content[key] = value
17
+ }
18
+
19
+ fun get (): RequestBody {
20
+ val json = Gson ().toJson(content)
21
+ return json.toRequestBody(JSON_MEDIATYPE )
22
+ }
23
+
24
+ override fun toString (): String {
25
+ return content.toString()
26
+ }
27
+
28
+ companion object {
29
+ private val JSON_MEDIATYPE = " application/json; charset=utf-8" .toMediaType()
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments