[APIv2/Idziennik] Better request parameter adding.

This commit is contained in:
Kuba Szczodrzyński 2019-10-28 23:21:57 +01:00
parent 81c6275255
commit 2ad8a308b3

View File

@ -4,6 +4,7 @@
package pl.szczodrzynski.edziennik.api.v2.idziennik.data
import com.google.gson.JsonArray
import com.google.gson.JsonObject
import im.wangchao.mhttp.Request
import im.wangchao.mhttp.Response
@ -83,9 +84,19 @@ open class IdziennikWeb(open val data: DataIdziennik) {
.userAgent(IDZIENNIK_USER_AGENT)
.postJson()
.apply {
val json = JsonObject()
parameters.map { (name, value) ->
addParameter(name, value)
when (value) {
is JsonObject -> json.add(name, value)
is JsonArray -> json.add(name, value)
is String -> json.addProperty(name, value)
is Int -> json.addProperty(name, value)
is Long -> json.addProperty(name, value)
is Float -> json.addProperty(name, value)
is Char -> json.addProperty(name, value)
}
}
setJsonBody(json)
}
.allowErrorCode(HTTP_UNAUTHORIZED)
.allowErrorCode(HTTP_INTERNAL_ERROR)