Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_gist(slug, version, fresh):
"""Download a gist"""
if '/' in slug:
parts = slug.split('/')
username, title = parts[0], parts[1]
url = _u('user/' + username + '/gist/' + title + _v(version))
else:
url = _u('gist/' + slug + _v(version))
res = get(url, headers=_h(fresh))
if res.status_code == 200:
return res.json()['data']
raise Exception('Failed to retrieve Gist: ' + pretty(res))
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 get_current_user():
res = get(url=_u('/user/profile'), headers=_h())
if res.status_code == 200:
return res.json()['data']
raise Exception('Failed to fetch current user profile. ' + pretty(res))