2018-12-26 08:07:24 +00:00
|
|
|
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
|
|
|
|
|
|
|
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ResponseParameters
|
2019-01-17 02:43:51 +00:00
|
|
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.toJsonWithoutNulls
|
2018-12-26 08:07:24 +00:00
|
|
|
import kotlinx.serialization.*
|
|
|
|
import kotlinx.serialization.json.JsonObject
|
|
|
|
|
|
|
|
interface Request<T: Any> {
|
|
|
|
fun method(): String
|
|
|
|
fun resultSerializer(): KSerializer<T>
|
|
|
|
@ImplicitReflectionSerializer
|
|
|
|
fun json(): JsonObject = toJsonWithoutNulls()
|
|
|
|
}
|
|
|
|
|
|
|
|
fun <T : Any> StringFormat.extractResult(
|
|
|
|
from: String,
|
|
|
|
dataSerializer: KSerializer<T>
|
|
|
|
): ResponseParameters<T> {
|
|
|
|
return parse(ResponseParameters.serializer(dataSerializer), from)
|
|
|
|
}
|