Update api-python-client-doc to also serve up a gadget
diff --git a/samples/api-python-client-doc/gadget.html b/samples/api-python-client-doc/gadget.html
new file mode 100644
index 0000000..49a9436
--- /dev/null
+++ b/samples/api-python-client-doc/gadget.html
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<Module>
+ <ModulePrefs title="Google APIs" />
+ <Content type="html">
+ <![CDATA[
+ <table>
+ {% for item in directory %}
+ <tr>
+ <td><img style="width: 16px; height: 16px" src="{{ item.icons.x16 }}"/> {{ item.name }} </td>
+ <td><a href="{{ item.documentationLink }}">Documentation</a></td>
+ <td><a href="/{{ item.name }}/{{ item.version }}">PyDoc</a></td>
+ </tr>
+ {% endfor %}
+ </table>
+ ]]>
+ </Content>
+</Module>
diff --git a/samples/api-python-client-doc/index.html b/samples/api-python-client-doc/index.html
index f98a79f..79144b6 100644
--- a/samples/api-python-client-doc/index.html
+++ b/samples/api-python-client-doc/index.html
@@ -22,12 +22,16 @@
<table>
<tr>
<th>API</th>
+ <th>Documentation</th>
+ <th>PyDoc</th>
<th>Name</th>
<th>Version</th>
</tr>
{% for item in directory %}
<tr>
- <td><a href="/{{ item.name }}/{{ item.version }}"><img src="{{ item.icons.x16 }}"/> {{ item.title }} </a></td>
+ <td><img src="{{ item.icons.x16 }}"/> {{ item.title }}</td>
+ <td><a href="{{ item.documentationLink }}">Documentation</a></td>
+ <td><a href="/{{ item.name }}/{{ item.version }}">PyDoc</a></td>
<td>{{ item.name }}</td>
<td>{{ item.version}}</td>
</tr>
diff --git a/samples/api-python-client-doc/main.py b/samples/api-python-client-doc/main.py
index 506f27a..9aabde5 100755
--- a/samples/api-python-client-doc/main.py
+++ b/samples/api-python-client-doc/main.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright 2007 Google Inc.
+# Copyright 2011 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -14,6 +14,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+"""Sample application for Python documentation of APIs.
+
+This is running live at http://api-python-client-doc.appspot.com where it
+provides a list of APIs and PyDoc documentation for all the generated API
+surfaces as they appear in the google-api-python-client. In addition it also
+provides a Google Gadget.
+"""
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
@@ -23,8 +30,8 @@
import pydoc
import re
-from apiclient.discovery import build
from apiclient.anyjson import simplejson
+from apiclient import discovery
from google.appengine.api import memcache
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
@@ -32,6 +39,8 @@
class MainHandler(webapp.RequestHandler):
+ """Handles serving the main landing page.
+ """
def get(self):
http = httplib2.Http(memcache)
@@ -46,23 +55,45 @@
}))
-def render(resource):
+class GadgetHandler(webapp.RequestHandler):
+ """Handles serving the Google Gadget.
+ """
+
+ def get(self):
+ http = httplib2.Http(memcache)
+ resp, content = http.request('https://www.googleapis.com/discovery/v1/apis?preferred=true')
+ directory = simplejson.loads(content)['items']
+ for item in directory:
+ item['title'] = item.get('title', item.get('description', ''))
+ path = os.path.join(os.path.dirname(__file__), 'gadget.html')
+ self.response.out.write(
+ template.render(
+ path, {'directory': directory,
+ }))
+ self.response.headers.add_header('Content-Type', 'application/xml')
+
+
+def _render(resource):
+ """Use pydoc helpers on an instance to generate the help documentation.
+ """
obj, name = pydoc.resolve(type(resource))
return pydoc.html.page(
pydoc.describe(obj), pydoc.html.document(obj, name))
class ResourceHandler(webapp.RequestHandler):
+ """Handles serving the PyDoc for a given collection.
+ """
def get(self, service_name, version, collection):
- resource = build(service_name, version)
+ resource = discovery.build(service_name, version)
# descend the object path
if collection:
path = collection.split('/')
if path:
for method in path:
resource = getattr(resource, method)()
- page = render(resource)
+ page = _render(resource)
collections = []
for name in dir(resource):
@@ -89,6 +120,7 @@
application = webapp.WSGIApplication(
[
(r'/', MainHandler),
+ (r'/_gadget/', GadgetHandler),
(r'/([^\/]*)/([^\/]*)(?:/(.*))?', ResourceHandler),
],
debug=True)