![JAR search and dependency download from the Maven repository](/logo.png)
commonMain.com.huawei.hilink.c2c.integration.helper.callbackAdapters.HttpRequestMakerAdapters.kt Maven / Gradle / Ivy
package com.huawei.hilink.c2c.integration.helper.callbackAdapters
import com.huawei.hilink.c2c.integration.helper.HttpRequestMakingException
import com.huawei.hilink.c2c.integration.helper.api.HttpRequestMaker
import com.huawei.hilink.c2c.integration.helper.api.HttpRequestMakersConsumer
import com.huawei.hilink.c2c.integration.helper.api.HttpResponse
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine
/**
* Makes an ApplicationJson POST request.
*
* Used for sending events to HiLink console.
*
* @param address of the endpoint to send the request to
* @param authorizationHeader content of the Authorization header to be attached to the request
* @param bodyJson body for the request to be made
*
* @return a [HttpResponse] with response body and http code value.
*/
internal suspend fun HttpRequestMaker.postApplicationJsonRequestSuspending(
address: String,
authorizationHeader: String,
bodyJson: String
): HttpResponse =
suspendCoroutine {
postApplicationJsonRequest(address, authorizationHeader, bodyJson, object : HttpRequestMakersConsumer {
override fun onSuccess(result: HttpResponse) {
it.resume(result)
}
override fun onError() {
it.resumeWithException(HttpRequestMakingException())
}
})
}
/**
* Makes an UrlEncoded POST request.
*
* Used for Huawei OAuth flow, needed for events sending procedure.
*
* @param address of the endpoint to send the request to
* @param params a key-value map of parameters to include in the request (to encode in the url)
*
* @return a [HttpResponse] with response body and http code value.
*/
internal suspend fun HttpRequestMaker.postUrlEncodedRequestSuspending(
address: String,
params: Map
): HttpResponse =
suspendCoroutine {
postUrlEncodedRequest(address, params, object : HttpRequestMakersConsumer {
override fun onSuccess(result: HttpResponse) {
it.resume(result)
}
override fun onError() {
it.resumeWithException(HttpRequestMakingException())
}
})
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy