Equinox Requester

abstract class EquinoxRequester(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) : Requester

Deprecated

This class will be moved in the Equinox-Compose library in the next version

The EquinoxRequester class is useful to communicate with backend based on the SpringBoot framework with the EquinoxUser requests pre-implemented

Author

N7ghtm4r3 - Tecknobit

Since

1.0.1

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

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)

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
protected fun assembleCustomEndpointPath(customEndpoint: String, subEndpoint: String = ""): String

Method to assemble the endpoint to make the request to the custom controllers

Link copied to clipboard
protected fun assembleUsersEndpointPath(endpoint: String = ""): String

Method to assemble the endpoint to make the request to the users controller

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 changeEmail(newEmail: String): JSONObject

Method to execute the request to change the email of the user

Link copied to clipboard
open override 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
open fun changeLanguage(newLanguage: String): JSONObject

Method to execute the request to change the language of the user

Link copied to clipboard
open fun changePassword(newPassword: String): JSONObject

Method to execute the request to change the password of the user

Link copied to clipboard
open fun changeProfilePic(profilePic: File): JSONObject

Method to execute the request to change the profile pic of the user

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
open fun deleteAccount(): JSONObject

Method to execute the request to delete the account of the user

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 open fun getSignInPayload(email: String, password: String, vararg custom: Any?): APIRequest.Params

Method to create the payload for the signIn request.

Link copied to clipboard
protected open fun getSignUpPayload(serverSecret: String, name: String, surname: String, email: String, password: String, language: String, vararg custom: Any?): APIRequest.Params

Method to create the payload for the signUp request.

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
open fun signIn(email: String, password: String, vararg custom: Any?): JSONObject

Method to execute the request to sign in the Equinox's system

Link copied to clipboard
fun signUp(serverSecret: String, name: String, surname: String, email: String, password: String, language: String, vararg custom: Any?): JSONObject

Method to execute the request to sign up in the Equinox's system

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