diff --git a/sendsafely/SendSafely.py b/sendsafely/SendSafely.py index 5a1e3c1..49e941e 100644 --- a/sendsafely/SendSafely.py +++ b/sendsafely/SendSafely.py @@ -14,7 +14,7 @@ from pgpy.constants import KeyFlags, HashAlgorithm, SymmetricKeyAlgorithm, CompressionAlgorithm, PubKeyAlgorithm from sendsafely.Package import Package from sendsafely.exceptions import GetPackagesException, GetUserInformationException, TrustedDeviceException, \ - DeletePackageException, GetPackageInformationFailedException, GetKeycodeFailedException + DeletePackageException, GetPackageInformationFailedException, GetKeycodeFailedException, MoveFileException from sendsafely.utilities import make_headers, _get_string_from_file @@ -268,3 +268,19 @@ def get_sent_packages(self, row_index=0, page_size=100): row_index += page_size except Exception as e: GetPackagesException(details=str(e)) + + def move_file(self, package_id, file_id, destination_directory_id): + """ + Moves the file with the specified id to the directory with the specified ID + """ + endpoint = "/package/" + package_id + "/directory/" + destination_directory_id + "/file/" + file_id + url = self.BASE_URL + endpoint + headers = make_headers(self.API_SECRET, self.API_KEY, endpoint) + try: + response = requests.post(url=url, headers=headers).json() + except Exception as e: + raise MoveFileException(details=e) + + if response["response"] != "SUCCESS": + raise MoveFileException(details=response["message"]) + return response diff --git a/sendsafely/exceptions.py b/sendsafely/exceptions.py index 2920a63..3600eec 100644 --- a/sendsafely/exceptions.py +++ b/sendsafely/exceptions.py @@ -44,6 +44,17 @@ def __init__(self, details=None): display = self.message super().__init__(display) +class MoveFileException(Exception): + """Exception raised during file movement. + """ + def __init__(self, details=None): + self.message = "An error occurred during file movement." + self.details = details + display = self.details + if display is None: + display = self.message + super().__init__(display) + class FinalizePackageFailedException(Exception): """Exception raised while finalizing package.