feat(api): expose response info in requests
This commit is contained in:
parent
48b69c88a9
commit
db1f469a4f
3 changed files with 20 additions and 5 deletions
|
|
@ -0,0 +1,15 @@
|
|||
package moe.lava.neon.api
|
||||
|
||||
import io.ktor.client.call.body
|
||||
import io.ktor.client.statement.HttpResponse
|
||||
import io.ktor.util.reflect.TypeInfo
|
||||
import io.ktor.util.reflect.typeInfo
|
||||
|
||||
class ApiResponse<T>(
|
||||
val response: HttpResponse,
|
||||
private val bodyType: TypeInfo,
|
||||
) {
|
||||
suspend fun body() = response.body(bodyType) as T
|
||||
}
|
||||
|
||||
inline fun <reified T> HttpResponse.wrap() = ApiResponse<T>(this, typeInfo<T>())
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
package moe.lava.neon.api.endpoints
|
||||
|
||||
import io.ktor.client.call.body
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.request.header
|
||||
import io.ktor.client.request.parameter
|
||||
|
|
@ -8,6 +7,7 @@ import io.ktor.client.request.post
|
|||
import io.ktor.client.request.setBody
|
||||
import kotlinx.serialization.Serializable
|
||||
import moe.lava.neon.api.ApiClient
|
||||
import moe.lava.neon.api.wrap
|
||||
|
||||
@Serializable
|
||||
data class ExperimentResponse(
|
||||
|
|
@ -35,7 +35,7 @@ data class LoginResponse(
|
|||
|
||||
suspend fun ApiClient.getExperiments() = client.get("experiments") {
|
||||
parameter("with_guild_experiments", "true")
|
||||
}.body<ExperimentResponse>()
|
||||
}.wrap<ExperimentResponse>()
|
||||
|
||||
suspend fun ApiClient.login(email: String, password: String, fingerprint: String) = client.post("auth/login") {
|
||||
header("X-Fingerprint", fingerprint)
|
||||
|
|
@ -43,4 +43,4 @@ suspend fun ApiClient.login(email: String, password: String, fingerprint: String
|
|||
login = email,
|
||||
password = password,
|
||||
))
|
||||
}.body<LoginResponse>()
|
||||
}.wrap<LoginResponse>()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue