SauceNaoAPI/src/jvmTest/kotlin/Launcher.kt

28 lines
669 B
Kotlin
Raw Normal View History

2020-12-02 08:39:54 +00:00
import dev.inmo.saucenaoapi.SauceNaoAPI
2022-05-14 07:43:28 +00:00
import io.ktor.client.HttpClient
2019-08-19 08:13:43 +00:00
import kotlinx.coroutines.*
2019-12-12 18:47:52 +00:00
import java.io.File
2019-02-20 12:18:01 +00:00
2019-10-12 06:30:02 +00:00
suspend fun main(vararg args: String) {
2019-12-12 18:47:52 +00:00
val (key, requestSubject) = args
2019-02-20 12:18:01 +00:00
2022-05-14 07:43:28 +00:00
val client = HttpClient()
val scope = CoroutineScope(Dispatchers.IO).also {
it.coroutineContext.job.invokeOnCompletion {
client.close()
}
}
2019-12-12 18:47:52 +00:00
2022-05-14 07:43:28 +00:00
val api = SauceNaoAPI(key, client, scope = scope)
println(
when {
requestSubject.startsWith("/") -> File(requestSubject).let {
api.request(it)
2019-12-12 18:47:52 +00:00
}
2022-05-14 07:43:28 +00:00
else -> api.request(requestSubject)
}
)
2019-12-12 18:47:52 +00:00
scope.cancel()
2019-02-20 12:18:01 +00:00
}