def request(self, path, params=None, method='GET'):
        '''API request / call method'''
        _start = time.time()

        if not path.startswith('/'):
            path = '/' + path

        resp = self._request_helper(self.api_endpoint + path, params, method)

        if resp.status_code != 200:
            if resp.status_code == 400:
                raise VultrError('Invalid API location. Check the URL that' +
                                 ' you are using')
            elif resp.status_code == 403:
                raise VultrError('Invalid or missing API key. Check that' +
                                 ' your API key is present and matches' +
                                 ' your assigned key')
            elif resp.status_code == 405:
                raise VultrError('Invalid HTTP method. Check that the' +
                                 ' method (POST|GET) matches what the' +
                                 ' documentation indicates')
            elif resp.status_code == 412:
                raise VultrError('Request failed. Check the response body ' +
                                 'for a more detailed description. Body: \n' +
                                 resp.text)
            elif resp.status_code == 500:
                raise VultrError('Internal server error. Try again at a' +
                                 ' later time')
            elif resp.status_code == 503:
                raise VultrError('Rate limit hit. API requests are limited' +
                                 ' to an average of 1/s. Try your request' +
                                 ' again later.')

        # very simplistic synchronous rate limiting;
        _elapsed = time.time() - _start
        if _elapsed < self.req_duration:
            time.sleep(self.req_duration - _elapsed)

        # return an empty json object if the API doesn't respond with a value.
        return resp.json() if resp.text else json_module.loads('{}')
def request ( self , path , params = None , method = 'GET' ) : _start = time . time ( ) if not path . startswith ( '/' ) : path = '/' + path resp = self . _request_helper ( self . api_endpoint + path , params , method ) if resp . status_code != 200 : if resp . status_code == 400 : raise VultrError ( 'Invalid API location. Check the URL that' + ' you are using' ) elif resp . status_code == 403 : raise VultrError ( 'Invalid or missing API key. Check that' + ' your API key is present and matches' + ' your assigned key' ) elif resp . status_code == 405 : raise VultrError ( 'Invalid HTTP method. Check that the' + ' method (POST|GET) matches what the' + ' documentation indicates' ) elif resp . status_code == 412 : raise VultrError ( 'Request failed. Check the response body ' + 'for a more detailed description. Body: \n' + resp . text ) elif resp . status_code == 500 : raise VultrError ( 'Internal server error. Try again at a' + ' later time' ) elif resp . status_code == 503 : raise VultrError ( 'Rate limit hit. API requests are limited' + ' to an average of 1/s. Try your request' + ' again later.' ) _elapsed = time . time ( ) - _start if _elapsed < self . req_duration : time . sleep ( self . req_duration - _elapsed ) return resp . json ( ) if resp . text else json_module . loads ( '{}' )
API request / call method