Skip to content

Commit 809e0d3

Browse files
committed
Added first version of delete op
1 parent 320172c commit 809e0d3

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

preston/preston.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,3 +388,44 @@ def post_op(self, id: str, path_data: Union[dict, None], post_data: Any) -> dict
388388
"""
389389
path = self._get_path_for_op_id(id)
390390
return self.post_path(path, path_data, post_data)
391+
392+
def delete_path(self, path: str, path_data: Union[dict, None]) -> dict:
393+
"""Deletes a resource in the ESI by an endpoint URL.
394+
395+
This method is not marked "private" as it _can_ be used
396+
by consuming code, but it's probably easier to call the
397+
`delete_op` method instead.
398+
399+
Args:
400+
path: raw ESI URL path
401+
path_data: data to format the path with (can be None)
402+
403+
Returns:
404+
ESI response data
405+
"""
406+
var_insert = self._insert_vars(path, path_data)
407+
path = var_insert[0]
408+
target_url = self.BASE_URL + path
409+
if len(var_insert[1]) > 0:
410+
req = requests.models.PreparedRequest()
411+
req.prepare_url(target_url, var_insert[1])
412+
target_url = req.url
413+
414+
self._try_refresh_access_token()
415+
resp = self.session.delete(target_url)
416+
if resp.text:
417+
return resp.json()
418+
return None
419+
420+
def delete_op(self, id: str, path_data: Union[dict, None]) -> dict:
421+
"""Deletes a resource in the ESI by looking up an operation id.
422+
423+
Args:
424+
id: operation id
425+
path_data: data to format the path with (can be None)
426+
427+
Returns:
428+
ESI response data
429+
"""
430+
path = self._get_path_for_op_id(id)
431+
return self.delete_path(path, path_data)

0 commit comments

Comments
 (0)