pyzte5g/rest_framework.py
def _make_request(self, url: str, method: Literal['GET', 'POST']='GET', data: dict={}, remain_retries: int=0) -> dict:
        """
            Execute REST request to ZTE modem API.

            Arguments:
                url:
                    URL string pointing to REST endpoint.
                method:
                    Request method to use, either "GET" or "POST".
                data:
                    If method is "POST" this is the data packet that will be sent in the API request.
                remain_retries:
                    Integer specifying number of tries before failing on timeout.
            Returns:
                Dictionary Containing device values on "GET" and success or failure on "POST".
            Raises:
                TypeError:
                    If "url" is not a string.
                    OR "method" is not either "GET" or "POST".
                    OR "remain_retries" is not an integer.
        """

        if not isinstance(url, str):
            raise TypeError(f'"url" object must be passed as a string, not {type(url)}!')
        if method not in ['GET', 'POST']:
            raise TypeError(f'{method} is not a valid option, must be either "GET" or "POST"!')
        if not isinstance(remain_retries, int):
            raise TypeError(f'"remain_retries" object must be passed as an integer, not {type(url)}!')

        response = {}
        req_method = getattr(self, f'_method_request_{method.lower()}')()
        try:
            api_request = req_method(
                url=url,
                headers=self.headers,
                data=data,
                timeout=self.timeout,
            )
            response = api_request.json()
        except Timeout as e:
            if remain_retries and remain_retries <= 1:
                raise e
            elif not remain_retries:
                remain_retries = self.retries
            else:
                remain_retries -= 1
        except Exception as e:
            raise e
        if remain_retries and remain_retries >= 1:
            response = self._make_request(url=url, method=method, data=data, remain_retries=remain_retries)
        return response

            Execute REST request to ZTE modem API.

            Arguments:
                url:
                    URL string pointing to REST endpoint.
                method:
                    Request method to use, either "GET" or "POST".
                data:
                    If method is "POST" this is the data packet that will be sent in the API request.
                remain_retries:
                    Integer specifying number of tries before failing on timeout.
            Returns:
                Dictionary Containing device values on "GET" and success or failure on "POST".
            Raises:
                TypeError:
                    If "url" is not a string.
                    OR "method" is not either "GET" or "POST".
                    OR "remain_retries" is not an integer.
        
Execute REST request to ZTE modem API.
Execute REST request to ZTE modem API .
def _make_request(self, url: str, method: Literal['GET', 'POST']='GET', data: dict={}, remain_retries: int=0) -> dict:
        if not isinstance(url, str):
            raise TypeError(f'"url" object must be passed as a string, not {type(url)}!')
        if method not in ['GET', 'POST']:
            raise TypeError(f'{method} is not a valid option, must be either "GET" or "POST"!')
        if not isinstance(remain_retries, int):
            raise TypeError(f'"remain_retries" object must be passed as an integer, not {type(url)}!')
        response = {}
        req_method = getattr(self, f'_method_request_{method.lower()}')()
        try:
            api_request = req_method(
                url=url,
                headers=self.headers,
                data=data,
                timeout=self.timeout,
            )
            response = api_request.json()
        except Timeout as e:
            if remain_retries and remain_retries <= 1:
                raise e
            elif not remain_retries:
                remain_retries = self.retries
            else:
                remain_retries -= 1
        except Exception as e:
            raise e
        if remain_retries and remain_retries >= 1:
            response = self._make_request(url=url, method=method, data=data, remain_retries=remain_retries)
        return response
def _make_request ( self , url : str , method : Literal [ 'GET' , 'POST' ] = 'GET' , data : dict = { } , remain_retries : int = 0 ) -> dict : if not isinstance ( url , str ) : raise TypeError ( f'"url" object must be passed as a string, not {type(url)}!' ) if method not in [ 'GET' , 'POST' ] : raise TypeError ( f'{method} is not a valid option, must be either "GET" or "POST"!' ) if not isinstance ( remain_retries , int ) : raise TypeError ( f'"remain_retries" object must be passed as an integer, not {type(url)}!' ) response = { } req_method = getattr ( self , f'_method_request_{method.lower()}' ) ( ) try : api_request = req_method ( url = url , headers = self . headers , data = data , timeout = self . timeout , ) response = api_request . json ( ) except Timeout as e : if remain_retries and remain_retries <= 1 : raise e elif not remain_retries : remain_retries = self . retries else : remain_retries -= 1 except Exception as e : raise e if remain_retries and remain_retries >= 1 : response = self . _make_request ( url = url , method = method , data = data , remain_retries = remain_retries ) return response
Execute REST request to ZTE modem API.
Execute REST request to ZTE modem API .
"""
            Execute REST request to ZTE modem API.

            Arguments:
                url:
                    URL string pointing to REST endpoint.
                method:
                    Request method to use, either "GET" or "POST".
                data:
                    If method is "POST" this is the data packet that will be sent in the API request.
                remain_retries:
                    Integer specifying number of tries before failing on timeout.
            Returns:
                Dictionary Containing device values on "GET" and success or failure on "POST".
            Raises:
                TypeError:
                    If "url" is not a string.
                    OR "method" is not either "GET" or "POST".
                    OR "remain_retries" is not an integer.
        """
Dictionary Containing device values on "GET" and success or failure on "POST".
Dictionary Containing device values on " GET " and success or failure on " POST " .
If "url" is not a string.
OR "method" is not either "GET" or "POST".
OR "remain_retries" is not an integer.
If " url " is not a string . OR " method " is not either " GET " or " POST " . OR " remain_retries " is not an integer .
TypeError
self
url
str
URL string pointing to REST endpoint.
URL string pointing to REST endpoint .
method
Literal['GET', 'POST']
Request method to use, either "GET" or "POST".
Request method to use either " GET " or " POST " .
data
dict
If method is "POST" this is the data packet that will be sent in the API request.
If method is " POST " this is the data packet that will be sent in the API request .
remain_retries
int
Integer specifying number of tries before failing on timeout.
Integer specifying number of tries before failing on timeout .