Last active
August 30, 2016 17:49
-
-
Save chucknado/7739e825669ebde9cd4ecbbfff43d6aa to your computer and use it in GitHub Desktop.
Bottle app for simple server-side Zendesk app (https://support.zendesk.com/hc/en-us/articles/226176327)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bottle import route, run, template, request, response, static_file | |
import requests | |
@route('/sidebar') | |
def send_iframe_html(): | |
qs = request.query_string | |
response.set_cookie('my_app_params', qs) | |
return template('start', qs=qs) | |
@route('/list') | |
def show_tasks(): | |
access_token = "your_access_token" | |
header = {'Authorization': 'Bearer {}'.format(access_token)} | |
url = 'https://app.asana.com/api/1.0/projects/your_project_id/tasks' | |
r = requests.get(url, headers=header) | |
if r.status_code == 200: | |
tasks = r.json() | |
return template('list_tasks', list=tasks['data']) | |
else: | |
msg = 'Problem with the request: {} {}'.format(r.status_code, r.reason) | |
qs = request.get_cookie('my_app_params') | |
return template('start', qs=qs, error_msg=msg) | |
@route('/js/<filename>') | |
def send_js(filename): | |
return static_file(filename, root='static/js') | |
run(host='localhost', port=8080, debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment