Connector¶
cyhole.core.interaction
¶
Interaction
¶
Interaction(headers: Any | None = None)
This class is the building block for a new integration of an external API in cyhole library,
and every new external API must be identified by a class that inherits from this class.
Inside an Interaction there are two attributes identifying the clients responsable to
perform the API calls:
client: object used for synchronous logic.async_client: object used for asynchronous logic.
During the creation of the object is possible to specify some global configurations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
headers
|
Any | None
|
headers used globally in all API requests. |
None
|
Source code in src/cyhole/core/interaction.py
24 25 26 27 28 29 30 31 | |
api_return_model
¶
api_return_model(
sync: bool,
type: str,
url: str,
response_model: Type[ResponseModel],
*args: tuple,
**kwargs: Any
) -> ResponseModel | Coroutine[None, None, ResponseModel]
This function is used to execute a request to the API by forwarding the call to the
corresponding client (synchronous or asynchronous) according to the sync parameter.
This function is used to avoid code duplication in the methods of the Interaction classes,
and it assumes that the response of the API request is a JSON object that can be parsed into
a pydantic.BaseModel model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sync
|
bool
|
boolean to define if the request is synchronous or asynchronous. |
required |
type
|
str
|
request's type ( |
required |
url
|
str
|
the URL of the API endpoint. |
required |
response_model
|
Type[ResponseModel]
|
the |
required |
args
|
tuple
|
the positional arguments to be passed to the API request. |
()
|
kwargs
|
Any
|
the named arguments to be passed to the API request. |
{}
|
Returns:
| Type | Description |
|---|---|
ResponseModel | Coroutine[None, None, ResponseModel]
|
The response of the API request. If the request is synchronous, the response is a |
ResponseModel | Coroutine[None, None, ResponseModel]
|
|
ResponseModel | Coroutine[None, None, ResponseModel]
|
that will return a |
Source code in src/cyhole/core/interaction.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |