Skip to content

Commit

Permalink
docs: adding documentation to the function in db_client.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dfulmer committed Nov 5, 2024
1 parent 4125e07 commit 6999a06
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions aim/digifeeds/db_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ def __init__(self) -> None:
self.base_url = S.digifeeds_api_url

def get_item(self, barcode: str):
"""Get an item from the digifeeds database
Args:
barcode (str): Barcode of the item
Returns:
json: A response object
"""
url = self._url(f"items/{barcode}")
response = requests.get(url)
if response.status_code == 404:
Expand All @@ -16,19 +24,44 @@ def get_item(self, barcode: str):
return response.json()

def add_item(self, barcode: str):
"""Add an item to the digifeeds database
Args:
barcode (str): Barcode of the item
Returns:
json: A response object
"""
url = self._url(f"items/{barcode}")
response = requests.post(url)
if response.status_code != 200:
response.raise_for_status()
return response.json()

def get_or_add_item(self, barcode: str):
"""Gets or adds an item to the digifeeds database
Args:
barcode (str): Barcode of the item
Returns:
Object: An item
"""
item = self.get_item(barcode)
if not item:
item = self.add_item(barcode)
return item

def add_item_status(self, barcode: str, status: str):
"""Add a status to an item in the database
Args:
barcode (str): Barcode of the item
status (str): Status to add
Returns:
json: A response object
"""
url = self._url(f"items/{barcode}/status/{status}")
response = requests.put(url)
if response.status_code != 200:
Expand Down

0 comments on commit 6999a06

Please sign in to comment.