stexceed.WarframeMarKT.1.0.1.source-code.Requestable.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of WarframeMarKT Show documentation
Show all versions of WarframeMarKT Show documentation
Kotlin wrapper for api.warframe.market
import io.ktor.client.HttpClient
import io.ktor.client.features.cookies.cookies
import io.ktor.client.request.*
import io.ktor.http.ContentType
import io.ktor.http.HttpMethod
import io.ktor.http.contentType
import payload.PayloadContainer
interface Requestable {
val url: String
}
interface Get : Requestable {
suspend fun get(): ResponseType// = httpClient.requestUnwrapped(url, HttpMethod.Get)
}
interface Create : Requestable {
suspend fun create(payload: RequestType): ResponseType// = httpClient.requestUnwrapped(url, HttpMethod.Post)
}
interface Update : Requestable {
suspend fun update(payload: RequestType): ResponseType// = httpClient.requestUnwrapped(url, HttpMethod.Put)
}
interface Delete : Requestable {
suspend fun delete(): ResponseType// = httpClient.requestUnwrapped(url, HttpMethod.Delete)
}
private suspend inline fun HttpClient.requestUnwrapped(
url: String,
method: HttpMethod,
payload: Any? = null
) = request>(url) {
this.method = method
contentType(ContentType.Application.Json)
accept(ContentType.Application.Json)
header("language", WarframeMarket.language)
header("platform", WarframeMarket.platform)
val token = cookies(WarframeMarket.v1.auth.url + "/signin").find { it.name == "JWT" }!!.value
header("Authorization", "JWT $token")
if (payload != null) {
body = payload
}
}.payload
© 2015 - 2025 Weber Informatics LLC | Privacy Policy