mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-25 11:38:45 +00:00
ResponseParameters renaming to Response
This commit is contained in:
parent
6f04baea4e
commit
206b3fd3e4
@ -30,6 +30,7 @@ must be regular text
|
|||||||
### 0.9.3
|
### 0.9.3
|
||||||
|
|
||||||
* `KtorRequestsExecutor` now can use custom `JSON` string formatter (by default - non strict)
|
* `KtorRequestsExecutor` now can use custom `JSON` string formatter (by default - non strict)
|
||||||
|
* `ResponseParameters` renamed to `Response`
|
||||||
|
|
||||||
### 0.8.5
|
### 0.8.5
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestException
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters.EmptyLimiter
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters.EmptyLimiter
|
||||||
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.types.ResponseParameters
|
import com.github.insanusmokrassar.TelegramBotAPI.types.Response
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.call.HttpClientCall
|
import io.ktor.client.call.HttpClientCall
|
||||||
import io.ktor.client.engine.HttpClientEngine
|
import io.ktor.client.engine.HttpClientEngine
|
||||||
@ -61,7 +61,7 @@ class KtorRequestsExecutor(
|
|||||||
}
|
}
|
||||||
val content = call.response.content.toByteArray().toString(Charset.defaultCharset())
|
val content = call.response.content.toByteArray().toString(Charset.defaultCharset())
|
||||||
val responseObject = jsonFormatter.parse(
|
val responseObject = jsonFormatter.parse(
|
||||||
ResponseParameters.serializer(request.resultSerializer()),
|
Response.serializer(request.resultSerializer()),
|
||||||
content
|
content
|
||||||
)
|
)
|
||||||
responseObject.result ?: call.let {
|
responseObject.result ?: call.let {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.bot
|
package com.github.insanusmokrassar.TelegramBotAPI.bot
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ResponseParameters
|
import com.github.insanusmokrassar.TelegramBotAPI.types.Response
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
class RequestException(
|
class RequestException(
|
||||||
val response: ResponseParameters<*>,
|
val response: Response<*>,
|
||||||
message: String? = null,
|
message: String? = null,
|
||||||
cause: Throwable? = null
|
cause: Throwable? = null
|
||||||
) : IOException(
|
) : IOException(
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
|
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ResponseParameters
|
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
|
||||||
@ -15,6 +15,6 @@ interface Request<T: Any> {
|
|||||||
fun <T : Any> StringFormat.extractResult(
|
fun <T : Any> StringFormat.extractResult(
|
||||||
from: String,
|
from: String,
|
||||||
dataSerializer: KSerializer<T>
|
dataSerializer: KSerializer<T>
|
||||||
): ResponseParameters<T> {
|
): Response<T> {
|
||||||
return parse(ResponseParameters.serializer(dataSerializer), from)
|
return parse(Response.serializer(dataSerializer), from)
|
||||||
}
|
}
|
@ -4,8 +4,14 @@ import kotlinx.serialization.*
|
|||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
"Deprecated because incorrect name",
|
||||||
|
ReplaceWith("Response")
|
||||||
|
)
|
||||||
|
typealias ResponseParameters<T> = Response<T>
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class ResponseParameters<T : Any>(
|
data class Response<T : Any>(
|
||||||
val ok: Boolean = false,
|
val ok: Boolean = false,
|
||||||
@Optional
|
@Optional
|
||||||
val description: String? = null,
|
val description: String? = null,
|
@ -4,7 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestException
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.*
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ResponseParameters
|
import com.github.insanusmokrassar.TelegramBotAPI.types.Response
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.*
|
||||||
@ -147,7 +147,7 @@ fun RequestsExecutor.startGettingOfUpdates(
|
|||||||
|
|
||||||
fun <T: Any> RequestsExecutor.executeAsync(
|
fun <T: Any> RequestsExecutor.executeAsync(
|
||||||
request: Request<T>,
|
request: Request<T>,
|
||||||
onFail: (suspend (ResponseParameters<*>) -> Unit)? = null,
|
onFail: (suspend (Response<*>) -> Unit)? = null,
|
||||||
scope: CoroutineScope = GlobalScope,
|
scope: CoroutineScope = GlobalScope,
|
||||||
onSuccess: (suspend (T) -> Unit)? = null
|
onSuccess: (suspend (T) -> Unit)? = null
|
||||||
): Job {
|
): Job {
|
||||||
|
Loading…
Reference in New Issue
Block a user