Connector¶
cyhole.core.client
¶
APIClientInterface
¶
The following abstract class defines a general Client API. A client is used in order to connect and interact with an external API.
The key method of an API client is the api function that is used
to execute the actual requests.
api
abstractmethod
¶
api(
type: str,
url: str,
*args: tuple,
**kwargs: dict[str, Any]
) -> (
requests.Response
| Coroutine[None, None, requests.Response]
)
Function in charge to execute a request to an API endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type
|
str
|
request's type ( |
required |
url
|
str
|
API endpoint. |
required |
args
|
tuple
|
additional input parameters to provided. |
()
|
kwargs
|
dict[str, Any]
|
additional input parameters to provided. |
{}
|
Returns:
| Type | Description |
|---|---|
requests.Response | Coroutine[None, None, requests.Response]
|
The response object structured as |
Raises:
| Type | Description |
|---|---|
RequestTypeNotSupported
|
if the request type is not a valid value of |
AuthorizationAPIKeyError
|
if the response return a 401 code. |
Source code in src/cyhole/core/client.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
APIClient
¶
APIClient(
interaction: Interaction, headers: Any | None = None
)
Bases: APIClientInterface
flowchart TD
cyhole.core.client.APIClient[APIClient]
cyhole.core.client.APIClientInterface[APIClientInterface]
cyhole.core.client.APIClientInterface --> cyhole.core.client.APIClient
click cyhole.core.client.APIClient href "" "cyhole.core.client.APIClient"
click cyhole.core.client.APIClientInterface href "" "cyhole.core.client.APIClientInterface"
This client is designed to manage all the REST calls to an external API by using requests module.
Info
As a conseguence of using requests module, this client can be used to perform
the API requests in synchronous logic and achieve the parallelism by using threads.
Use this class as middlelayer to manage all the requests to an external API.
By default, all new Interaction should have the synchronous client that inherits from this class.
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/client.py
71 72 73 74 | |
AsyncAPIClient
¶
AsyncAPIClient(
interaction: Interaction, headers: Any | None = None
)
Bases: APIClientInterface
flowchart TD
cyhole.core.client.AsyncAPIClient[AsyncAPIClient]
cyhole.core.client.APIClientInterface[APIClientInterface]
cyhole.core.client.APIClientInterface --> cyhole.core.client.AsyncAPIClient
click cyhole.core.client.AsyncAPIClient href "" "cyhole.core.client.AsyncAPIClient"
click cyhole.core.client.APIClientInterface href "" "cyhole.core.client.APIClientInterface"
This client is designed to manage all the REST calls to an external API by using aiohttp module.
Info
As a conseguence of using aiohttp module, this client can be used to perform
the API requests in asynchronous logic of async paradigm.
Use this class as middlelayer to manage all the requests to an external API.
By default, all new Interaction should have the asynchronous client that inherits from this class.
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/client.py
115 116 117 118 119 | |
__aenter__
async
¶
__aenter__()
Open a new session.
Source code in src/cyhole/core/client.py
121 122 123 124 | |
__aexit__
async
¶
__aexit__(exc_type, exc_value, exc_traceback)
Exits from the session.
Source code in src/cyhole/core/client.py
126 127 128 129 | |
is_connected
¶
is_connected() -> bool
Check if the session is available.
Source code in src/cyhole/core/client.py
131 132 133 134 135 | |
connect
¶
connect() -> None
Init a new session.
Source code in src/cyhole/core/client.py
137 138 139 140 141 | |
close
async
¶
close() -> None
Close current available session.
Source code in src/cyhole/core/client.py
143 144 145 146 147 148 149 150 151 152 | |