Skip to content

Commit

Permalink
v2.0.4: add optional payload args
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielburnworth committed Sep 17, 2024
1 parent f296295 commit b88c789
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
24 changes: 16 additions & 8 deletions farmbot/functions/information.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ def __init__(self, state):
self.api = ApiConnect(state)
self.state = state

def api_get(self, endpoint, database_id=None, data_print=True):
def api_get(self, endpoint, database_id=None, payload=None, data_print=True):
"""Get information about a specific endpoint."""
self.state.print_status(
description=f"Retrieving {endpoint} information.")

endpoint_data = self.api.request("GET", endpoint, database_id)
endpoint_data = self.api.request(
method="GET",
endpoint=endpoint,
database_id=database_id,
payload=payload)

if data_print:
self.state.print_status(
Expand All @@ -45,40 +49,44 @@ def api_get(self, endpoint, database_id=None, data_print=True):

return endpoint_data

def api_patch(self, endpoint, new_data, database_id=None):
def api_patch(self, endpoint, payload, database_id=None):
"""Change information contained within an endpoint."""
self.state.print_status(description=f"Editing {endpoint}.")

result = self.api.request(
method="PATCH",
endpoint=endpoint,
database_id=database_id,
payload=new_data)
payload=payload)

self.state.print_status(update_only=True, endpoint_json=result)

return result

def api_post(self, endpoint, new_data):
def api_post(self, endpoint, payload=None):
"""Create new information contained within an endpoint."""
self.state.print_status(description=f"Adding new data to {endpoint}.")

result = self.api.request(
method="POST",
endpoint=endpoint,
database_id=None,
payload=new_data)
payload=payload)

self.state.print_status(update_only=True, endpoint_json=result)

return result

def api_delete(self, endpoint, database_id=None):
def api_delete(self, endpoint, database_id=None, payload=None):
"""Delete information contained within an endpoint."""
self.state.print_status(
description=f"Deleting {endpoint} with id={database_id}.")

result = self.api.request("DELETE", endpoint, database_id=database_id)
result = self.api.request(
method="DELETE",
endpoint=endpoint,
database_id=database_id,
payload=payload)

self.state.print_status(update_only=True, endpoint_json=result)

Expand Down
18 changes: 9 additions & 9 deletions farmbot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .functions.resources import Resources
from .functions.tools import ToolControls

VERSION = "2.0.3"
VERSION = "2.0.4"


class Farmbot():
Expand Down Expand Up @@ -143,21 +143,21 @@ def take_photo(self):

# information.py

def api_get(self, endpoint, database_id=None):
def api_get(self, endpoint, database_id=None, payload=None):
"""Get information about a specific endpoint."""
return self.info.api_get(endpoint, database_id)
return self.info.api_get(endpoint, database_id, payload)

def api_patch(self, endpoint, new_data, database_id=None):
def api_patch(self, endpoint, payload, database_id=None):
"""Change information contained within an endpoint."""
return self.info.api_patch(endpoint, new_data, database_id)
return self.info.api_patch(endpoint, payload, database_id)

def api_post(self, endpoint, new_data):
def api_post(self, endpoint, payload=None):
"""Create new information contained within an endpoint."""
return self.info.api_post(endpoint, new_data)
return self.info.api_post(endpoint, payload)

def api_delete(self, endpoint, database_id=None):
def api_delete(self, endpoint, database_id=None, payload=None):
"""Delete information contained within an endpoint."""
return self.info.api_delete(endpoint, database_id)
return self.info.api_delete(endpoint, database_id, payload)

def safe_z(self):
"""Returns the highest safe point along the z-axis."""
Expand Down

0 comments on commit b88c789

Please sign in to comment.