From e6bfdae4c75ed4697e1ae5a625555b672da3a34d Mon Sep 17 00:00:00 2001 From: Anthony Date: Wed, 29 Jul 2020 01:17:01 +0100 Subject: [PATCH] Fixes for Resources interface --- README.md | 16 ++++++++++------ dink/resources.py | 14 +++----------- setup.py | 2 +- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 486ba87..481291f 100644 --- a/README.md +++ b/README.md @@ -24,11 +24,15 @@ import zipfile client = dink.Client('your_api_key...') -assets = zipfile.ZipFile() -assets.write('includes/footer.html') -assets.write('css/document.css') -assets.write('images/logo.png') -assets.write('fonts/company-font.otf') +assets = io.BytesIO() +with zipfile.ZipFile(assets, mode='w', compression=zipfile.ZIP_DEFLATED) as z: + + z.write('includes/footer.html') + z.write('css/document.css') + z.write('images/logo.png') + z.write('fonts/company-font.otf') + +assets.seek(0) pdfs = dink.resources.PDF.create( client, @@ -81,7 +85,7 @@ pdfs = dink.resources.PDF.create( ).to_json_type() } }, - global_vars={ + global_args={ 'title': 'Weekly sales report' }, assets=assets diff --git a/dink/resources.py b/dink/resources.py index 676a249..09901de 100644 --- a/dink/resources.py +++ b/dink/resources.py @@ -53,7 +53,7 @@ def create(cls, client, template_html, document_args, - global_vars=None, + global_args=None, assets=None ): """ @@ -64,14 +64,6 @@ def create(cls, feature `store_key` and `uid` attributes but an `error` attribute. """ - if isinstance(assets, zipfile.ZipFile): - - # Convert the assets archive to a file we can send to the server - f = io.BytesIO() - assets.write(f) - f.seek(0) - asset = f - results = client( 'put', f'pdfs', @@ -79,8 +71,8 @@ def create(cls, data={ 'template_html': template_html, 'document_args': json.dumps(document_args), - 'global_vars': json.dumps(global_vars) \ - if global_vars else None + 'global_args': json.dumps(global_args) \ + if global_args else None } ) diff --git a/setup.py b/setup.py index a3af2aa..4d7e0c0 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ # Versions should comply with PEP440. For a discussion on single-sourcing # the version across setup.py and the project code, see # https://packaging.python.org/en/latest/single_source_version.html - version='0.0.3', + version='0.0.4', description=( 'The DInk Python library provides a pythonic interface to the DInk ' 'API.',