Skip to content

Commit

Permalink
Fixes for Resources interface
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyjb committed Jul 29, 2020
1 parent dd1b3a4 commit e6bfdae
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -81,7 +85,7 @@ pdfs = dink.resources.PDF.create(
).to_json_type()
}
},
global_vars={
global_args={
'title': 'Weekly sales report'
},
assets=assets
Expand Down
14 changes: 3 additions & 11 deletions dink/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def create(cls,
client,
template_html,
document_args,
global_vars=None,
global_args=None,
assets=None
):
"""
Expand All @@ -64,23 +64,15 @@ 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',
files={'assets': assets} if assets else None,
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
}
)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down

0 comments on commit e6bfdae

Please sign in to comment.