diff options
author | neodarz <neodarz@neodarz.net> | 2020-04-11 20:50:48 +0200 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2020-04-11 20:50:48 +0200 |
commit | 246fb448132fd3ea354d235f701d9c9248a20361 (patch) | |
tree | f15890cc922b6b317b01db8641cff0274e45ca3f /pyfunkwhale/client.py | |
parent | 47c7023dbaf5eb6682101b93f76e4c7b8acf4f56 (diff) | |
download | pyfunkwhale-246fb448132fd3ea354d235f701d9c9248a20361.tar.xz pyfunkwhale-246fb448132fd3ea354d235f701d9c9248a20361.zip |
Add more documentation
Diffstat (limited to 'pyfunkwhale/client.py')
-rw-r--r-- | pyfunkwhale/client.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/pyfunkwhale/client.py b/pyfunkwhale/client.py index 81611ba..2221a35 100644 --- a/pyfunkwhale/client.py +++ b/pyfunkwhale/client.py @@ -44,6 +44,10 @@ class Client(object): write_file(token_filename, self.token) def _get_token(self): + """ + Ask the user to go on the authorization page of the funkwhale instance + and then wait the response code for fetch the token generated. + """ print("For authorizate this app go to:\n{}".format( self.authorization_url)) self.authorization_code = input("Enter response code: ") @@ -54,6 +58,10 @@ class Client(object): client_secret=self.client_secret) def _refresh_token(self): + """ + Check if the token is expired in 60 seconds and if True will ask a new + token from the instance. + """ if time() - 60 > self.token["expires_at"]: self.token = self.oauth_client.refresh_token( self.token_endpoint, @@ -63,6 +71,25 @@ class Client(object): write_file(self.token_filename, self.token) def call(self, endpoint, method, params=None, data=None): + """ + Call the API + + Parameters + ---------- + endpoint : str + The endpoint to call on the API + method : str + The HTTP method to use for calling the endpoint + params : dict, optional + The uri params for a GET method + data : dict, optional + The uri data for a POST method + + Raises + ------ + requests.exceptions.HTTPError + If their is an error during requesting the API. + """ self._refresh_token() headers = {'Authorization': self.token['token_type'] + ' ' + self.token['access_token']} |