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

stexceed.WarframeMarKT.1.0.1.source-code.Requestable.kt Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
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