From 21b3e0b0884848f38a6155724f53b182785d467e Mon Sep 17 00:00:00 2001 From: Chad Selph Date: Thu, 11 Oct 2012 20:57:20 -0700 Subject: [PATCH] tweeks --- docs/browser.rst | 20 +++++++++++++------- main.py | 10 ++++++++-- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/docs/browser.rst b/docs/browser.rst index c32b1d7..9d42c11 100644 --- a/docs/browser.rst +++ b/docs/browser.rst @@ -69,14 +69,11 @@ new AppEngine RequestHandler into ``main.py``. .. code-block:: python - import os - - class IndexPage(webapp2.RequestHandler): def get(self): params = { - "token": gen_token("ACXXX", "XXX", "APXXX") + "token": gen_token(ACCOUNT_SID, AUTH_TOKEN, APP_SID) } self.response.out.write(render_template("index.html", params)) @@ -158,13 +155,22 @@ Let's add a feature where we can see a visualization of the queue .. code-block:: python - some python code that queries the queue + import json + from twilio import TwilioRestClient + + class QueueStatusPage(webapp2.RequestHandler): + + def get(self): + client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN) + q_data = {"queues": client.queues.get(QUEUE_SID)} + self.response.out.write(json.dumps(q_data)) +Add this QueueStatusPage into the WSIApplication's routing map as ``/queue-status``. Now we need some Javascript to poll the state of the queue and update the UI. .. code-block:: javascript - $.get("/queue-status", function() { - + $.get("/queue-status", function(result) { + // update your UI here }); diff --git a/main.py b/main.py index 4d77911..1d1bc0f 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,16 @@ -import webapp2 -from google.appengine.ext.webapp import template import os +from google.appengine.ext.webapp import template +import twilio +import webapp2 + +ACCOUNT_SID = "ACXXX" +AUTH_TOKEN = "XXX" +APP_SID = "APXXX" # Utility functions + def render_template(rel_path, parameters=None, folder="templates"): """ Takes a path relative to the templates/ folder and