Requester

abstract class Requester(var host: String, var userId: String? = null, var userToken: String? = null, var debugMode: Boolean = false, val connectionTimeout: Long = DEFAULT_REQUEST_TIMEOUT.toLong(), val connectionErrorMessage: String, val enableCertificatesValidation: Boolean = false)

Deprecated

This class will be moved in the equinox-core module in the next version

The Requester class is useful to communicate with backend based on the SpringBoot framework

Author

N7ghtm4r3 - Tecknobit

Parameters

host

The host address where is running the backend

userId

The user identifier

userToken

The user token

debugMode

: whether the requester is still in development and who is developing needs the log of the requester's workflow, if it is enabled all the details of the requests sent and the errors occurred will be printed in the console

connectionTimeout

Time to keep alive request then throw the connection refused error

connectionErrorMessage

The error to send when a connection error occurred

enableCertificatesValidation

: whether enable the SSL certificates validation, this for example when the certificate is a self-signed certificate to by-pass

Inheritors

Constructors

Link copied to clipboard
constructor(host: String, userId: String? = null, userToken: String? = null, debugMode: Boolean = false, connectionTimeout: Long = DEFAULT_REQUEST_TIMEOUT.toLong(), connectionErrorMessage: String, enableCertificatesValidation: Boolean = false)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
protected val apiRequest: APIRequest

apiRequest -> the instance to communicate and make the requests to the backend

Link copied to clipboard
Link copied to clipboard
protected val connectionTimeout: Long
Link copied to clipboard
protected var debugMode: Boolean
Link copied to clipboard
protected val enableCertificatesValidation: Boolean = false
Link copied to clipboard
protected val headers: APIRequest.Headers

headers the headers used in the request

Link copied to clipboard
protected var host: String
Link copied to clipboard
private val initHost: () -> Unit

initHost Method to init correctly the host value

Link copied to clipboard
protected var interceptorAction: () -> Unit?

interceptorAction the action of the interceptor to execute when a request has been sent, if not specified is null by default and no interceptions will be executed

Link copied to clipboard

mustValidateCertificates flag whether the requests must validate the SSL certificates, this for example when the SSL is a self-signed certificate

Link copied to clipboard
protected val timeFormatter: TimeFormatter

timeFormatter the formatter used to format the timestamp values

Link copied to clipboard
protected var userId: String?
Link copied to clipboard
protected var userToken: String?

Functions

Link copied to clipboard
fun attachInterceptorOnRequest(interceptor: () -> Unit)

Method to attach a new interceptor to the Requester to execute it when a request has been sent

Link copied to clipboard
open fun changeHost(host: String)

Method to change, during the runtime for example when the session changed, the host address to make the requests

Link copied to clipboard
protected fun connectionErrorMessage(): JSONObject

Method to set the RESPONSE_STATUS_KEY to send when an error during the connection occurred

Link copied to clipboard
protected fun createPaginationQuery(page: Int, pageSize: Int): APIRequest.Params

Method to create the query with the pagination parameters

Link copied to clipboard
protected fun execDelete(endpoint: String, query: APIRequest.Params? = null, payload: APIRequest.Params? = null): JSONObject

Method to execute a RequestMethod.DELETE request to the backend

Link copied to clipboard
protected fun execGet(endpoint: String, query: APIRequest.Params? = null): JSONObject

Method to execute a RequestMethod.GET request to the backend

Link copied to clipboard
protected fun execMultipartRequest(endpoint: String, query: APIRequest.Params? = null, body: MultipartBody): JSONObject

Method to exec a multipart body request

Link copied to clipboard
protected fun execPatch(endpoint: String, query: APIRequest.Params? = null, payload: APIRequest.Params = Params()): JSONObject

Method to execute a RequestMethod.PATCH request to the backend

Link copied to clipboard
protected fun execPost(endpoint: String, query: APIRequest.Params? = null, payload: APIRequest.Params = Params()): JSONObject

Method to execute a RequestMethod.POST request to the backend

Link copied to clipboard
protected fun execPut(endpoint: String, query: APIRequest.Params? = null, payload: APIRequest.Params = Params()): JSONObject

Method to execute a RequestMethod.PUT request to the backend

Link copied to clipboard
private fun execRequest(method: APIRequest.RequestMethod, endpoint: String, query: APIRequest.Params? = null, payload: APIRequest.Params? = null): JSONObject

Method to execute a request to the backend

Link copied to clipboard
protected fun interceptRequest()

Method to execute the interceptorAction if it is specified by the attachInterceptorOnRequest method

Link copied to clipboard
private fun logError(exception: Exception)

Method to print a log of an exception occurred during a request sent if the debugMode is enabled

Link copied to clipboard
private fun logHeaders()

Method to log the current headers used in the requests

Link copied to clipboard
private fun logRequestInfo(requestUrl: String, requestPayloadInfo: () -> Unit, response: JSONObject?)

Method to print the details of the request sent if the debugMode is enabled

Link copied to clipboard
fun setConnectionTimeout(connectionTimeout: Long)

Method to set programmatically timeout for the requests

Link copied to clipboard
fun setUserCredentials(userId: String?, userToken: String?)

Method to set the user credentials used to make the authenticated requests

Link copied to clipboard
private fun validateSelfSignedCertificate(okHttpClient: OkHttpClient): OkHttpClient

Method to validate a self-signed SLL certificate and bypass the checks of its validity

No-any params required