Skip to content

Commit

Permalink
docs: add docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMarble committed Aug 28, 2021
1 parent 515f2aa commit 2406a54
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions datadis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@


def get_token(username: str, password: str) -> str:
"""Get authentication token for private api
Args:
username (str): NIF/NIE associated with the account
password (str): Password for the account
Raises:
Exception: If the authentication fails
Returns:
str: Bearer token
"""
credentials = {'username': username, 'password': password}
r = requests.post(_ENDPOINTS['get_token'], data=credentials)
if r.status_code == 200:
Expand All @@ -18,6 +30,17 @@ def get_token(username: str, password: str) -> str:


def get_supplies(token: str) -> dict:
"""Search all the supplies
Args:
token (str): Bearer token
Raises:
Exception: If the authentication fails
Returns:
dict: A dictionary with the supplies
"""
headers = {'Authorization': f'Bearer {token}'}
r = requests.get(_ENDPOINTS['get_supplies'], headers=headers)
if r.status_code == 200:
Expand All @@ -27,6 +50,19 @@ def get_supplies(token: str) -> dict:


def get_contract_detail(token: str, cups: str, distributorCode: int) -> dict:
"""Search the contract detail
Args:
token (str): Bearer token
cups (str): Cups code. Get it from get_supplies
distributorCode (int): Distributor code. Get it from get_supplies
Raises:
Exception: [description]
Returns:
dict: [description]
"""
headers = {'Authorization': f'Bearer {token}'}

r = requests.get(_ENDPOINTS['get_contract_detail']
Expand Down

0 comments on commit 2406a54

Please sign in to comment.