[APIv2/Librus] Fix Librus messages requests

This commit is contained in:
Kacper Ziubryniewicz 2019-10-25 22:12:45 +02:00
parent 8c099bc137
commit 9aef3d56df

View File

@ -6,11 +6,13 @@ package pl.szczodrzynski.edziennik.api.v2.librus.data
import im.wangchao.mhttp.Request import im.wangchao.mhttp.Request
import im.wangchao.mhttp.Response import im.wangchao.mhttp.Response
import im.wangchao.mhttp.body.MediaTypeUtils
import im.wangchao.mhttp.callback.TextCallbackHandler import im.wangchao.mhttp.callback.TextCallbackHandler
import okhttp3.Cookie import okhttp3.Cookie
import org.jsoup.Jsoup import org.jsoup.Jsoup
import org.jsoup.nodes.Document import org.jsoup.nodes.Document
import org.jsoup.parser.Parser import org.jsoup.parser.Parser
import org.redundent.kotlin.xml.PrintOptions
import org.redundent.kotlin.xml.xml import org.redundent.kotlin.xml.xml
import pl.szczodrzynski.edziennik.api.v2.* import pl.szczodrzynski.edziennik.api.v2.*
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
@ -79,6 +81,7 @@ open class LibrusMessages(open val data: DataLibrus) {
)) ))
val requestXml = xml("service") { val requestXml = xml("service") {
"header" { }
"data" { "data" {
for ((key, value) in parameters.orEmpty()) { for ((key, value) in parameters.orEmpty()) {
key { key {
@ -86,12 +89,15 @@ open class LibrusMessages(open val data: DataLibrus) {
} }
} }
} }
} }.toString(PrintOptions(
singleLineTextElements = true,
useSelfClosingTags = true
))
Request.builder() Request.builder()
.url("$LIBRUS_MESSAGES_URL/$endpoint") .url("$LIBRUS_MESSAGES_URL/$endpoint")
.userAgent(SYNERGIA_USER_AGENT) .userAgent(SYNERGIA_USER_AGENT)
.setTextBody(requestXml.toString(), "application/xml") .setTextBody(requestXml, MediaTypeUtils.APPLICATION_XML)
.apply { .apply {
when (method) { when (method) {
GET -> get() GET -> get()