commonMain.service.RestService.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kord-rest Show documentation
Show all versions of kord-rest Show documentation
Idiomatic Kotlin Wrapper for The Discord API
The newest version!
package dev.kord.rest.service
import dev.kord.rest.request.RequestBuilder
import dev.kord.rest.request.RequestHandler
import dev.kord.rest.route.Route
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
public abstract class RestService(@PublishedApi internal val requestHandler: RequestHandler) {
@PublishedApi
internal suspend inline fun call(route: Route, builder: RequestBuilder.() -> Unit = {}): T {
contract {
callsInPlace(builder, InvocationKind.EXACTLY_ONCE)
}
val interceptedBuilder = RequestBuilder(route).apply(builder)
requestHandler.intercept(interceptedBuilder)
val request = interceptedBuilder.build()
return requestHandler.handle(request)
}
}