Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if gist_slug:
return upload_file(gist_slug=gist_slug, file=nb_file, version_title=version_title)
else:
data = {'visibility': privacy}
# For compatibility with old version of API endpoint
if privacy == 'auto':
data['public'] = True
elif privacy == 'secret' or privacy == 'private':
data['public'] = False
if title:
data['title'] = title
if version_title:
data['version_title'] = version_title
res = post(url=_u('/gist/create'),
data=data,
files={'files': nb_file},
headers=auth_headers)
if res.status_code == 200:
return res.json()['data']
raise ApiError('File upload failed: ' + pretty(res))
def upload_file(gist_slug, file, folder=None, version=None, artifact=False, version_title=None):
"""Upload an additional file to a gist"""
data = {'artifact': 'true'} if artifact else {}
if folder:
data['folder'] = folder
if version_title:
data['version_title'] = version_title
res = post(url=_u('/gist/' + gist_slug + '/upload' + _v(version)),
files={'files': file}, data=data, headers=_h())
if res.status_code == 200:
return res.json()['data']
raise ApiError('File upload failed: ' + pretty(res))
def post_blocks(blocks, version=None):
url = _u('/data/record' + _v(version))
res = post(url, json=blocks, headers=_h())
if res.status_code == 200:
return res.json()['data']
else:
raise ApiError('Data logging failed: ' + pretty(res))
def post_slack_message(data, safe=False):
"""Push data to Slack, if slack is integrated with jovian account"""
url = _u('/slack/notify')
res = post(url, json=data, headers=_h())
if res.status_code == 200:
return res.json()
elif safe:
return {'data': {'messageSent': False}}
else:
raise ApiError('Slack trigger failed: ' + pretty(res))
def post_records(gist_slug, tracking_slugs, version=None):
"""Associated tracked records with a commit"""
url = _u('/data/' + gist_slug + '/commit' + _v(version))
res = post(url, json=tracking_slugs, headers=_h())
if res.status_code == 200:
return res.json()['data']
else:
raise ApiError('Data logging failed: ' + pretty(res))