Terarea  2
The automation project
Loading...
Searching...
No Matches
src.lib.actions.query_boilerplate.QueryEndpoint Class Reference
Collaboration diagram for src.lib.actions.query_boilerplate.QueryEndpoint:
Collaboration graph

Public Member Functions

None __init__ (self, str host="http://127.0.0.1", Union[int, None] port=6000, int delay=2, bool debug=False)
 
requests.Response get_endpoint (self, str path, Union[Dict[str, Any], None] content=None, Union[Mapping[str, str], None] header=None)
 
requests.Response post_endpoint (self, str path, Union[Dict[str, Any], None] content=None, Union[Mapping[str, str], None] header=None)
 
requests.Response put_endpoint (self, str path, Union[Dict[str, Any], None] content=None, Union[Mapping[str, str], None] header=None)
 
requests.Response patch_endpoint (self, str path, Union[Dict[str, Any], None] content=None, Union[Mapping[str, str], None] header=None)
 
requests.Response delete_endpoint (self, str path, Union[Dict[str, Any], None] content=None, Union[Mapping[str, str], None] header=None)
 
requests.Response head_endpoint (self, str path, Union[Dict[str, Any], None] content=None, Union[Mapping[str, str], None] header=None)
 
requests.Response options_endpoint (self, str path, Union[Dict[str, Any], None] content=None, Union[Mapping[str, str], None] header=None)
 
int get_status (self, requests.Response response)
 
str get_content_type (self, requests.Response response)
 
Dict[str, Union[str, bytes, Dict[str, Any], None]] get_content (self, requests.Response response)
 
Dict[str, Union[int, Dict[str, Union[str, bytes, Dict[str, Any], None]]]] compile_response_data (self, requests.Response response)
 

Data Fields

bool debug = debug
 
Disp disp
 

Protected Attributes

str _host = f"http://{host}"
 
 _delay = delay
 

Detailed Description

_summary_
    This is the class in charge of containing the boilerplate endpoint functions.

Definition at line 22 of file query_boilerplate.py.

Constructor & Destructor Documentation

◆ __init__()

None src.lib.actions.query_boilerplate.QueryEndpoint.__init__ ( self,
str host = "http://127.0.0.1",
Union[int, None] port = 6000,
int delay = 2,
bool debug = False )
_summary_
    Class in charge of containing the boilerplate endpoint functions to make queries to the web.

Args:
    host (_type_, optional): _description_. Defaults to "http://127.0.0.1".
    port (Union[int, None], optional): _description_. Defaults to 6000.
    delay (int, optional): _description_. Defaults to 2.
    debug (bool, optional): _description_. Defaults to False.

Definition at line 27 of file query_boilerplate.py.

Member Function Documentation

◆ compile_response_data()

Dict[str, Union[int, Dict[str, Union[str, bytes, Dict[str, Any], None]]]] src.lib.actions.query_boilerplate.QueryEndpoint.compile_response_data ( self,
requests.Response response )
Compile the response from an HTTP request into a dictionary.

Args:
    response (requests.Response): The HTTP response from the server.

Returns:
    Dict[str, Union[int, Dict[str, Union[str, bytes, Dict[str, Any], None]]]: A dictionary with the response status code and content.

Definition at line 341 of file query_boilerplate.py.

◆ delete_endpoint()

requests.Response src.lib.actions.query_boilerplate.QueryEndpoint.delete_endpoint ( self,
str path,
Union[Dict[str, Any], None] content = None,
Union[Mapping[str, str], None] header = None )
_summary_
    This function is in charge of sending a DELETE request to the server.
Args:
    path (str): _description_: The path of the endpoint.
    content (Union[Dict[str, Any], None], optional): _description_: The content to be sent to the server.
    header (Union[Mapping[str, str], None], optional): _description_: The header to be sent to the server. Defaults to None.
Returns:
    requests.Response: _description_: The response from the server.

Definition at line 173 of file query_boilerplate.py.

◆ get_content()

Dict[str, Union[str, bytes, Dict[str, Any], None]] src.lib.actions.query_boilerplate.QueryEndpoint.get_content ( self,
requests.Response response )
Retrieve and parse content from an HTTP response based on its Content-Type.

Args:
    response (requests.Response): The HTTP response from the server.

Raises:
    ValueError: If the response content is not valid JSON.

Returns:
    Dict[str, Union[str, bytes, Dict[str, Any], None]]: A dictionary with parsed response content.
    Contains two keys:
        - ACONST.CONTENT_TYPE_KEY: str - The content type of the response.
        - ACONST.CONTENT_KEY: Union[Dict[str, Any], str, bytes, None] - Parsed content.
            - JSON (application/json, application/ld+json) -> Dict
            - Text (text/html, text/plain, text/csv, text/xml) -> str
            - XML (application/xml) -> str
            - Binary data (e.g., application/octet-stream, application/pdf) -> bytes
            - None for unhandled types.

Definition at line 288 of file query_boilerplate.py.

◆ get_content_type()

str src.lib.actions.query_boilerplate.QueryEndpoint.get_content_type ( self,
requests.Response response )
_summary_
    This function is in charge of getting the content type from the response.

Args:
    response (requests.Response): _description_: The response from the server.

Raises:
    UnknownContentTypeError: _description_: If no content type is found in the header.

Returns:
    str: _description_: The content type from the response.

Definition at line 270 of file query_boilerplate.py.

◆ get_endpoint()

requests.Response src.lib.actions.query_boilerplate.QueryEndpoint.get_endpoint ( self,
str path,
Union[Dict[str, Any], None] content = None,
Union[Mapping[str, str], None] header = None )
_summary_
    This function is in charge of sending a GET request to the server.
Args:
    path (str): _description_: The path of the endpoint.
    content (Union[Dict[str, Any], None], optional): _description_: The content to be sent to the server.
    header (Union[Mapping[str, str], None], optional): _description_: The header to be sent to the server. Defaults to None.
Returns:
    requests.Response: _description_: The response from the server.

Definition at line 57 of file query_boilerplate.py.

◆ get_status()

int src.lib.actions.query_boilerplate.QueryEndpoint.get_status ( self,
requests.Response response )
_summary_
    This function is in charge of getting the status code from the response.
Args:
    response (requests.Response): _description_: The response from the server.
Returns:
    int: _description_: The status code from the response.

Definition at line 260 of file query_boilerplate.py.

◆ head_endpoint()

requests.Response src.lib.actions.query_boilerplate.QueryEndpoint.head_endpoint ( self,
str path,
Union[Dict[str, Any], None] content = None,
Union[Mapping[str, str], None] header = None )
_summary_
    This function is in charge of sending a HEAD request to the server.
Args:
    path (str): _description_: The path of the endpoint.
    content (Union[Dict[str, Any], None], optional): _description_: The content to be sent to the server.
    header (Union[Mapping[str, str], None], optional): _description_: The header to be sent to the server. Defaults to None.
Returns:
    requests.Response: _description_: The response from the server.

Definition at line 202 of file query_boilerplate.py.

◆ options_endpoint()

requests.Response src.lib.actions.query_boilerplate.QueryEndpoint.options_endpoint ( self,
str path,
Union[Dict[str, Any], None] content = None,
Union[Mapping[str, str], None] header = None )
_summary_
    This function is in charge of sending a OPTIONS request to the server.
Args:
    path (str): _description_: The path of the endpoint.
    content (Union[Dict[str, Any], None], optional): _description_: The content to be sent to the server.
    header (Union[Mapping[str, str], None], optional): _description_: The header to be sent to the server. Defaults to None.
Returns:
    requests.Response: _description_: The response from the server.

Definition at line 231 of file query_boilerplate.py.

◆ patch_endpoint()

requests.Response src.lib.actions.query_boilerplate.QueryEndpoint.patch_endpoint ( self,
str path,
Union[Dict[str, Any], None] content = None,
Union[Mapping[str, str], None] header = None )
_summary_
    This function is in charge of sending a PATCH request to the server.
Args:
    path (str): _description_: The path of the endpoint.
    content (Union[Dict[str, Any], None], optional): _description_: The content to be sent to the server.
    header (Union[Mapping[str, str], None], optional): _description_: The header to be sent to the server. Defaults to None.
Returns:
    requests.Response: _description_: The response from the server.

Definition at line 144 of file query_boilerplate.py.

◆ post_endpoint()

requests.Response src.lib.actions.query_boilerplate.QueryEndpoint.post_endpoint ( self,
str path,
Union[Dict[str, Any], None] content = None,
Union[Mapping[str, str], None] header = None )
_summary_
    This function is in charge of sending a POST request to the server.
Args:
    path (str): _description_: The path of the endpoint.
    content (Union[Dict[str, Any], None], optional): _description_: The content to be sent to the server.
    header (Union[Mapping[str, str], None], optional): _description_: The header to be sent to the server. Defaults to None.
Returns:
    requests.Response: _description_: The response from the server.

Definition at line 86 of file query_boilerplate.py.

◆ put_endpoint()

requests.Response src.lib.actions.query_boilerplate.QueryEndpoint.put_endpoint ( self,
str path,
Union[Dict[str, Any], None] content = None,
Union[Mapping[str, str], None] header = None )
_summary_
    This function is in charge of sending a PUT request to the server.
Args:
    path (str): _description_: The path of the endpoint.
    content (Union[Dict[str, Any], None], optional): _description_: The content to be sent to the server.
    header (Union[Mapping[str, str], None], optional): _description_: The header to be sent to the server. Defaults to None.
Returns:
    requests.Response: _description_: The response from the server.

Definition at line 115 of file query_boilerplate.py.

Field Documentation

◆ _delay

src.lib.actions.query_boilerplate.QueryEndpoint._delay = delay
protected

Definition at line 46 of file query_boilerplate.py.

◆ _host

str src.lib.actions.query_boilerplate.QueryEndpoint._host = f"http://{host}"
protected

Definition at line 39 of file query_boilerplate.py.

◆ debug

bool src.lib.actions.query_boilerplate.QueryEndpoint.debug = debug

Definition at line 37 of file query_boilerplate.py.

◆ disp

Disp src.lib.actions.query_boilerplate.QueryEndpoint.disp
Initial value:
= Disp(
TOML_CONF,
SAVE_TO_FILE,
FILE_NAME,
FILE_DESCRIPTOR,
debug=self.debug,
logger=self.__class__.__name__
)

Definition at line 48 of file query_boilerplate.py.


The documentation for this class was generated from the following file: