mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
complete native integration
This commit is contained in:
parent
05c99642cb
commit
999efc64eb
@ -11,8 +11,8 @@ import kotlinx.serialization.json.Json
|
|||||||
/**
|
/**
|
||||||
* Represents default [BaseRequestsExecutor] working on [Ktor](https://ktor.io) [HttpClient]
|
* Represents default [BaseRequestsExecutor] working on [Ktor](https://ktor.io) [HttpClient]
|
||||||
*
|
*
|
||||||
* * On JS and JVM platforms it is [dev.inmo.tgbotapi.bot.ktor.base.DefaultKtorRequestsExecutor]
|
* * On JS, JVM and MingwX64 platforms it is [dev.inmo.tgbotapi.bot.ktor.base.DefaultKtorRequestsExecutor]
|
||||||
* * On LinuxX64 and MingwX64 it is [dev.inmo.tgbotapi.bot.ktor.base.MultipleClientKtorRequestsExecutor]
|
* * On LinuxX64 it is [dev.inmo.tgbotapi.bot.ktor.base.MultipleClientKtorRequestsExecutor]
|
||||||
*/
|
*/
|
||||||
expect class KtorRequestsExecutor (
|
expect class KtorRequestsExecutor (
|
||||||
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
||||||
|
@ -17,13 +17,11 @@ import kotlinx.serialization.json.Json
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This function is used in default constructor of [MultipleClientKtorRequestsExecutor] and on all non-native
|
* This function is used in default constructor of [MultipleClientKtorRequestsExecutor] and on all non-native
|
||||||
* platforms should return [HttpClient.config] call
|
* platforms and MingwX64 should return [client]
|
||||||
*
|
*
|
||||||
* On LinuxX64 it will create copy with Curl engine or throw an exception if engine is different with Curl
|
* On LinuxX64 it will create copy with Curl engine or throw an exception if engine is different with Curl
|
||||||
* On MingwX64 it will create copy with WinHttp engine or throw an exception if engine is different with WinHttp
|
|
||||||
*
|
*
|
||||||
* @throws IllegalArgumentException When pass non Curl-based [HttpClient] on LinuxX64 or non WinHttp-based [HttpClient]
|
* @throws IllegalArgumentException When pass non Curl-based [HttpClient] on LinuxX64
|
||||||
* on MingwX64
|
|
||||||
*/
|
*/
|
||||||
internal expect inline fun platformClientCopy(client: HttpClient): HttpClient
|
internal expect inline fun platformClientCopy(client: HttpClient): HttpClient
|
||||||
|
|
||||||
@ -31,7 +29,7 @@ internal expect inline fun platformClientCopy(client: HttpClient): HttpClient
|
|||||||
* Will use its parameters of constructor to create several [DefaultKtorRequestsExecutor] and use them in [execute]
|
* Will use its parameters of constructor to create several [DefaultKtorRequestsExecutor] and use them in [execute]
|
||||||
* and [close] operations
|
* and [close] operations
|
||||||
*
|
*
|
||||||
* This [BaseRequestsExecutor] has been created for native targets due to their inability of requests paralleling
|
* This [BaseRequestsExecutor] has been created for LinuxX64 target due to its inability of requests paralleling
|
||||||
*
|
*
|
||||||
* Under the hood on each [execute] it will take [DefaultKtorRequestsExecutor] and mark it as busy, execute
|
* Under the hood on each [execute] it will take [DefaultKtorRequestsExecutor] and mark it as busy, execute
|
||||||
* [Request], free up taken [DefaultKtorRequestsExecutor] and return (or throw) the result of execution
|
* [Request], free up taken [DefaultKtorRequestsExecutor] and return (or throw) the result of execution
|
||||||
|
@ -4,12 +4,10 @@ import io.ktor.client.*
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This function is used in default constructor of [MultipleClientKtorRequestsExecutor] and on all non-native
|
* This function is used in default constructor of [MultipleClientKtorRequestsExecutor] and on all non-native
|
||||||
* platforms should return [HttpClient.config] call
|
* platforms and MingwX64 should return [client]
|
||||||
*
|
*
|
||||||
* On LinuxX64 it will create copy with Curl engine or throw an exception if engine is different with Curl
|
* On LinuxX64 it will create copy with Curl engine or throw an exception if engine is different with Curl
|
||||||
* On MingwX64 it will create copy with WinHttp engine or throw an exception if engine is different with WinHttp
|
|
||||||
*
|
*
|
||||||
* @throws IllegalArgumentException When pass non Curl-based [HttpClient] on LinuxX64 or non WinHttp-based [HttpClient]
|
* @throws IllegalArgumentException When pass non Curl-based [HttpClient] on LinuxX64
|
||||||
* on MingwX64
|
|
||||||
*/
|
*/
|
||||||
internal actual inline fun platformClientCopy(client: HttpClient): HttpClient = client.config { }
|
internal actual inline fun platformClientCopy(client: HttpClient): HttpClient = client.config { }
|
||||||
|
@ -4,12 +4,10 @@ import io.ktor.client.*
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This function is used in default constructor of [MultipleClientKtorRequestsExecutor] and on all non-native
|
* This function is used in default constructor of [MultipleClientKtorRequestsExecutor] and on all non-native
|
||||||
* platforms should return [HttpClient.config] call
|
* platforms and MingwX64 should return [client]
|
||||||
*
|
*
|
||||||
* On LinuxX64 it will create copy with Curl engine or throw an exception if engine is different with Curl
|
* On LinuxX64 it will create copy with Curl engine or throw an exception if engine is different with Curl
|
||||||
* On MingwX64 it will create copy with WinHttp engine or throw an exception if engine is different with WinHttp
|
|
||||||
*
|
*
|
||||||
* @throws IllegalArgumentException When pass non Curl-based [HttpClient] on LinuxX64 or non WinHttp-based [HttpClient]
|
* @throws IllegalArgumentException When pass non Curl-based [HttpClient] on LinuxX64
|
||||||
* on MingwX64
|
|
||||||
*/
|
*/
|
||||||
internal actual inline fun platformClientCopy(client: HttpClient): HttpClient = client.config { }
|
internal actual inline fun platformClientCopy(client: HttpClient): HttpClient = client.config { }
|
||||||
|
@ -5,13 +5,11 @@ import io.ktor.client.engine.curl.*
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This function is used in default constructor of [MultipleClientKtorRequestsExecutor] and on all non-native
|
* This function is used in default constructor of [MultipleClientKtorRequestsExecutor] and on all non-native
|
||||||
* platforms should return [client]
|
* platforms and MingwX64 should return [client]
|
||||||
*
|
*
|
||||||
* On LinuxX64 it will create copy with Curl engine or throw an exception if engine is different with Curl
|
* On LinuxX64 it will create copy with Curl engine or throw an exception if engine is different with Curl
|
||||||
* On MingwX64 it will create copy with WinHttp engine or throw an exception if engine is different with WinHttp
|
|
||||||
*
|
*
|
||||||
* @throws IllegalArgumentException When pass non Curl-based [HttpClient] on LinuxX64 or non WinHttp-based [HttpClient]
|
* @throws IllegalArgumentException When pass non Curl-based [HttpClient] on LinuxX64
|
||||||
* on MingwX64
|
|
||||||
*/
|
*/
|
||||||
internal actual inline fun platformClientCopy(client: HttpClient): HttpClient = (client.engineConfig as? CurlClientEngineConfig) ?.let {
|
internal actual inline fun platformClientCopy(client: HttpClient): HttpClient = (client.engineConfig as? CurlClientEngineConfig) ?.let {
|
||||||
lateinit var config: HttpClientConfig<out CurlClientEngineConfig>
|
lateinit var config: HttpClientConfig<out CurlClientEngineConfig>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package dev.inmo.tgbotapi.bot.ktor
|
package dev.inmo.tgbotapi.bot.ktor
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.bot.ktor.base.MultipleClientKtorRequestsExecutor
|
import dev.inmo.tgbotapi.bot.ktor.base.DefaultKtorRequestsExecutor
|
||||||
|
|
||||||
actual typealias KtorRequestsExecutor = MultipleClientKtorRequestsExecutor
|
actual typealias KtorRequestsExecutor = DefaultKtorRequestsExecutor
|
||||||
|
@ -5,20 +5,10 @@ import io.ktor.client.engine.winhttp.*
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This function is used in default constructor of [MultipleClientKtorRequestsExecutor] and on all non-native
|
* This function is used in default constructor of [MultipleClientKtorRequestsExecutor] and on all non-native
|
||||||
* platforms should return [client]
|
* platforms and MingwX64 should return [client]
|
||||||
*
|
*
|
||||||
* On LinuxX64 it will create copy with Curl engine or throw an exception if engine is different with Curl
|
* On LinuxX64 it will create copy with Curl engine or throw an exception if engine is different with Curl
|
||||||
* On MingwX64 it will create copy with WinHttp engine or throw an exception if engine is different with WinHttp
|
|
||||||
*
|
*
|
||||||
* @throws IllegalArgumentException When pass non Curl-based [HttpClient] on LinuxX64 or non WinHttp-based [HttpClient]
|
* @throws IllegalArgumentException When pass non Curl-based [HttpClient] on LinuxX64
|
||||||
* on MingwX64
|
|
||||||
*/
|
*/
|
||||||
internal actual inline fun platformClientCopy(client: HttpClient): HttpClient = (client.engineConfig as? WinHttpClientEngineConfig) ?.let { engineConfig ->
|
internal actual inline fun platformClientCopy(client: HttpClient): HttpClient = client.config { }
|
||||||
lateinit var config: HttpClientConfig<out WinHttpClientEngineConfig>
|
|
||||||
client.config {
|
|
||||||
config = this as HttpClientConfig<out WinHttpClientEngineConfig>
|
|
||||||
}.close()
|
|
||||||
HttpClient(WinHttp) {
|
|
||||||
this.plusAssign(config)
|
|
||||||
}
|
|
||||||
} ?: throw IllegalArgumentException("On LinuxX64 TelegramBotAPI currently support only Curl Ktor HttpClient engine")
|
|
||||||
|
Loading…
Reference in New Issue
Block a user