commonMain.com.huawei.hilink.c2c.integration.helper.api.HttpRequestMaker.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of helper-jvm Show documentation
Show all versions of helper-jvm Show documentation
The helper library streamlines the HiLink C2C integration and exposes a simple API.
package com.huawei.hilink.c2c.integration.helper.api
/**
* Sends either JsonApplication or UrlEncoded POST requests to a given address.
*
* Please implement those methods with your preferred way of sending http requests.
*/
public interface HttpRequestMaker {
/**
* Makes an ApplicationJson POST request.
*
* Used for sending events to HiLink console. It will be invoked when
* you call methods on [HiLinkHelper] like [HiLinkHelper.notifyDeviceStatusChange]
*
* @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
* @param consumer a callback with an [HttpResponse] containing response body and http code value.
* Contains [ResultConsumer.onSuccess] and [ResultConsumer.onError] functions.
*/
public fun postApplicationJsonRequest(
address: String,
authorizationHeader: String,
bodyJson: String,
consumer: HttpRequestMakersConsumer
)
/**
* 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)
* @param consumer a callback with an [HttpResponse] containing response body and http code value.
* Contains [ResultConsumer.onSuccess] and [ResultConsumer.onError] functions.
*/
public fun postUrlEncodedRequest(
address: String,
params: Map,
consumer: HttpRequestMakersConsumer
)
}