Interactions¶
An Interaction is the most important element in the cyhole library because it is in charge to perform all the requests to an external API system.
As a conseguence, every external API implemented in cyhole has its own dedicated class that inherits from cyhole.core.interaction.Interaction class.
The structure of a standard Interaction is described by the image below:
Inside an Interaction there are two attributes identifying the clients responsable to perform the API calls:
client: object used for synchronous logic calls. This attribute is an object created by a class that inherits fromcyhole.core.client.APIClient.async_client: object used for asynchronous logic calls. This attribute is an object created by a class that inherits fromcyhole.core.client.AsyncAPIClient.
By looking to the image above, it is possibile to notice that the Interaction class has also a set of private methods, one for each implemented endpoint. All these methods are then also available in client and async_client to be used.
The idea beyond this architecture is to minimise the code repetition, every endopoint is identified by a private method inside Interaction class, and this method has all the required logic to hendle the dedicated API endopint call. In addition, the method can be executed in sync or async mode; for this reason the clients inside the interaction have implemented the corresponding method in non-private mode to be executed with the desired logic.
Example¶
Consider the Jupiter interaction and its GET endpoint Price.
The main class inherits from Interaction class and it has:
client: object created byJupiterClientclass that inherits fromAPIClient.async_client: object created byJupiterAsyncClientclass that inherits fromAsyncAPIClient.
The GET "Price" endopint is available as:
Jupiter._get_price: private version of the endpoint with all the logic.JupiterClient.get_price: synchronous logic call.JupiterAsyncClient.get_price: asynchronous logic call.