1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-06-03 00:15:27 +00:00
tgbotapi/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/TelegramAPIUrlsKeeper.kt

30 lines
769 B
Kotlin
Raw Normal View History

2020-10-04 11:06:30 +00:00
package dev.inmo.tgbotapi.utils
2019-07-25 08:25:18 +00:00
2020-11-06 06:07:46 +00:00
const val telegramBotAPIDefaultUrl = "https://api.telegram.org"
private inline val String.withoutLastSlash: String
get() {
var correctedUrl = this
while (true) {
val withoutSuffix = correctedUrl.removeSuffix("/")
if (withoutSuffix == correctedUrl) {
return correctedUrl
}
correctedUrl = withoutSuffix
}
}
2019-07-25 08:25:18 +00:00
class TelegramAPIUrlsKeeper(
token: String,
2020-11-06 06:07:46 +00:00
hostUrl: String = telegramBotAPIDefaultUrl
2019-07-25 08:25:18 +00:00
) {
val commonAPIUrl: String
val fileBaseUrl: String
init {
val correctedHost = hostUrl.withoutLastSlash
commonAPIUrl = "$correctedHost/bot$token"
fileBaseUrl = "$correctedHost/file/bot$token"
}
2019-07-25 08:25:18 +00:00
}