def _request(self, *args, **kwargs):
        """Make a signed request to the libcal API."""
        if not self.token:
            self._obtain_token()

        headers = {
            "Authorization": "Bearer {}".format(self.token)
        }

        # add authorization headers
        if "headers" in kwargs:
            kwargs["headers"].update(headers)
        else:
            kwargs["headers"] = headers

        # add api site to url
        args = list(args)
        if not args[1].startswith("http"):
            args[1] = "{}{}".format(API_URL, args[1])

        has_no_token = kwargs.get("no_token")
        if has_no_token:
            del kwargs["no_token"]
        resp = requests.request(*args, **kwargs)
        if resp.status_code == 401 and not has_no_token:
            self._obtain_token()
            kwargs["no_token"] = True
            self._request(*args, **kwargs)
        return resp
def _request ( self , * args , ** kwargs ) : if not self . token : self . _obtain_token ( ) headers = { "Authorization" : "Bearer {}" . format ( self . token ) } if "headers" in kwargs : kwargs [ "headers" ] . update ( headers ) else : kwargs [ "headers" ] = headers args = list ( args ) if not args [ 1 ] . startswith ( "http" ) : args [ 1 ] = "{}{}" . format ( API_URL , args [ 1 ] ) has_no_token = kwargs . get ( "no_token" ) if has_no_token : del kwargs [ "no_token" ] resp = requests . request ( * args , ** kwargs ) if resp . status_code == 401 and not has_no_token : self . _obtain_token ( ) kwargs [ "no_token" ] = True self . _request ( * args , ** kwargs ) return resp
Make a signed request to the libcal API.