Verified Commit ed19120e authored by Konstantin Kopper's avatar Konstantin Kopper
Browse files

Use automatic serialization for pseuco.com API requests

parent c1b1486e
Pipeline #27103 passed with stages
in 5 minutes and 37 seconds
......@@ -4,6 +4,8 @@ import com.pseuco.FileSharer
import com.pseuco.PseuCoComFile
import io.ktor.client.HttpClient
import io.ktor.client.engine.apache.Apache
import io.ktor.client.features.json.JsonFeature
import io.ktor.client.features.json.serializer.KotlinxSerializer
import io.ktor.client.request.accept
import io.ktor.client.request.get
import io.ktor.client.request.post
......@@ -11,12 +13,11 @@ import io.ktor.client.statement.HttpStatement
import io.ktor.http.ContentType
import io.ktor.http.HttpStatusCode
import io.ktor.http.URLProtocol
import io.ktor.http.content.TextContent
import io.ktor.http.contentType
import io.ktor.http.withCharset
import io.ktor.utils.io.jvm.javaio.toInputStream
import kotlinx.serialization.SerializationException
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
......@@ -40,7 +41,11 @@ object PseuCoShare : FileSharer {
* @since 2.0.0
* @see Apache
*/
private val client = HttpClient(Apache)
private val client = HttpClient(Apache) {
install(JsonFeature) {
serializer = KotlinxSerializer()
}
}
fun close() = client.close()
......@@ -76,12 +81,8 @@ object PseuCoShare : FileSharer {
path("api", "paste", "add")
}
accept(ContentType.Application.Json.withCharset(Charsets.UTF_8))
body = TextContent(
Json.encodeToString(
if (temporary) PseuCoComExchange(file) else PseuCoComExchange(file, 1)
),
contentType = ContentType.Application.Json
)
body = if (temporary) PseuCoComExchange(file) else PseuCoComExchange(file, 1)
contentType(ContentType.Application.Json)
}.execute()
if (c.status != HttpStatusCode.OK)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment