All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.wulkanowy.sdk.hebe.repository.RoutingRulesRepository.kt Maven / Gradle / Ivy

Go to download

Unified way of retrieving data from the UONET+ register through mobile api and scraping api

There is a newer version: 2.7.0
Show newest version
package io.github.wulkanowy.sdk.hebe.repository

import io.github.wulkanowy.sdk.hebe.exception.InvalidTokenException
import io.github.wulkanowy.sdk.hebe.exception.UnknownTokenException
import io.github.wulkanowy.sdk.hebe.service.RoutingRulesService

internal class RoutingRulesRepository(private val api: RoutingRulesService) {

    suspend fun getRouteByToken(token: String): String {
        if (token.length < 4) throw InvalidTokenException("Token '$token' is too short")

        val tokenSymbol = token.substring(0..2)

        if ("FK1" == tokenSymbol) return "https://api.fakelog.cf"

        return api.getRoutingRules()
            .split("\r?\n".toRegex())
            .singleOrNull { tokenSymbol == it.substringBefore(",") }
            ?.substringAfter(",")
            ?: throw UnknownTokenException("This token: '$token' is unsupported")
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy