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

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 function to init correctly the host value

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 = "", query: String = ""): String

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

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

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

Link copied to clipboard
open fun changeEmail(newEmail: String): JSONObject

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

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

Function 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

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

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

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

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

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

Link copied to clipboard
protected fun connectionErrorMessage(): JSONObject

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

Link copied to clipboard
open fun deleteAccount(): JSONObject

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

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

Function to execute a RequestMethod.DELETE request to the backend

Link copied to clipboard
protected fun execGet(endpoint: String): JSONObject

Function to execute a RequestMethod.GET request to the backend

Link copied to clipboard
protected fun execMultipartRequest(endpoint: String, body: MultipartBody): JSONObject

Function to exec a multipart body request

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

Function to execute a RequestMethod.PATCH request to the backend

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

Function to execute a RequestMethod.POST request to the backend

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

Function to execute a RequestMethod.PUT request to the backend

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

Function to execute a request to the backend

Link copied to clipboard
protected open fun getSignInPayload(email: String, password: String, vararg custom: Any?): APIRequest.Params

Function 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

Function to create the payload for the signUp request.

Link copied to clipboard
private fun isSuccessfulResponse(response: JSONObject?): SocketManager.StandardResponseCode

Function to get whether the request has been successful or not

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

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

Link copied to clipboard
private fun logHeaders()

Function to log the current headers used in the requests

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

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

Link copied to clipboard
fun sendRequest(request: () -> JSONObject, onResponse: (JsonHelper) -> Unit, onConnectionError: (JsonHelper) -> Unit? = null)
fun sendRequest(request: () -> JSONObject, onSuccess: (JsonHelper) -> Unit, onFailure: (JsonHelper) -> Unit, onConnectionError: (JsonHelper) -> Unit? = null)

Function to execute and manage the response of a request

Link copied to clipboard
fun setConnectionTimeout(connectionTimeout: Long)

Function to set programmatically timeout for the requests

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

Function 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

Function 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

Function 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