diff --git a/examples/animate.py b/examples/animate.py new file mode 100644 index 0000000..e2def95 --- /dev/null +++ b/examples/animate.py @@ -0,0 +1,11 @@ +from filestack import Client, Security + +# create security object +json_policy = {"expiry":1717101000,"call":["pick","read","stat","write","writeUrl","store","convert"]} +security = Security(json_policy, '') +APIKEY = '' + +client = Client(apikey=APIKEY, security=security) +transform = client.transform_external('/animate=fit:scale,width:200,height:300/[,]') +transform.animate(fit='scale',width=200,height=300,loop=0,delay=1000) +print(transform.url) diff --git a/examples/convert_pdf.py b/examples/convert_pdf.py new file mode 100644 index 0000000..b82f66f --- /dev/null +++ b/examples/convert_pdf.py @@ -0,0 +1,12 @@ +from filestack import Client, Security + +# create security object +json_policy = {"call":["pick","read","stat","write","writeUrl","store","convert"],"expiry":1717099200} +security = Security(json_policy, '') +APIKEY = '' + +client = Client(apikey=APIKEY, security=security) +transform = client.transform_external('pdfconvert=pageorientation:landscape/HANDLER') +transform.pdf_convert(pageorientation='landscape', pageformat='a4', metadata=True) +print(transform.url) + diff --git a/examples/createpdf.py b/examples/createpdf.py new file mode 100644 index 0000000..4a8cde2 --- /dev/null +++ b/examples/createpdf.py @@ -0,0 +1,12 @@ +from filestack import Client, Security + +# create security object +json_policy = {"call":["pick","read","stat","write","writeUrl","store","convert"],"expiry":1717099200} +security = Security(json_policy, '') +APIKEY = '' + +client = Client(apikey=APIKEY, security=security) +transform = client.transform_external('/pdfcreate/[,]') +transform.pdfcreate(engine='mupdf') +print(transform.url) + diff --git a/examples/doc_to_image.py b/examples/doc_to_image.py new file mode 100644 index 0000000..dd03ef4 --- /dev/null +++ b/examples/doc_to_image.py @@ -0,0 +1,11 @@ +from filestack import Client, Security + +# create security object +json_policy = {"call":["pick","read","stat","write","writeUrl","store","convert"],"expiry":1717099200} +security = Security(json_policy, '') +APIKEY = '' + +client = Client(apikey=APIKEY, security=security) +transform = client.transform_external('/doc_to_images/') +transform.doc_to_images(pages=[1], engine='imagemagick', format='png', quality=100, density=100, hidden_slides=False) +print(transform.url) diff --git a/examples/fallback.py b/examples/fallback.py new file mode 100644 index 0000000..a249750 --- /dev/null +++ b/examples/fallback.py @@ -0,0 +1,11 @@ +from filestack import Client, Security + +# create security object +json_policy = {"call":["pick","read","stat","write","writeUrl","store","convert"],"expiry":1717099200} +security = Security(json_policy, '') +APIKEY = '' + +client = Client(apikey=APIKEY, security=security) +transform = client.transform_external('/') +transform.fallback(file='HANDLER', cache=12) +print(transform.url) diff --git a/examples/smart_crop.py b/examples/smart_crop.py new file mode 100644 index 0000000..b49390f --- /dev/null +++ b/examples/smart_crop.py @@ -0,0 +1,11 @@ +from filestack import Client, Security + +# create security object +json_policy = {"call":["pick","read","stat","write","writeUrl","store","convert"],"expiry":1717099200} +security = Security(json_policy, '') +APIKEY = '' + +client = Client(apikey=APIKEY, security=security) +transform = client.transform_external('/smart_crop=width:100,height:100/HANDLER') +transform.smart_crop(width=100, height=100) +print(transform.url) diff --git a/filestack/mixins/imagetransformation.py b/filestack/mixins/imagetransformation.py index 62a6667..61332c8 100644 --- a/filestack/mixins/imagetransformation.py +++ b/filestack/mixins/imagetransformation.py @@ -117,13 +117,13 @@ def quality(self, value=None): def zip(self): return self._add_transform_task('zip', locals()) - def fallback(self, handle=None, cache=None): + def fallback(self, file=None, cache=None): return self._add_transform_task('fallback', locals()) def pdf_info(self, colorinfo=None): return self._add_transform_task('pdfinfo', locals()) - def pdf_convert(self, pageorientation=None, pageformat=None, pages=None): + def pdf_convert(self, pageorientation=None, pageformat=None, pages=None, metadata=None): return self._add_transform_task('pdfconvert', locals()) def minify_js(self, gzip=None, use_babel_polyfill=None, keep_fn_name=None, keep_class_name=None, @@ -153,6 +153,18 @@ def av_convert(self, *, preset=None, force=None, title=None, extname=None, filen def auto_image(self): return self._add_transform_task('auto_image', locals()) + def doc_to_images(self, pages=None, engine=None, format=None, quality=None, density=None, hidden_slides=None): + return self._add_transform_task('doc_to_images', locals()) + + def smart_crop(self, mode=None, width=None, height=None, fill_color=None, coords=None): + return self._add_transform_task('smart_crop', locals()) + + def pdfcreate(self, engine=None): + return self._add_transform_task('pdfcreate', locals()) + + def animate(self, delay=None, loop=None, width=None, height=None, fit=None, align=None, background=None): + return self._add_transform_task('animate', locals()) + def _add_transform_task(self, transformation, params): if isinstance(self, filestack.models.Transformation): instance = self diff --git a/tests/tasks_test.py b/tests/tasks_test.py new file mode 100644 index 0000000..50207be --- /dev/null +++ b/tests/tasks_test.py @@ -0,0 +1,47 @@ +import re + +import pytest +import responses + +from filestack import Transformation, AudioVisual +from filestack import config + +APIKEY = 'SOMEAPIKEY' +HANDLE = 'SOMEHANDLE' +EXTERNAL_URL = 'SOMEEXTERNALURL' + + +@pytest.fixture +def transform(): + return Transformation(apikey=APIKEY, external_url=EXTERNAL_URL) + + +def test_createpdf(transform): + target_url = '{}/{}/pdfcreate/{}/[v7MSSKswR0mvEwZS9LD0,Sr5CrtQPSs5TTZzor1Cw]'.format(config.CDN_URL, APIKEY, EXTERNAL_URL) + obj = transform.pdfcreate(engine='mupdf') + assert obj.url + +def test_animate(transform): + target_url = '{}/{}/animate=fit:scale,width:200,height:300/{}/[OjKeBAuBTIWygi1NE8fx,WTY6jjIaTPOvWY9KsNh9]'.format(config.CDN_URL, APIKEY, EXTERNAL_URL) + obj = transform.animate(fit='scale',width=200,height=300,loop=0,delay=1000) + assert obj.url + +def test_doc_to_images(transform): + target_url = '{}/{}/doc_to_images/{}/3zOWSOLQ0SEdphqVil9Q'.format(config.CDN_URL, APIKEY, EXTERNAL_URL) + obj = transform.doc_to_images(pages=[1], engine='imagemagick', format='png', quality=100, density=100, hidden_slides=False) + assert obj.url + +def test_smart_crop(transform): + target_url = '{}/{}/smart_crop=width:100,height:100/{}/v7MSSKswR0mvEwZS9LD0'.format(config.CDN_URL, APIKEY, EXTERNAL_URL) + obj = transform.smart_crop(width=100, height=100) + assert obj.url + +def test_pdf_convert(transform): + target_url = '{}/{}/pdfconvert=pageorientation:landscape/{}/3zOWSOLQ0SEdphqVil9Q'.format(config.CDN_URL, APIKEY, EXTERNAL_URL) + obj = transform.pdf_convert(pageorientation='landscape', pageformat='a4', metadata=True) + assert obj.url + +def test_fallback(transform): + target_url = '{}/{}/{}'.format(config.CDN_URL, APIKEY, EXTERNAL_URL) + obj = transform.fallback(file='3zOWSOLQ0SEdphqVil9Q', cache=12) + assert obj.url