mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-23 00:57:13 +00:00
update defaults in telegramBot factories
This commit is contained in:
parent
b5334c2b72
commit
bf8f4c75f8
@ -13,7 +13,7 @@ import io.ktor.client.engine.*
|
||||
*/
|
||||
fun telegramBot(
|
||||
urlsKeeper: TelegramAPIUrlsKeeper,
|
||||
client: HttpClient
|
||||
client: HttpClient = HttpClient()
|
||||
): TelegramBot = telegramBot(urlsKeeper) {
|
||||
this.client = client
|
||||
}
|
||||
@ -66,7 +66,7 @@ inline fun telegramBot(
|
||||
inline fun telegramBot(
|
||||
token: String,
|
||||
apiUrl: String = telegramBotAPIDefaultUrl,
|
||||
client: HttpClient
|
||||
client: HttpClient = HttpClient()
|
||||
): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, apiUrl), client)
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
|
@ -16,33 +16,6 @@ import io.ktor.client.features.*
|
||||
import io.ktor.client.statement.readText
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
class KtorRequestsExecutorBuilder(
|
||||
var telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper
|
||||
) {
|
||||
var client: HttpClient = HttpClient()
|
||||
var callsFactories: List<KtorCallFactory> = emptyList()
|
||||
var excludeDefaultFactories: Boolean = false
|
||||
var requestsLimiter: RequestLimiter = ExceptionsOnlyLimiter()
|
||||
var jsonFormatter: Json = nonstrictJsonFormat
|
||||
|
||||
fun build() = KtorRequestsExecutor(telegramAPIUrlsKeeper, client, callsFactories, excludeDefaultFactories, requestsLimiter, jsonFormatter)
|
||||
}
|
||||
|
||||
inline fun telegramBot(
|
||||
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
||||
crossinline builder: KtorRequestsExecutorBuilder.() -> Unit = {}
|
||||
): TelegramBot = KtorRequestsExecutorBuilder(telegramAPIUrlsKeeper).apply(builder).build()
|
||||
|
||||
/**
|
||||
* Shortcut for [telegramBot]
|
||||
*/
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun telegramBot(
|
||||
token: String,
|
||||
apiUrl: String = telegramBotAPIDefaultUrl,
|
||||
crossinline builder: KtorRequestsExecutorBuilder.() -> Unit = {}
|
||||
): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, apiUrl), builder)
|
||||
|
||||
@RiskFeature
|
||||
fun createTelegramBotDefaultKtorCallRequestsFactories() = listOf(
|
||||
SimpleRequestCallFactory(),
|
||||
@ -127,3 +100,30 @@ class KtorRequestsExecutor(
|
||||
client.close()
|
||||
}
|
||||
}
|
||||
|
||||
class KtorRequestsExecutorBuilder(
|
||||
var telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper
|
||||
) {
|
||||
var client: HttpClient = HttpClient()
|
||||
var callsFactories: List<KtorCallFactory> = emptyList()
|
||||
var excludeDefaultFactories: Boolean = false
|
||||
var requestsLimiter: RequestLimiter = ExceptionsOnlyLimiter()
|
||||
var jsonFormatter: Json = nonstrictJsonFormat
|
||||
|
||||
fun build() = KtorRequestsExecutor(telegramAPIUrlsKeeper, client, callsFactories, excludeDefaultFactories, requestsLimiter, jsonFormatter)
|
||||
}
|
||||
|
||||
inline fun telegramBot(
|
||||
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
||||
builder: KtorRequestsExecutorBuilder.() -> Unit = {}
|
||||
): TelegramBot = KtorRequestsExecutorBuilder(telegramAPIUrlsKeeper).apply(builder).build()
|
||||
|
||||
/**
|
||||
* Shortcut for [telegramBot]
|
||||
*/
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun telegramBot(
|
||||
token: String,
|
||||
apiUrl: String = telegramBotAPIDefaultUrl,
|
||||
builder: KtorRequestsExecutorBuilder.() -> Unit = {}
|
||||
): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, apiUrl), builder)
|
||||
|
Loading…
Reference in New Issue
Block a user