From f252fdf8a98c3c7ead02e5c25685706aba6d0689 Mon Sep 17 00:00:00 2001 From: Oliver Hilton Date: Mon, 4 Nov 2013 11:18:59 +0000 Subject: [PATCH 1/4] allow additional custom metadata in uploads --- setup.py | 2 +- src/thirdlight.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 04720a8..72fc28c 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name = "thirdlight", - version = "0.1.0", + version = "0.1.1", author = "ReThought Ltd", author_email = "code@rethought-solutions.com", url = "https://github.com/Rethought/thirdlight.git", diff --git a/src/thirdlight.py b/src/thirdlight.py index b7ad584..da0e577 100644 --- a/src/thirdlight.py +++ b/src/thirdlight.py @@ -212,7 +212,7 @@ def connect(self): self.session_key = response.sessionId def upload_image(self, source, folderId=None, folderPath=None, caption="", - keywords=[], block=True): + keywords=[], block=True, extra_meta={}): """Upload image at 'source' to folder with the given folderId and captioned and keyworded accordingly. Asynchronous upload, you get the uploadKey returned. @@ -272,6 +272,9 @@ def upload_image(self, source, folderId=None, folderPath=None, caption="", "data": b64, "metadata": {'caption': caption, 'keywords': keywords}, } + # Any additional file metadata to include in the upload + if extra_meta: + fileData['metadata'].update(extra_meta) fileData = dict(upload_file=fileData) self.Upload_AddFilesToUpload(uploadKey=uploadKey, fileData=fileData) From 295ef334349f322240ac135ac8c5475a259d8d59 Mon Sep 17 00:00:00 2001 From: Oliver Hilton Date: Mon, 4 Nov 2013 15:28:52 +0000 Subject: [PATCH 2/4] pass through any metadata keys in the create upload method --- setup.py | 2 +- src/thirdlight.py | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 72fc28c..8226e88 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name = "thirdlight", - version = "0.1.1", + version = "0.1.2", author = "ReThought Ltd", author_email = "code@rethought-solutions.com", url = "https://github.com/Rethought/thirdlight.git", diff --git a/src/thirdlight.py b/src/thirdlight.py index da0e577..332795a 100644 --- a/src/thirdlight.py +++ b/src/thirdlight.py @@ -252,9 +252,19 @@ def upload_image(self, source, folderId=None, folderPath=None, caption="", if folderId is None: folderId = self.resolve_folder_id(folderPath) - response = self.Upload_CreateUpload(params=dict(destination=folderId, - synchronous=False, - lifetime=60)) + edit_md = dict( + caption='OPTIONAL', + keywords='OPTIONAL' + ) + for key in extra_meta: + edit_md.update({key: 'OPTIONAL'}) + + response = self.Upload_CreateUpload(params=dict( + destination=folderId, + synchronous=False, + lifetime=60, + editablemetadata=edit_md + )) uploadKey = response.uploadKey # get the file base64 encoded - we'll look to sort out the big file From 0fca8c3a6d633a95ff7ff527c2de6aed0e127045 Mon Sep 17 00:00:00 2001 From: ojhilt Date: Tue, 15 Apr 2014 11:36:10 +0100 Subject: [PATCH 3/4] make compatible with new requests package --- setup.py | 2 +- src/thirdlight.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 8226e88..22cb91a 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name = "thirdlight", - version = "0.1.2", + version = "0.2.0", author = "ReThought Ltd", author_email = "code@rethought-solutions.com", url = "https://github.com/Rethought/thirdlight.git", diff --git a/src/thirdlight.py b/src/thirdlight.py index 332795a..045395c 100644 --- a/src/thirdlight.py +++ b/src/thirdlight.py @@ -194,7 +194,7 @@ def _query(self, **inParams): response = requests.post( self.thirdlight.api_url, data=json.dumps(params), - ).json + ).json() # note some methods return None - such as adding files to # an asynchronous upload. From a7287fe187949c7f3d5567fb96570395e823fa00 Mon Sep 17 00:00:00 2001 From: Oliver Hilton Date: Fri, 16 Jun 2017 11:27:40 +0100 Subject: [PATCH 4/4] enable impersonating a user for new api calls --- setup.py | 2 +- src/thirdlight.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 22cb91a..4e06b31 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name = "thirdlight", - version = "0.2.0", + version = "0.2.1", author = "ReThought Ltd", author_email = "code@rethought-solutions.com", url = "https://github.com/Rethought/thirdlight.git", diff --git a/src/thirdlight.py b/src/thirdlight.py index 045395c..58b03f2 100644 --- a/src/thirdlight.py +++ b/src/thirdlight.py @@ -108,7 +108,7 @@ class ThirdLight(object): API_VERSION = "1.0" FOLDER_TREE = None - def __init__(self, thirdlight_url, api_key): + def __init__(self, thirdlight_url, api_key, api_user=None): """ Construct a ThirdLight object which will hook into `api.json.tlx` at `thirdlight_url` which will likely be of the form @@ -117,6 +117,7 @@ def __init__(self, thirdlight_url, api_key): self.api_url = urllib.basejoin(thirdlight_url, ThirdLight.API_ENDPOINT) self.api_key = api_key + self.api_user = api_user self.session_key = None def _is_tl_method(self, name): @@ -211,6 +212,10 @@ def connect(self): response = self.Core_LoginWithKey(apikey=self.api_key) self.session_key = response.sessionId + if self.api_user: + response = self.Core_ImpersonateUser(userRef=self.api_user, lookupType='username') + self.session_key = response.sessionId + def upload_image(self, source, folderId=None, folderPath=None, caption="", keywords=[], block=True, extra_meta={}): """Upload image at 'source' to folder with the given folderId