diff options
author | xTITUSMAXIMUSX <chad@chadhigh.com> | 2024-03-01 14:09:50 -0600 |
---|---|---|
committer | xTITUSMAXIMUSX <chad@chadhigh.com> | 2024-03-01 14:09:50 -0600 |
commit | cecc7ddc74bec0c659ced4e86d1a1ebbf02d23a6 (patch) | |
tree | 65cb87b71e623a59abd67ffb1c1612a86f885b75 /pyvyos/device.py | |
parent | 067511871fc6f870aadb16be1ec108427d7881cd (diff) | |
download | pyvyos-cecc7ddc74bec0c659ced4e86d1a1ebbf02d23a6.tar.gz pyvyos-cecc7ddc74bec0c659ced4e86d1a1ebbf02d23a6.zip |
Updated _get_payload for multi command supprot
Diffstat (limited to 'pyvyos/device.py')
-rw-r--r-- | pyvyos/device.py | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/pyvyos/device.py b/pyvyos/device.py index cc87a32..da3f064 100644 --- a/pyvyos/device.py +++ b/pyvyos/device.py @@ -104,27 +104,40 @@ class VyDevice: Returns: dict: The payload for the API request. """ - data = { - 'op': op, - 'path': path - } + if isinstance(path, str): + path = [path] + + if isinstance(path, list) and len(path) == 1: + # If path is a list and contains only one element, use it directly + data = {'op': op, 'path': path[0]} + else: + data = [] + current_command = {'op': op, 'path': []} + for p in path: + if isinstance(p, list): + # If the current item is a list, merge it into the current command + if current_command['path']: + data.append(current_command) + current_command = {'op': op, 'path': p} + else: + # Otherwise, add the item to the current command's path + current_command['path'].append(p) + + # Add the last command to data + if current_command['path']: + data.append(current_command) - if file is not None: - data['file'] = file - - if url is not None: - data['url'] = url - - if name is not None: - data['name'] = name - payload = { 'data': json.dumps(data), 'key': self.apikey } + if url is not None: + payload['url'] = url + return payload + def _api_request(self, command, op, path=[], method='POST', file=None, url=None, name=None): """ Make an API request. |