Skip to content

Commit

Permalink
Merge pull request #8 from kbase/xfer-instructions
Browse files Browse the repository at this point in the history
Added transfer description and instructions fields.
  • Loading branch information
jeff-cohere authored Aug 14, 2024
2 parents 871b5b8 + 7de12f0 commit fae8cb8
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions dts/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,22 @@ def transfer(self,
file_ids = None,
source = None,
destination = None,
description = None,
timeout = None):
"""
`client.transfer(file_ids = None,
source = None,
destination = None,
description = None,
instructions = None,
timeout = None) -> UUID
* Submits a request to transfer files from a source to a destination database. the
files in the source database are identified by a list of string file_ids.
Optional arguments:
* description: a string containing Markdown text describing the transfer
* instructions: a dict representing a JSON object containing instructions
for processing the payload at its destination
"""
if not self.uri:
raise RuntimeError('dts.Client: not connected.')
Expand All @@ -253,13 +260,22 @@ def transfer(self,
raise TypeError('transfer: file_ids must be a list of string file IDs.')
if timeout and not isinstance(timeout, int) and not isinstance(timeout, float):
raise TypeError('transfer: timeout must be a number of seconds.')
if description and not isinstance(description, str):
raise TypeError('transfer: description must be a string containing Markdown.')
if instructions and not isinstance(instructions, dict):
raise TypeError('transfer: instructions must be a dict representing a JSON object containing machine-readable instructions for processing the payload at its destination.')
json_obj = {
'source': source,
'destination': destination,
'file_ids': file_ids,
}
if description:
json_obj['description'] = description
if instructions:
json_obj['instructions'] = instructions
try:
response = requests.post(url=f'{self.uri}/transfers',
json={
'source': source,
'destination': destination,
'file_ids': file_ids,
},
json=json_obj,
auth=self.auth,
timeout=timeout)
response.raise_for_status()
Expand Down

0 comments on commit fae8cb8

Please sign in to comment.