Add PATCH convenience method

This commit is contained in:
agatha 2023-09-08 21:30:54 -04:00
parent 5578fcc43e
commit d535e879ed
2 changed files with 15 additions and 0 deletions

View File

@ -14,6 +14,7 @@ convenience methods:
- `self.__get`
- `self.__post`
- `self.__put`
- `self.__patch`
- `self.__delete`
## Error Handling

View File

@ -104,6 +104,20 @@ class ApiWrapper:
except json.JSONDecodeError:
raise InvalidApiResponse('Invalid JSON received')
def __patch(self, endpoint, data=None):
url = self.base_url + endpoint
try:
response = self.session.put(url, data=data)
response.raise_for_status()
except requests.RequestException as e:
raise ApiRequestException(f'Failed to execute PATCH request: {str(e)}')
try:
return response.json()
except json.JSONDecodeError:
raise InvalidApiResponse('Invalid JSON received')
def __delete(self, endpoint):
url = self.base_url + endpoint