1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-23 02:28:45 +00:00

Request extracting result method removed

This commit is contained in:
InsanusMokrassar 2019-08-19 16:06:04 +06:00
parent 84eb2fac7c
commit f86ae2b592
2 changed files with 2 additions and 8 deletions

View File

@ -8,6 +8,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters.EmptyLim
import com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters.RequestLimiter import com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters.RequestLimiter
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.extractResult import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.extractResult
import com.github.insanusmokrassar.TelegramBotAPI.types.Response
import com.github.insanusmokrassar.TelegramBotAPI.types.RetryAfterError import com.github.insanusmokrassar.TelegramBotAPI.types.RetryAfterError
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
import io.ktor.client.HttpClient import io.ktor.client.HttpClient
@ -74,7 +75,7 @@ class KtorRequestsExecutor(
val content = call.response.use { val content = call.response.use {
it.content.toByteArray().toString(Charsets.UTF_8) it.content.toByteArray().toString(Charsets.UTF_8)
} }
val responseObject = jsonFormatter.extractResult(content) val responseObject = jsonFormatter.parse(Response.serializer(), content)
(responseObject.result ?.let { (responseObject.result ?.let {
jsonFormatter.fromJson(request.resultDeserializer(), it) jsonFormatter.fromJson(request.resultDeserializer(), it)

View File

@ -1,6 +1,5 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.types.Response
import com.github.insanusmokrassar.TelegramBotAPI.utils.toJsonWithoutNulls import com.github.insanusmokrassar.TelegramBotAPI.utils.toJsonWithoutNulls
import kotlinx.serialization.* import kotlinx.serialization.*
import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.JsonObject
@ -12,9 +11,3 @@ interface Request<T: Any> {
fun json(): JsonObject = toJsonWithoutNulls(RequestSerializer) fun json(): JsonObject = toJsonWithoutNulls(RequestSerializer)
} }
object RequestSerializer : KSerializer<Request<*>> by ContextSerializer(Request::class) object RequestSerializer : KSerializer<Request<*>> by ContextSerializer(Request::class)
fun StringFormat.extractResult(
from: String
): Response {
return parse(Response.serializer(), from)
}