Skip to content

Commit e6bfdae

Browse files
committed
Fixes for Resources interface
1 parent dd1b3a4 commit e6bfdae

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ import zipfile
2424

2525
client = dink.Client('your_api_key...')
2626

27-
assets = zipfile.ZipFile()
28-
assets.write('includes/footer.html')
29-
assets.write('css/document.css')
30-
assets.write('images/logo.png')
31-
assets.write('fonts/company-font.otf')
27+
assets = io.BytesIO()
28+
with zipfile.ZipFile(assets, mode='w', compression=zipfile.ZIP_DEFLATED) as z:
29+
30+
z.write('includes/footer.html')
31+
z.write('css/document.css')
32+
z.write('images/logo.png')
33+
z.write('fonts/company-font.otf')
34+
35+
assets.seek(0)
3236

3337
pdfs = dink.resources.PDF.create(
3438
client,
@@ -81,7 +85,7 @@ pdfs = dink.resources.PDF.create(
8185
).to_json_type()
8286
}
8387
},
84-
global_vars={
88+
global_args={
8589
'title': 'Weekly sales report'
8690
},
8791
assets=assets

dink/resources.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def create(cls,
5353
client,
5454
template_html,
5555
document_args,
56-
global_vars=None,
56+
global_args=None,
5757
assets=None
5858
):
5959
"""
@@ -64,23 +64,15 @@ def create(cls,
6464
feature `store_key` and `uid` attributes but an `error` attribute.
6565
"""
6666

67-
if isinstance(assets, zipfile.ZipFile):
68-
69-
# Convert the assets archive to a file we can send to the server
70-
f = io.BytesIO()
71-
assets.write(f)
72-
f.seek(0)
73-
asset = f
74-
7567
results = client(
7668
'put',
7769
f'pdfs',
7870
files={'assets': assets} if assets else None,
7971
data={
8072
'template_html': template_html,
8173
'document_args': json.dumps(document_args),
82-
'global_vars': json.dumps(global_vars) \
83-
if global_vars else None
74+
'global_args': json.dumps(global_args) \
75+
if global_args else None
8476
}
8577
)
8678

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# Versions should comply with PEP440. For a discussion on single-sourcing
2222
# the version across setup.py and the project code, see
2323
# https://packaging.python.org/en/latest/single_source_version.html
24-
version='0.0.3',
24+
version='0.0.4',
2525
description=(
2626
'The DInk Python library provides a pythonic interface to the DInk '
2727
'API.',

0 commit comments

Comments
 (0)